What about Bob?

master
James Stevenson 2019-01-19 05:21:58 -05:00
parent eea4a4a535
commit d2fab280a9
2 changed files with 25 additions and 12 deletions

View File

@ -25,11 +25,22 @@ minetest.register_node("mobs:spawner", {
on_blast = function()
end,
on_timer = function(pos, elapsed)
if check_for_player(pos) then
minetest.get_node_timer(pos):set(10, 0)
print(dump(pos), elapsed)
if elapsed < 10 then
minetest.get_node_timer(pos):set(10, elapsed + 0.1)
return
else
minetest.get_node_timer(pos):start(10)
end
limiter(pos)
if check_for_player(pos) then
minetest.get_node_timer(pos):start(10)
return
end
if limiter(pos) then
return
end
local node = minetest.get_node_or_nil({
x = pos.x,
@ -115,7 +126,9 @@ minetest.register_abm({
catch_up = false,
action = function(pos, node, active_object_count, active_object_count_wider)
--print(active_object_count, active_object_count_wider)
limiter(pos)
if limiter(pos) then
minetest.set_node(pos, {name = "air"})
end
end,
})

View File

@ -1,7 +1,9 @@
local random = math.random
local stepper = 0
mobs.check_for_player = function(pos)
local objects_in_radius = minetest.get_objects_inside_radius(pos, 16)
mobs.check_for_player = function(pos, radius)
radius = radius or 32
local objects_in_radius = minetest.get_objects_inside_radius(pos, radius)
for i = 1, #objects_in_radius do
local object = objects_in_radius[i]
local player = object:is_player()
@ -69,13 +71,12 @@ mobs.redo = function(pos, radius)
local t = minetest.get_node_timer(n)
if not t:is_started() then
print("Restarting timer.")
t:start(1)
t:start(10)
end
end
local a = minetest.find_nodes_in_area_under_air(p1, p2, "group:reliable")
if a and a[1] then
print("Setting spawner.")
local an = a[random(#a)]
local np = {
x = an.x,
@ -95,7 +96,7 @@ mobs.limiter = function(pos, radius, limit, immediate_surrounding, surrounding)
minetest.get_objects_inside_radius(pos, radius)
if #immediate_surrounding > 6 then
return
return true
end
local surrounding = surrounding or
@ -114,12 +115,11 @@ mobs.limiter = function(pos, radius, limit, immediate_surrounding, surrounding)
end
end
if h > limit then
return
return true
end
end
end
local stepper = 0
minetest.register_globalstep(function(dtime)
if stepper < 10 then
stepper = stepper + dtime
@ -157,6 +157,6 @@ minetest.register_globalstep(function(dtime)
break
end
minetest.get_node_timer(pos):start(0)
minetest.get_node_timer(pos):start(10)
end
end)