Skip to content
This repository has been archived by the owner on Dec 14, 2019. It is now read-only.

Commit

Permalink
Fix crash caused by spawn control
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockMen committed May 23, 2014
1 parent b449a66 commit ec83599
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions init.lua
Expand Up @@ -44,17 +44,18 @@ function creatures.spawn(pos, number, mob, limit, range, abs_max)
if range == nil then range = 10 end
if abs_max == nil then abs_max = absolute_mob_max end
local m_name = string.sub(mob,11)
if not creatures.spawned[m_name] then creatures.spawned[m_name] = 0 end
local spawned = creatures.spawned[m_name]
if not spawned then spawned = 0 end
local res,mobs,player_near = creatures.find_mates(pos, m_name, range)
for i=1,number do
local x = 1/math.random(1,3)
local z = 1/math.random(1,3)
local p = {x=pos.x+x,y=pos.y,z=pos.z+z}
if mobs+i <= limit and creatures.spawned[m_name]+i < abs_max then
if mobs+i <= limit and spawned+i < abs_max then
minetest.after(i/5,function()
local obj = minetest.env:add_entity(p, mob)
if obj then
creatures.spawned[m_name] = creatures.spawned[m_name] + 1
creatures.spawned[m_name] = spawned + 1
minetest.log("action", "Spawned "..mob.." at ("..pos.x..","..pos.y..","..pos.z..")")
end
end)
Expand Down

0 comments on commit ec83599

Please sign in to comment.