 |
 |
 |
|
 |
 |
 |
|
 |
 |
Saving data with packet_utils and dropped object parents. |
|
|
|
|
23:39:18 12 August 2013 |
|
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.
My mods: http://bit.ly/TKModStatus
My stream: http://www.twitch.tv/tkgp
|
22:51:41 15 August 2013 |
|
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 |
|
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.
My mods: http://bit.ly/TKModStatus
My stream: http://www.twitch.tv/tkgp
|
07:47:08 20 August 2013 |
|
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. |
09:27:07 23 August 2013 |
|
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---
|
|
1 | All Messages |
|
|
|
» » |
|
All short dates are in Month-Day-Year format. |
 |
|
 |
|
|
|
 |
 |
 |