ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
Saving data with packet_utils and dropped object parents.

Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  23:39:18  12 August 2013
profilee-mailreply Message URLTo the Top
TKGP
Senior Resident
 

 
On forum: 01/25/2013
 

Message edited by:
TKGP
08/12/2013 23:40:06
Messages: 454
Saving data with packet_utils and dropped object parents.

The first question is pretty simple: where do items go when you drop them? I need to transfer a dropped item back into the player's inventory, and I've managed to fudge it by doing

obj:parent():transfer_item( obj, db.actor )


While this does work, it spits an error into the console; "can't detach independant object", and on game quit there's a crash for "parent not found. id_parent=0 id_entity=23081 frame=762".
There must be a better way to do it but I haven't the foggiest what it would be.

Secondly while I can read the data I need (which attachments are present) just fine with packet_utils, I can't modify it and save back to the weapon. Stripped down a bit, this is what I want to do:

local weaponData = packet_utils.get_object_data( obj )
if math.mod( weaponData.addon_flags, 2 ) == 1 then --basically if a scope is equipped
weaponData.addon_flags = weaponData.addon_flags - 1 --remove the scope
packet_utils.set_object_data( obj, weaponData )


It definitely reads in fine, I can successfully check whether the scope is equipped, but I must be missing something in attempting to save it because the weapon never actually gets changed.
  22:51:41  15 August 2013
profilee-mailreply Message URLTo the Top
NatVac
Senior Resident
 

 
On forum: 06/15/2007
Messages: 4263
Your fudge is the normal solution. Don't worry about "can't detach independant object". That's not any problem other than the "Error" spam confusing those who look at the log file.

The crash is related to the actor_binder:on_item_drop() function which is called for every inventory item when you quit the game. The error is that the actor object (id = 0) is already not valid (strange).

Here's a suggested solution: You can put a test for quitting the game at the beginning of the on_item_drop() function in bind_stalker.script to prevent the crash:

function actor_binder:on_item_drop (obj)
  if quitting_game then return end


At the top of the file put this:

quitting_game = false

Insert this as the first line in each of two functions in ui_main_menu.script:

  bind_stalker.quitting_game = true

The two functions are main_menu:OnMessageQuitGame() and main_menu:OnMessageQuitWin().

As for your second question, I vaguely recall that updating the packet needed to be followed by a STATE_Read() to set the object's attributes from the packet (which I assume your packet_utils.script is doing), but this might not be possible on a weapon in the actor's possession, at least not while online (which the actor always is). There is some engine function to add the scope to the weapon but it is probably not script-accessible.

I think notanumber went through this experience for his mod stuff. He may have moved the weapon out of inventory (e.g., dropped it), modified it, then moved it back. Or he might have deleted the old and created a new one with all the desired trimmings. Go to http://zhat.dk/stalker/ to check out his Progressive Weapons stuff and/or search this forum for the discussion on it.
  04:58:16  18 August 2013
profilee-mailreply Message URLTo the Top
TKGP
Senior Resident
 

 
On forum: 01/25/2013
Messages: 454
Yep, that little check fixed the crash.
As for the packet stuff, I took a peek into notanumber's scripts and as you guessed he creates an entirely new item and transfers the old properties onto it. I tried it out and discovered that I could easily take the data from one weapon and transfer it onto the new one, but I still couldn't successfully change it between the two. But, a little searching later it turns out that if you want to write new data rather than editing the existing field (data.addon_flags in this case), you assign the new value to upd_addon_flags instead.
Long story short, it works! Thanks for your help NatVac.

Now, a new question to bother you all with. I know how to detect when the actor opens a container, by checking for the ui_car_body infoportion, but how do I get the identity of what you're looking at? I'd like to make it such that when you open a container it will search for some particular items and automatically transfer them to you if present, which should be more or less trivial once I can actually reference the container.
  07:47:08  20 August 2013
profilee-mailreply Message URLTo the Top
NatVac
Senior Resident
 

 
On forum: 06/15/2007
Messages: 4263
I'm glad you got it working, TKGP.

