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!
[done]Spawning items to the ground every x seconds
[done]Spawning items to the ground every x seconds
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!
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!
Last edited by iHeroN on Sun Aug 28, 2016 3:57 pm, edited 1 time in total.
- aubergine18
- Smart Inserter

- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Spawning items to the ground every x seconds
Use the on_tick event to do something every minute. There are 60 ticks per second, so 60*60 = 3600 per minute.
To create entities, use create_entity() on the player surface:
Code: Select all
script.on_event(defines.events.on_tick, function()
if game.tick % 3600 then
-- make your trees drop items
end
end)
Code: Select all
game.players[playerId].surface.create_entity(...) -- playerId is index of a player
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Spawning items to the ground every x seconds
thanks.... but how to get the coordinates of the trees entities? it is ok also a website that explain things in general
- aubergine18
- Smart Inserter

- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Spawning items to the ground every x seconds
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.
* 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.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Spawning items to the ground every x seconds
thanks for the help and for fast reply!
