I'm looking to make a simple mod that allows growing trees. Craft or find saplings, plant them and they'll turn into full-sized trees after some delay.
I don't play multi and from memory last time I did control.lua modding there are things to avoid to maintain multiplayer sync.
I want to be able to place a sapling entity, and after some delay (fixed or random, not sure yet) it will be removed and replaced by a full-sized tree (don't have the art skills to do intermediate steps, but the same principle would apply).
So what's the best way to go about adding a whole bunch of timed events in a way that won't break multiplayer or slow the game down too much if the player throws down a large number?
Good way to go about growing trees?
- Arch666Angel
- Smart Inserter
- Posts: 1636
- Joined: Sun Oct 18, 2015 11:52 am
- Contact:
Re: Good way to go about growing trees?
Isn't that exactly what the treefarm mod does?
Angels Mods
I. Angel's Mods Subforum
II. Development and Discussion
III. Bugs & FAQ

"should be fixed"
I. Angel's Mods Subforum
II. Development and Discussion
III. Bugs & FAQ

"should be fixed"
Re: Good way to go about growing trees?
There is also a Greenhouse mod that "grows" trees as a normal production recipe - much more performance friendly then treefarm but more limited (wood only).
Re: Good way to go about growing trees?
Ok so the best way i can see is as follows:GotLag wrote:I'm looking to make a simple mod that allows growing trees. Craft or find saplings, plant them and they'll turn into full-sized trees after some delay.
I don't play multi and from memory last time I did control.lua modding there are things to avoid to maintain multiplayer sync.
I want to be able to place a sapling entity, and after some delay (fixed or random, not sure yet) it will be removed and replaced by a full-sized tree (don't have the art skills to do intermediate steps, but the same principle would apply).
So what's the best way to go about adding a whole bunch of timed events in a way that won't break multiplayer or slow the game down too much if the player throws down a large number?
1. When you build the sapling, enter it into a global table,
Code: Select all
script.on_event(defines.on_built_entity, function(event)
if event.entity.name == "sapling" then table.insert(global.sapling, sapling)
end
Code: Select all
script.on_event(defines.on_tick, check_saplings)
function check_saplings()
for k, sapling in pairs (global.saplings) do
if k % 600 == game.tick % 600 then //This is the magic, the 600 spreads all the checks over 10 seconds
if math.random(0,1) > 0.6 then //This is how you can make it semi-random
grow_sapling(sapling)
end
end
end
end