I don't know about the question as I've not tried anything yet, but you could add a "use_object" callback to bind_stalker.script. You should be able to use the object parameter that is passed into the use_object() callback. Check its section() or name().

For some guidelines on implementing this callback, see the latest ZRP's bind_stalker.script. There are also examples showing how you can auto-acquire favorite ammo and medkits from stalkers (through xr_motivator.script) or mutant parts from dead mutants (via bind_monster.script) when you search them. Support code is in zx.script.
  19:52:59  20 August 2013
profilee-mailreply Message URLTo the Top
TKGP
Senior Resident
 

 
On forum: 01/25/2013
Messages: 454

---QUOTATION---
you could add a "use_object" callback to bind_stalker.script. You should be able to use the object parameter that is passed into the use_object() callback.
---END QUOTATION---


I've used that callback to run logic on use of inventory items, but in bind_stalker the use callback doesn't fire on opening containers; however as you suggested I looked through the scripts and it turns out you can add the callback to other objects to trigger when they're being used, and by who. So, another problem solved! And since the ZRP guys already implemented this I don't need to bother reinventing the wheel.
  09:27:07  23 August 2013
profilee-mailreply Message URLTo the Top
NatVac
Senior Resident
 

 
On forum: 06/15/2007
Messages: 4263
>> in bind_stalker the use callback doesn't fire on opening containers

Ah, yes, that suggestion was my not thinking, AKA "replying from the hip". But that didn't stop you from figuring it out. I remember adding that bind_monster.script callback support to ZRP after telling Cpt. Borovich how to do it*. Did you add a callback for a container or just use the callback on NPCs/monsters?

---QUOTATION---
*"ZRP - A joint effort in fixing S.T.A.L.K.E.R.", page 99:
https://www.gsc-game.com/main.php?t=community&s=forums&s_game_type=xr&thm_id=11786&page=99&sec_id=16
---END QUOTATION---

  05:52:11  26 August 2013
profilee-mailreply Message URLTo the Top
TKGP
Senior Resident
 

 
On forum: 01/25/2013
Messages: 454

---QUOTATION---
Did you add a callback for a container or just use the callback on NPCs/monsters?
---END QUOTATION---


Well to be honest once I saw it was a solved problem I stopped looking into it. Although, having had occasion on a different matter to work with static containers, they do seem to have some odd behaviors (inventory_for_each doesn't work?). And now that you mention it, I can see why you wouldn't be able to use the same method for containers.

As per usual, I have a new question which should be pretty easy. How do you tell if an item is on the belt, or get a list of items on the belt?
  22:46:29  27 August 2013
profilee-mailreply Message URLTo the Top
Vintar
a bit of this and a lot of that
(Resident)

 

 
On forum: 08/08/2008
Messages: 6349

---QUOTATION---
As per usual, I have a new question which should be pretty easy. How do you tell if an item is on the belt, or get a list of items on the belt?
---END QUOTATION---



There is no method for checking items on belt in the original version of the game, it was modded in and I would only be guessing who added it first. Happily I can say that methods will be readily available in LA
  03:14:25  29 August 2013
profilee-mailreply Message URLTo the Top
TKGP
Senior Resident
 

 
On forum: 01/25/2013
Messages: 454

---QUOTATION---
Happily I can say that methods will be readily available in LA
---END QUOTATION---


I'll keep that in mind if Lost Alpha ever comes out (no offense).

Also, after digging deep into the bowels of GSC forums I found the information I needed, so if anyone else is interested I'll restate it here.
When you call inventory_for_each it steps through equipped items (including belt) last. So, just spawn some item to act as a marker, check until you get to that point, make sure what you're looking at isn't in one of the normal slots, and voila, belt items.
 
Each word should be at least 3 characters long.
Search:    
Search conditions:    - spaces as AND    - spaces as OR   
 
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
 

All short dates are in Month-Day-Year format.


 

Copyright © 1995-2019 GSC Game World. All rights reserved.
This site is best viewed in Internet Explorer 4.xx and up and Javascript enabled. Webmaster.
Opera Software products are not supported.
If any problem concerning the site functioning under Opera Software appears apply
to Opera Software technical support service.