[done]Spawning items to the ground every x seconds

Place to get help with not working mods / modding interface.
iHeroN
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sun Jul 24, 2016 12:18 pm
Contact:

[done]Spawning items to the ground every x seconds

Post by iHeroN »

Sorry for the bad english but i'm italian :D
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! :D
Last edited by iHeroN on Sun Aug 28, 2016 3:57 pm, edited 1 time in total.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Spawning items to the ground every x seconds

Post 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
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.
iHeroN
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sun Jul 24, 2016 12:18 pm
Contact:

Re: Spawning items to the ground every x seconds

Post by iHeroN »

thanks.... but how to get the coordinates of the trees entities? it is ok also a website that explain things in general
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Spawning items to the ground every x seconds

Post 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.
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.
iHeroN
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sun Jul 24, 2016 12:18 pm
Contact:

Re: Spawning items to the ground every x seconds

Post by iHeroN »

thanks for the help and for fast reply!
Post Reply

Return to “Modding help”