From 7c3d35bd0397e58c6ed81e040def0bf5f8dd8c94 Mon Sep 17 00:00:00 2001 From: MinetestSam <42088654+MinetestSam@users.noreply.github.com> Date: Sat, 2 May 2020 15:06:06 +0530 Subject: [PATCH] ctf_bandages: Add percentage-based healing (#609) Remove HP hardcoding; heal up to a certain percentage of player's `hp_max` property. --- mods/ctf/ctf_bandages/init.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mods/ctf/ctf_bandages/init.lua b/mods/ctf/ctf_bandages/init.lua index 37f9a95..5924160 100644 --- a/mods/ctf/ctf_bandages/init.lua +++ b/mods/ctf/ctf_bandages/init.lua @@ -1,9 +1,10 @@ --Inspired from Andrey's bandages mod -local healing_limit = 15 +ctf_bandages = {} +ctf_bandages.heal_percent = 0.75 --Percentage of total HP to be healed minetest.register_craftitem("ctf_bandages:bandage", { - description = "Bandage\n\nHeals teammates for 3-4 HP until HP is equal to "..healing_limit, + description = "Bandage\n\nHeals teammates for 3-4 HP until HP is equal to 75% of the total HP", inventory_image = "ctf_bandages_bandage.png", on_use = function(itemstack, player, pointed_thing) if pointed_thing.type ~= "object" then @@ -17,10 +18,11 @@ minetest.register_craftitem("ctf_bandages:bandage", { local name = player:get_player_name() if ctf.player(pname).team == ctf.player(name).team then local hp = object:get_hp() - if hp > 0 and hp < healing_limit then + local limit = ctf_bandages.heal_percent * object:get_properties().hp_max + if hp > 0 and hp < limit then hp = hp + math.random(3,4) - if hp > healing_limit then - hp = healing_limit + if hp > limit then + hp = limit end object:set_hp(hp) itemstack:take_item()