2020-11-28 18:13:52 +00:00
|
|
|
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
|
|
|
if reason.type ~= "punch" or not reason.object or not reason.object:is_player() then
|
|
|
|
return hp_change
|
|
|
|
end
|
2020-11-08 17:08:14 +00:00
|
|
|
|
2020-11-28 18:13:52 +00:00
|
|
|
local class = ctf_classes.get(reason.object)
|
2020-10-14 03:00:21 +00:00
|
|
|
|
2020-11-28 18:13:52 +00:00
|
|
|
if class.properties.melee_bonus and reason.object:get_wielded_item():get_name():find("sword") then
|
|
|
|
local change = hp_change - class.properties.melee_bonus
|
2020-11-08 18:09:15 +00:00
|
|
|
|
2020-11-28 18:13:52 +00:00
|
|
|
if player:get_hp() + change <= 0 and player:get_hp() + hp_change > 0 then
|
|
|
|
local wielded_item = reason.object:get_wielded_item()
|
2020-10-14 03:00:21 +00:00
|
|
|
|
2020-11-28 18:13:52 +00:00
|
|
|
for i = 1, #ctf.registered_on_killedplayer do
|
|
|
|
ctf.registered_on_killedplayer[i](
|
|
|
|
player:get_player_name(),
|
|
|
|
reason.object:get_player_name(),
|
|
|
|
wielded_item,
|
|
|
|
wielded_item:get_tool_capabilities()
|
|
|
|
)
|
|
|
|
end
|
2020-11-08 01:17:21 +00:00
|
|
|
end
|
2020-11-28 18:13:52 +00:00
|
|
|
|
|
|
|
return change
|
2020-10-13 15:42:41 +00:00
|
|
|
end
|
2020-11-28 18:13:52 +00:00
|
|
|
|
|
|
|
return hp_change
|
|
|
|
end, true)
|