Jump to content

Floor item spawn


Sanchez

Recommended Posts

Hello, can someone help with item spawn script please? I need to spawn items on the ground with exact coordinates once per day.
I tried different variants of this, but it won't work:

function Spawn(square)
square:AddWorldInventoryItem("Base.Stone", 10000, 10000, 0);
end

Events.EveryDays.Add(Spawn);

Most errors look like:
java.lang.RuntimeException: attempted index: AddWorldInventoryItem of non-table: null

I'am weak in scripting, and can't make it work, please help!

Edited by Sanchez
Link to comment
Share on other sites

1 hour ago, Sanchez said:

attempted index: AddWorldInventoryItem of non-table: null

The problem here looks to be your not passing a proper IsoGridSquare object into your function. Calling your function like that through the EveryDays event will not pass your 'square' variable into the function.

 

local x, y, z = 0, 0, 0 -- change to where you want to spawn
local function Spawn()
	local square = getCell():getOrCreateGridSquare(x, y, z)
	if not square then return end
	square:AddWorldInventoryItem("Base.Stone", 0, 0, 0)
end

Events.EveryDays.Add(Spawn)

 

 

 

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...