Define Properties() spawn_type = "pumpkinmeep" -- name of a template spawn_population = 5 spawn_range = 1.1 spawn_level = 1 children = {} ExposeProperty("spawn_population", "How many meeps will live with this spawner. The spawner will try to maintain this population if any die.") ExposeProperty("spawn_range", "How far away in tiles the pumpkins will spawn.") PersistProperty("spawn_population") PersistProperty("spawn_range") end Trigger tick() if #self.children < self.spawn_population then local x = self.x + (math.random()*self.spawn_range*2) - self.spawn_range local y = self.y + (math.random()*self.spawn_range*2) - self.spawn_range -- Debug("spawning %s at %f,%f", self.spawn_type, x, y) local child = CreateObject(self.spawn_type, x, y, 0, 1) SendTo(child, "reset", 0, self.x, self.y) if child then table.insert(self.children, child) end end local deleted = {} for i,child in pairs(self.children) do if child.id == nil then table.remove(self.children, i) end end end Trigger destroyed() for i,child in pairs(self.children) do DestroyObject(child) end end