1 --this is where mob spawning is defined
3 --spawn mob in a square doughnut shaped radius
7 --inner and outer part of square donut radius
11 --for debug testing to isolate mobs
14 minetest.register_globalstep(function(dtime)
17 if timer >= tick and math.random(1,chance) == chance then
20 --check through players
21 for _,player in ipairs(minetest.get_connected_players()) do
22 --don't spawn near dead players
23 if player:get_hp() > 0 then
25 --local mob_number = math.random(0,2)
28 local pos = vector.floor(vector.add(player:getpos(),0.5))
32 --this is used to determine the axis buffer from the player
33 local axis = math.random(0,1)
35 --cast towards the direction
37 x = pos.x + math.random(inner,outer)*int[math.random(1,2)]
38 z = pos.z + math.random(-outer,outer)
40 z = pos.z + math.random(inner,outer)*int[math.random(1,2)]
41 x = pos.x + math.random(-outer,outer)
45 local spawner = minetest.find_nodes_in_area_under_air(vector.new(x,pos.y-32,z), vector.new(x,pos.y+32,z), {"main:grass","main:sand","main:water"})
47 --print(dump(spawner))
48 if table.getn(spawner) > 0 then
49 local mob_pos = spawner[1]
50 mob_pos.y = mob_pos.y + 1
51 --print("Spawning at: "..minetest.pos_to_string(mob_pos))
52 minetest.add_entity(mob_pos,"mob:pig")
56 elseif timer > tick then