Page 1 of 1
[done]Spawning items to the ground every x seconds
Posted: Sun Aug 28, 2016 3:22 pm
by iHeroN
Sorry for the bad english but i'm italian

Hi I'm new to lua and factorio modding in general. I have a question for you. I want to make a mod that adds special trees to the game. these trees, will grow and then drop to the ground an item every minute/some time. can someone help me? thanks!

Re: Spawning items to the ground every x seconds
Posted: Sun Aug 28, 2016 3:37 pm
by aubergine18
Use the
on_tick event to do something every minute. There are 60 ticks per second, so 60*60 = 3600 per minute.
Code: Select all
script.on_event(defines.events.on_tick, function()
if game.tick % 3600 then
-- make your trees drop items
end
end)
To create entities, use
create_entity() on the player surface:
Code: Select all
game.players[playerId].surface.create_entity(...) -- playerId is index of a player
Re: Spawning items to the ground every x seconds
Posted: Sun Aug 28, 2016 3:48 pm
by iHeroN
thanks.... but how to get the coordinates of the trees entities? it is ok also a website that explain things in general
Re: Spawning items to the ground every x seconds
Posted: Sun Aug 28, 2016 3:54 pm
by aubergine18
Three good sources of info:
*
API docs
*
Modding section in the wiki
*
Mod portal - download mods that do similar things, unzip them and see how they do it
See also:
Modding references, in particular the
large guide to modding.
Re: Spawning items to the ground every x seconds
Posted: Sun Aug 28, 2016 3:56 pm
by iHeroN
thanks for the help and for fast reply!