Extra error checking: abms.lua
This commit is contained in:
parent
e1e7745a15
commit
aa999e2ed5
2 changed files with 148 additions and 22 deletions
164
abms.lua
164
abms.lua
|
@ -15,7 +15,6 @@ local fortress_mob_count = 5
|
||||||
local players_in_orbit = {}
|
local players_in_orbit = {}
|
||||||
|
|
||||||
local mushrooms = {"flowers:mushroom_brown", "flowers:mushroom_red"}
|
local mushrooms = {"flowers:mushroom_brown", "flowers:mushroom_red"}
|
||||||
local hunger_mod = minetest.get_modpath("hunger")
|
|
||||||
|
|
||||||
|
|
||||||
-- fungal tree nodes
|
-- fungal tree nodes
|
||||||
|
@ -64,10 +63,18 @@ local fortress_group = {'group:fortress'}
|
||||||
local firework_active = false
|
local firework_active = false
|
||||||
local function firework()
|
local function firework()
|
||||||
local t = minetest.get_timeofday()
|
local t = minetest.get_timeofday()
|
||||||
|
if not (t and type(t) == 'number') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if not firework_active and (t < 0.25 or t > 0.75) then
|
if not firework_active and (t < 0.25 or t > 0.75) then
|
||||||
firework_active = true
|
firework_active = true
|
||||||
local ps = {}
|
local ps = {}
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
|
if not (players and type(players) == 'table') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
for i = 1, #players do
|
for i = 1, #players do
|
||||||
local pp = players[i]:getpos()
|
local pp = players[i]:getpos()
|
||||||
if pp and pp.y > 0 then
|
if pp and pp.y > 0 then
|
||||||
|
@ -89,7 +96,14 @@ local function firework()
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
|
if not (dtime and type(dtime) == 'number') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local time = minetest.get_gametime()
|
local time = minetest.get_gametime()
|
||||||
|
if not (time and type(time) == 'number') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Execute only after an interval.
|
-- Execute only after an interval.
|
||||||
if last_dps_check and time - last_dps_check < dps_delay then
|
if last_dps_check and time - last_dps_check < dps_delay then
|
||||||
|
@ -130,6 +144,10 @@ minetest.register_globalstep(function(dtime)
|
||||||
-- Spawn mobs in fortresses -- only when a player is near
|
-- Spawn mobs in fortresses -- only when a player is near
|
||||||
local minetest_find_nodes_in_area = minetest.find_nodes_in_area
|
local minetest_find_nodes_in_area = minetest.find_nodes_in_area
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
|
if not (players and type(players) == 'table') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local do_fortress_spawns = (fun_caves.fortress_spawns and #fun_caves.fortress_spawns > 0)
|
local do_fortress_spawns = (fun_caves.fortress_spawns and #fun_caves.fortress_spawns > 0)
|
||||||
for i = 1, #players do
|
for i = 1, #players do
|
||||||
local player = players[i]
|
local player = players[i]
|
||||||
|
@ -153,7 +171,11 @@ minetest.register_globalstep(function(dtime)
|
||||||
if mob_count < fortress_mob_count then
|
if mob_count < fortress_mob_count then
|
||||||
local f1 = vector.subtract(pos, fortress_floor)
|
local f1 = vector.subtract(pos, fortress_floor)
|
||||||
local f2 = vector.add(pos, fortress_floor)
|
local f2 = vector.add(pos, fortress_floor)
|
||||||
local floor_nodes, count = minetest.find_nodes_in_area_under_air(f1, f2, fortress_group)
|
local floor_nodes = minetest.find_nodes_in_area_under_air(f1, f2, fortress_group)
|
||||||
|
if not (floor_nodes and type(floor_nodes) == 'table') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if #floor_nodes > 0 then
|
if #floor_nodes > 0 then
|
||||||
local new_mob_pos = floor_nodes[math.random(#floor_nodes)]
|
local new_mob_pos = floor_nodes[math.random(#floor_nodes)]
|
||||||
new_mob_pos.y = new_mob_pos.y + 2
|
new_mob_pos.y = new_mob_pos.y + 2
|
||||||
|
@ -223,12 +245,20 @@ minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
-- ... from standing on or near hot objects.
|
-- ... from standing on or near hot objects.
|
||||||
local counts = minetest_find_nodes_in_area(minp, maxp, hot_stuff)
|
local counts = minetest_find_nodes_in_area(minp, maxp, hot_stuff)
|
||||||
|
if not (counts and type(counts) == 'table') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if #counts > 1 then
|
if #counts > 1 then
|
||||||
player:set_hp(player:get_hp() - 1)
|
player:set_hp(player:get_hp() - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ... from standing on or near poison.
|
-- ... from standing on or near poison.
|
||||||
local counts = minetest_find_nodes_in_area(minp, maxp, poison_stuff)
|
local counts = minetest_find_nodes_in_area(minp, maxp, poison_stuff)
|
||||||
|
if not (counts and type(counts) == 'table') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if #counts > 1 then
|
if #counts > 1 then
|
||||||
player:set_hp(player:get_hp() - 1)
|
player:set_hp(player:get_hp() - 1)
|
||||||
end
|
end
|
||||||
|
@ -236,6 +266,10 @@ minetest.register_globalstep(function(dtime)
|
||||||
-- ... from standing on or near cold objects (less often).
|
-- ... from standing on or near cold objects (less often).
|
||||||
if dps_count % cold_delay == 0 then
|
if dps_count % cold_delay == 0 then
|
||||||
counts = minetest_find_nodes_in_area(minp, maxp, cold_stuff)
|
counts = minetest_find_nodes_in_area(minp, maxp, cold_stuff)
|
||||||
|
if not (counts and type(counts) == 'table') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if #counts > 1 then
|
if #counts > 1 then
|
||||||
player:set_hp(player:get_hp() - 1)
|
player:set_hp(player:get_hp() - 1)
|
||||||
end
|
end
|
||||||
|
@ -254,6 +288,9 @@ minetest.register_globalstep(function(dtime)
|
||||||
end
|
end
|
||||||
|
|
||||||
last_dps_check = minetest.get_gametime()
|
last_dps_check = minetest.get_gametime()
|
||||||
|
if not (last_dps_check and type(last_dps_check) == 'number') then
|
||||||
|
last_dps_check = 0
|
||||||
|
end
|
||||||
dps_count = dps_count - 1
|
dps_count = dps_count - 1
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -269,6 +306,10 @@ minetest.register_abm({
|
||||||
chance = 10,
|
chance = 10,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
minetest.set_node(pos, {name = "default:cobble"})
|
minetest.set_node(pos, {name = "default:cobble"})
|
||||||
minetest.sound_play("default_cool_lava",
|
minetest.sound_play("default_cool_lava",
|
||||||
{pos = pos, max_hear_distance = 16, gain = 0.25})
|
{pos = pos, max_hear_distance = 16, gain = 0.25})
|
||||||
|
@ -282,6 +323,10 @@ minetest.register_abm({
|
||||||
chance = 150,
|
chance = 150,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
fun_caves.soft_boom(pos)
|
fun_caves.soft_boom(pos)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -294,6 +339,10 @@ minetest.register_abm({
|
||||||
chance = 50,
|
chance = 50,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
fun_caves.soft_boom(pos)
|
fun_caves.soft_boom(pos)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -306,6 +355,10 @@ minetest.register_abm({
|
||||||
interval = fun_caves.time_factor,
|
interval = fun_caves.time_factor,
|
||||||
chance = 25,
|
chance = 25,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Check for stem under the cap.
|
-- Check for stem under the cap.
|
||||||
local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
|
local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
|
||||||
if not node_under or node_under.name ~= "fun_caves:giant_mushroom_stem" then
|
if not node_under or node_under.name ~= "fun_caves:giant_mushroom_stem" then
|
||||||
|
@ -321,6 +374,10 @@ minetest.register_abm({
|
||||||
interval = 2 * fun_caves.time_factor,
|
interval = 2 * fun_caves.time_factor,
|
||||||
chance = 110,
|
chance = 110,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if (minetest.get_node_light(pos, nil) or 99) >= fun_caves.light_max + 2 then
|
if (minetest.get_node_light(pos, nil) or 99) >= fun_caves.light_max + 2 then
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
return
|
return
|
||||||
|
@ -338,6 +395,10 @@ minetest.register_abm({
|
||||||
chance = 100,
|
chance = 100,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
pos.y = pos.y - 1
|
pos.y = pos.y - 1
|
||||||
local node_below = minetest.get_node_or_nil(pos)
|
local node_below = minetest.get_node_or_nil(pos)
|
||||||
if node_below and node_below.name == 'air' then
|
if node_below and node_below.name == 'air' then
|
||||||
|
@ -352,6 +413,10 @@ minetest.register_abm({
|
||||||
chance = 40,
|
chance = 40,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -363,29 +428,14 @@ minetest.register_abm({
|
||||||
interval = fun_caves.time_factor,
|
interval = fun_caves.time_factor,
|
||||||
chance = 10,
|
chance = 10,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
minetest.set_node(pos, ice_node)
|
minetest.set_node(pos, ice_node)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
if false then
|
|
||||||
minetest.register_abm({
|
|
||||||
nodenames = {"fun_caves:pyramid_1"},
|
|
||||||
interval = 1,
|
|
||||||
chance = 1,
|
|
||||||
action = function(pos, node)
|
|
||||||
local p = table.copy(pos)
|
|
||||||
for i = 1, 20 do
|
|
||||||
p.y = p.y + 1
|
|
||||||
local node = minetest.get_node_or_nil(p)
|
|
||||||
if not node or node.name ~= 'air' then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
minetest.set_node(pos, {name = 'default:sandstone'})
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
local no_tree_grow = {'fun_caves:bark', 'fun_caves:leaves'}
|
local no_tree_grow = {'fun_caves:bark', 'fun_caves:leaves'}
|
||||||
local wood_nodes = {{name = 'fun_caves:diamondwood'}, {name = 'fun_caves:ironwood'}, {name = 'fun_caves:sap'}, {name = 'fun_caves:tree'}}
|
local wood_nodes = {{name = 'fun_caves:diamondwood'}, {name = 'fun_caves:ironwood'}, {name = 'fun_caves:sap'}, {name = 'fun_caves:tree'}}
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
|
@ -394,6 +444,10 @@ minetest.register_abm({
|
||||||
chance = 900,
|
chance = 900,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local new_pos = minetest.find_node_near(pos, 1, no_tree_grow)
|
local new_pos = minetest.find_node_near(pos, 1, no_tree_grow)
|
||||||
if new_pos then
|
if new_pos then
|
||||||
return
|
return
|
||||||
|
@ -425,6 +479,10 @@ minetest.register_abm({
|
||||||
interval = fun_caves.time_factor,
|
interval = fun_caves.time_factor,
|
||||||
chance = 10,
|
chance = 10,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if pos.y <= 11168 or pos.y >= 15168 then
|
if pos.y <= 11168 or pos.y >= 15168 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -432,6 +490,10 @@ minetest.register_abm({
|
||||||
local p1 = vector.subtract(pos, 1)
|
local p1 = vector.subtract(pos, 1)
|
||||||
local p2 = vector.add(pos, 1)
|
local p2 = vector.add(pos, 1)
|
||||||
local positions = minetest.find_nodes_in_area(p1, p2, air_list)
|
local positions = minetest.find_nodes_in_area(p1, p2, air_list)
|
||||||
|
if not (positions and type(positions) == 'table') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local minetest_get_node_or_nil = minetest.get_node_or_nil
|
local minetest_get_node_or_nil = minetest.get_node_or_nil
|
||||||
local minetest_set_node = minetest.set_node
|
local minetest_set_node = minetest.set_node
|
||||||
for _, p3 in pairs(positions) do
|
for _, p3 in pairs(positions) do
|
||||||
|
@ -451,6 +513,10 @@ minetest.register_abm({
|
||||||
chance = 50,
|
chance = 50,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if (minetest.get_node_light(pos, nil) or 99) >= fun_caves.light_max + 2 then
|
if (minetest.get_node_light(pos, nil) or 99) >= fun_caves.light_max + 2 then
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
return
|
return
|
||||||
|
@ -492,6 +558,10 @@ minetest.register_abm({
|
||||||
interval = 2 * fun_caves.time_factor,
|
interval = 2 * fun_caves.time_factor,
|
||||||
chance = 75,
|
chance = 75,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local pos_up = {x=pos.x,y=pos.y+1,z=pos.z}
|
local pos_up = {x=pos.x,y=pos.y+1,z=pos.z}
|
||||||
local node_up = minetest.get_node_or_nil(pos_up)
|
local node_up = minetest.get_node_or_nil(pos_up)
|
||||||
if not node_up or node_up.name ~= "air" then
|
if not node_up or node_up.name ~= "air" then
|
||||||
|
@ -515,6 +585,10 @@ minetest.register_abm({
|
||||||
interval = 2 * fun_caves.time_factor,
|
interval = 2 * fun_caves.time_factor,
|
||||||
chance = 75,
|
chance = 75,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if pos.y > 0 then
|
if pos.y > 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -539,6 +613,10 @@ minetest.register_abm({
|
||||||
interval = 5 * fun_caves.time_factor,
|
interval = 5 * fun_caves.time_factor,
|
||||||
chance = 375,
|
chance = 375,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Clumsy, but it's the best way to limit them to caves.
|
-- Clumsy, but it's the best way to limit them to caves.
|
||||||
if pos.y > 0 then
|
if pos.y > 0 then
|
||||||
return
|
return
|
||||||
|
@ -569,6 +647,10 @@ minetest.register_abm({
|
||||||
interval = 9 * fun_caves.time_factor,
|
interval = 9 * fun_caves.time_factor,
|
||||||
chance = 1000,
|
chance = 1000,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local pos_up = {x=pos.x,y=pos.y+1,z=pos.z}
|
local pos_up = {x=pos.x,y=pos.y+1,z=pos.z}
|
||||||
local node_up = minetest.get_node_or_nil(pos_up)
|
local node_up = minetest.get_node_or_nil(pos_up)
|
||||||
if not node_up or node_up.name ~= "air" then
|
if not node_up or node_up.name ~= "air" then
|
||||||
|
@ -594,6 +676,10 @@ minetest.register_abm({
|
||||||
interval = 3 * fun_caves.time_factor,
|
interval = 3 * fun_caves.time_factor,
|
||||||
chance = 300,
|
chance = 300,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if not fun_caves.hot_spike then
|
if not fun_caves.hot_spike then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -639,8 +725,16 @@ minetest.register_abm({
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
chance = 32767,
|
chance = 32767,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local ps = {}
|
local ps = {}
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
|
if not (players and type(players) == 'table') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
for i = 1, #players do
|
for i = 1, #players do
|
||||||
local pp = players[i]:getpos()
|
local pp = players[i]:getpos()
|
||||||
local pd = vector.subtract(pp, pos)
|
local pd = vector.subtract(pp, pos)
|
||||||
|
@ -669,6 +763,10 @@ minetest.register_abm({
|
||||||
interval = 3 * fun_caves.time_factor,
|
interval = 3 * fun_caves.time_factor,
|
||||||
chance = 330,
|
chance = 330,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
if not (pos and node) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
minetest.set_node(pos, {name="default:dirt"})
|
minetest.set_node(pos, {name="default:dirt"})
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -706,6 +804,10 @@ minetest.after(0, function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function add_effects(pos, radius)
|
local function add_effects(pos, radius)
|
||||||
|
if not (pos and radius and type(radius) == 'number') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
minetest.add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
amount = 128,
|
amount = 128,
|
||||||
time = 1,
|
time = 1,
|
||||||
|
@ -724,6 +826,10 @@ local function add_effects(pos, radius)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function destroy(pos, cid)
|
local function destroy(pos, cid)
|
||||||
|
if not (pos and cid) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local def = cid_data[cid]
|
local def = cid_data[cid]
|
||||||
if not def or minetest.is_protected(pos, "") then
|
if not def or minetest.is_protected(pos, "") then
|
||||||
return
|
return
|
||||||
|
@ -744,6 +850,10 @@ local function destroy(pos, cid)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function explode(pos, radius)
|
local function explode(pos, radius)
|
||||||
|
if not (pos and radius and type(radius) == 'number') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local pos = vector.round(pos)
|
local pos = vector.round(pos)
|
||||||
local vm = VoxelManip()
|
local vm = VoxelManip()
|
||||||
local p1 = vector.subtract(pos, radius)
|
local p1 = vector.subtract(pos, radius)
|
||||||
|
@ -778,6 +888,10 @@ local function explode(pos, radius)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function calc_velocity(pos1, pos2, old_vel, power)
|
local function calc_velocity(pos1, pos2, old_vel, power)
|
||||||
|
if not (pos1 and pos2 and old_vel and power) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local vel = vector.direction(pos1, pos2)
|
local vel = vector.direction(pos1, pos2)
|
||||||
vel = vector.normalize(vel)
|
vel = vector.normalize(vel)
|
||||||
vel = vector.multiply(vel, power)
|
vel = vector.multiply(vel, power)
|
||||||
|
@ -793,9 +907,17 @@ local function calc_velocity(pos1, pos2, old_vel, power)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function entity_physics(pos, radius)
|
local function entity_physics(pos, radius)
|
||||||
|
if not (pos and radius and type(radius) == 'number') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Make the damage radius larger than the destruction radius
|
-- Make the damage radius larger than the destruction radius
|
||||||
radius = radius * 2
|
radius = radius * 2
|
||||||
local objs = minetest.get_objects_inside_radius(pos, radius)
|
local objs = minetest.get_objects_inside_radius(pos, radius)
|
||||||
|
if not (objs and type(objs) == 'table') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local math_max = math.max
|
local math_max = math.max
|
||||||
local vector_distance = vector.distance
|
local vector_distance = vector.distance
|
||||||
for _, obj in pairs(objs) do
|
for _, obj in pairs(objs) do
|
||||||
|
|
6
init.lua
6
init.lua
|
@ -227,11 +227,15 @@ function fun_caves.hunger_change(player, change)
|
||||||
end
|
end
|
||||||
|
|
||||||
local hp = player:get_hp()
|
local hp = player:get_hp()
|
||||||
|
if not (hp and type(hp) == 'number') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if change < 0 or hp >= 16 then
|
if change < 0 or hp >= 16 then
|
||||||
fun_caves.db.hunger[player_name] = math.min(20, math.max(0, fun_caves.db.hunger[player_name] + change))
|
fun_caves.db.hunger[player_name] = math.min(20, math.max(0, fun_caves.db.hunger[player_name] + change))
|
||||||
player:hud_change(fun_caves.hunger_id[player_name], 'number', fun_caves.db.hunger[player_name])
|
player:hud_change(fun_caves.hunger_id[player_name], 'number', fun_caves.db.hunger[player_name])
|
||||||
if fun_caves.db.hunger[player_name] == 0 then
|
if fun_caves.db.hunger[player_name] == 0 then
|
||||||
player:set_hp(player:get_hp() - 1)
|
player:set_hp(hp - 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue