Jump to content

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


Undefined

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
Link to comment
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?

Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...