Jump to content
Undefined

Is there a way to modify the attribute of an item that already spawned?

Recommended Posts

I want to modify the Weight Reduction of the Toolbox.

 

I'm using Item Tweaker API.

 

The changes doesn't take effect in a currently saved game, but it does work in a new game.

 

Does anyone know how to get it to work for toolboxes that have already spawned?

Edited by Undefined

Share this post


Link to post
Share on other sites

40 minutes ago, Tchernobill said:

this mod modifies the item definition that is used at item spawn time.

It will never modify an already spawned item.

You need something else to modify the item already spawned.

Thanks. Can you point me in the right direction?

Share this post


Link to post
Share on other sites

12 minutes ago, Hugo Qwerty said:

Thanks. I've known about that method and have looked through the code base for statements that call setWeightReduction (link), but I'm not sure how I would implement it.

 

I was thinking I'd need to loop through all Toolboxes in the game and then call setWeightReduction, but I don't know the name of the array (or what method I can call that returns an array of all spawned toolboxes).

 

I also figured that maybe the toolbox attributes where saved in the game files once they spawned so it might not even be possible.

Edited by Undefined

Share this post


Link to post
Share on other sites

I thought that maybe someone in the workshop might have this figured out so I looked around for other weight reduction mods.

 

The only workaround I've found is someone who added a crafting recipe where you use the old item to craft a new item of the same type, which then has the changed attribute.

 

If it's not possible to change the attribute of a spawned item, this will have to suffice.

Edited by Undefined

Share this post


Link to post
Share on other sites

4 hours ago, Hugo Qwerty said:

You might be able to use the Event system: https://pzwiki.net/wiki/Modding:Lua_Events

 

Not sure which event would be best, OnPlayerUpdate perhaps?  Then check the players inventory for a tool box, however I expect that event runs a lot so it might be excessive for something like this.

Thanks for the link!

 

I noticed the OnGameStart event, which I first saw from looking at Item Tweaker API's code.

 

I think this or OnLoad would have the least overhead, but I'd still need a way to pull an array with all the toolboxes (or items spawned) in the current game. Optionally, I would save the name of the game file to to a text file so it only runs one time per game. The problem is getting an array with the items, which I don't know how to go about.

 

The OnPlayerUpdate would be easier since I'd just have to check the player's inventory and I'm sure getting the player's inventory is better documented. The problem would be the overhead, which would be excessive and unnecessary.

 

So now the next step is, how to get an array of all the world items to loop through them and setWeightReduction.

 

If you  happen to know a method that returns the items in the world, I would be grateful if you could share it. In the meantime, I'll be looking around to see if such a method exists.

Edited by Undefined

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...