Damage logic consolidation
This commit is contained in:
parent
4dd97d3b2c
commit
baa54a6cd7
@ -9,6 +9,18 @@ nodecore.register_healthfx,
|
||||
nodecore.registered_healthfx
|
||||
= nodecore.mkreg()
|
||||
|
||||
minetest.register_privilege("ncdqd", {
|
||||
description = "Invulnerable to all kinds of damage",
|
||||
give_to_singleplayer = false,
|
||||
give_to_admin = false
|
||||
})
|
||||
|
||||
function nodecore.player_can_take_damage(player)
|
||||
return minetest.settings:get_bool("enable_damage")
|
||||
and not player:get_armor_groups().immortal
|
||||
and not minetest.check_player_privs(player, "ncdqd")
|
||||
end
|
||||
|
||||
local handnode = minetest.registered_items["nc_player_hand:hand"]
|
||||
function nodecore.register_virtual_item(name, def)
|
||||
return minetest.register_node(name, nodecore.underride(def, {
|
||||
@ -32,7 +44,7 @@ local function rounddist(n)
|
||||
end
|
||||
|
||||
local function checkinv(player)
|
||||
local dmg = minetest.settings:get_bool("enable_damage")
|
||||
local dmg = nodecore.player_can_take_damage(player)
|
||||
local inv = player:get_inventory()
|
||||
local size = inv:get_size("main")
|
||||
local max = size - 1
|
||||
|
@ -7,7 +7,7 @@ local hurtcache = {}
|
||||
|
||||
minetest.register_on_player_hpchange(function(player, hp)
|
||||
local orig = player:get_hp()
|
||||
if player:get_armor_groups().immortal then
|
||||
if not nodecore.player_can_take_damage(player) then
|
||||
return orig
|
||||
end
|
||||
local pname
|
||||
|
@ -102,6 +102,12 @@ local function walkspeed(player, cached, set)
|
||||
end
|
||||
end
|
||||
|
||||
local function nodmgbreath(player)
|
||||
if (not nodecore.player_can_take_damage(player)) and player:get_breath() < 11 then
|
||||
player:set_breath(11)
|
||||
end
|
||||
end
|
||||
|
||||
local cache = {}
|
||||
minetest.register_globalstep(function()
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
@ -118,6 +124,7 @@ minetest.register_globalstep(function()
|
||||
setfootsteps(player, cached, set)
|
||||
fallspeed(player, cached, set)
|
||||
walkspeed(player, cached, set)
|
||||
nodmgbreath(player)
|
||||
|
||||
if set.props then player:set_properties(set.props) end
|
||||
if set.physics then player:set_physics_override(set.physics) end
|
||||
|
Loading…
x
Reference in New Issue
Block a user