Fix up medkit interrupt reasons (#734)

* Bugfix of "Add reason to medkit"
 * Fix reasons while attack and damage
 * Remove `die` reason, add `attack` reason

* Change suggested code

* Fix doc

* fix line contains trailing whitespace

* Update init.lua

Co-authored-by: LoneWolfHT <lonewolf04361@gmail.com>
This commit is contained in:
Emojigit 2021-01-06 11:56:55 +08:00 committed by GitHub
parent 518e3f0807
commit 88c326f13d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -47,17 +47,17 @@ local function start_healing(stack, player)
end
-- Interrupt reason can be:
-- damage: get damage from another player
-- move: move more then 1m
-- die: die because any reason
-- Interrupt reasons:
-- attack: Attacked another player
-- move: Moved 1m away from initial healing pos
-- damage: Damaged by another player
local function reason_handler(reason)
if reason == "damage" then
return " because someone damaged you!"
if reason == "attack" then
return " because you attacked other player!"
elseif reason == "move" then
return " because you moved!"
elseif reason == "die" then
return " because you died!"
elseif reason == "damage" then
return " because someone damaged you!"
else
return "!"
end
@ -132,12 +132,12 @@ end)
minetest.register_on_player_hpchange(function(player, hp, reason)
if hp < 0 then
if players[player:get_player_name()] then
stop_healing(player, "die")
stop_healing(player, "damage")
end
if reason and reason.type == "punch" then
local hitter = reason.object
if hitter and players[hitter:get_player_name()] then
stop_healing(hitter, "damage")
stop_healing(hitter, "attack")
end
end
end