-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdamage.lua
50 lines (45 loc) · 1.73 KB
/
damage.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
--local bc = better_commands
---Deals damage; copied from Mineclonia's mcl_util.deal_damage
---@param target minetest.ObjectRef
---@param damage integer
---@param reason table?
---@param damage_immortal? boolean
function better_commands.deal_damage(target, damage, reason, damage_immortal)
local luaentity = target:get_luaentity()
if luaentity then
if luaentity.deal_damage then -- Mobs Redo/Mobs MC
--minetest.log("deal_damage")
luaentity:deal_damage(damage, reason or {type = "generic"})
return
elseif luaentity.hurt then -- Animalia
--minetest.log("hurt/indicate_damage")
luaentity:hurt(damage)
luaentity:indicate_damage()
return
elseif luaentity.health then -- Mobs Redo/Mobs MC/NSSM
-- local puncher = mcl_reason and mcl_reason.direct or target
-- target:punch(puncher, 1.0, {full_punch_interval = 1.0, damage_groups = {fleshy = damage}}, vector.direction(puncher:get_pos(), target:get_pos()), damage)
if luaentity.health > 0 then
--minetest.log("luaentity.health")
luaentity.health = luaentity.health - damage
luaentity:check_for_death(reason)
--minetest.log(luaentity.health)
end
return
end
end
local hp = target:get_hp()
local armorgroups = target:get_armor_groups()
if hp > 0 and armorgroups and (damage_immortal or not armorgroups.immortal) then
--minetest.log("set_hp")
target:set_hp(hp - damage, reason)
end
--minetest.log("nothing")
end
-- Make sure players always die when /killed
minetest.register_on_player_hpchange(function(player, hp_change, reason)
if reason.better_commands == "kill" then
return math.min(hp_change, -1000000000), true
end
return hp_change
end, true)