Linking item to lua code
0

2 posts in this topic

Recommended Posts

Sorry, didn't come up with a better name for the topic.

I'm currently struggling with the linkage of items and lua code altering them. I try to give an example to better illustrate my problem:

I was looking at the shotgun and how it's moddata is used to store info with the item object itself, but I just can't get it. Somehow the item "Shotgun" defined in items.txt is generating an instance in lua, which then get's altered and this alterations are stored in the moddata of that specific instance of the shotgun item. How does this all work and when exactly does the shotgun instance reload the stored info from moddata?

 

Why am I asking this:

For the past couple of weeks I'm struggling with my cooling box mod. The cooling itself works fine, but it's the reload and persistents that's giving me headaches.

Share this post


Link to post
Share on other sites

I realize this was asked a month ago, but hopefully this helps someone in the future.

 

I'm not sure if I completely understand your issue. Are you having issues with the saving/loading moddata? I have included some sample code that should help, each school bag has it's own unique moddata value of "Test".

 

--Saving
local bagItem = InventoryItemFactory.CreateItem("Base.Schoolbag") --Create the item in code
getSpecificPlayer(0):getCurrentSquare():AddWorldInventoryItem(bagItem, 0, 0, 0) --spawn the item on the ground
bagItem:getModData()["Test"] = ZombRand(100) --set "Test" to a random value between 0-99

--Loading
local hasBag = getSpecificPlayer(0):getInventory():contains("Schoolbag") --check if player has container

if (hasBag) then --if they have container
  local moddataBag = getSpecificPlayer(0):getInventory():FindAndReturn("Schoolbag") --find the container
  print("*****schoolbag value:*****")
  print(moddataBag:getModData()["Test"]) --print the value of the container
end

 

Edited by nater

Share this post


Link to post
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
0