Jump to content

fixed loot


Recommended Posts

I'm new to mod creation and I need help with my mod, which should spawn chests with fixed loot near players on command, but I don't understand how to make the loot fixed. I will be glad for any help)

Spoiler
local _G = GLOBAL
local AllPlayers = _G.AllPlayers
local TUNING = _G.TUNING
 
--------------------------------------------  
AddPrefabPostInit("world"function(inst)
    if not _G.TheWorld.ismastersim then
        return
    end
 
    _G.TheWorld:ListenForEvent("seasontick"function()
    if _G.TheWorld.state.cycles == 1 then
      _G.TheWorld:PushEvent("cornucopia")
    end
    end)
 
    inst:ListenForEvent("cornucopia"function(inst)
      inst:DoTaskInTime(4function()
            for i, v in ipairs(AllPlayers) do
 
        local x, y, z = v.Transform:GetWorldPosition()
                    local gift = _G.SpawnPrefab("treasurechest")
                            gift.Transform:SetPosition(x, y, z)
 
                            local items = {}
                            local item = _G.SpawnPrefab("pigskin")
                            item.components.stackable:SetStackSize(1)
                            table.insert(items, item)
 
                            item = _G.SpawnPrefab("cutgrass")
                            item.components.stackable:SetStackSize(5)
                            table.insert(items, item)
 
                            item = _G.SpawnPrefab("twigs")
                            item.components.stackable:SetStackSize(5)
                            table.insert(items, item)
 
                            item = _G.SpawnPrefab("lubricant")
                            item.components.stackable:SetStackSize(3)
                            table.insert(items, item)
 
                            gift.components.container:GiveItem(items)
 
                            for i, v in ipairs(items) do
                                v:Remove()
                end 
      end
    end)
  end)
end)

 

Link to comment
Share on other sites

Does nothing happen?

I think the problem is that you give a table to the function GiveItem, but it can't use tables.

Do something like :

for i,v in ipairs(items) do 
	gift.components.container:GiveItem(v)
end

 

Edited by Monti18
  • Like 1
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
 Share

×
  • Create New...