diff --git a/.luacheckrc b/.luacheckrc index 2bce17e..02a89f3 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -16,7 +16,7 @@ globals = { "ctf_colors", "hudkit", "default", "treasurer", "ChatCmdBuilder", "ctf_map", "ctf_match", "ctf_stats", "ctf_treasure", "ctf_playertag", "chatplus", "irc", "armor", "vote", "give_initial_stuff", "hud_score", "physics", "tsm_chests", - "armor", "shooter", "grenades", "ctf_classes" + "armor", "shooter", "grenades", "ctf_classes", "ctf_bandages" } read_globals = { diff --git a/mods/ctf/ctf_classes/init.lua b/mods/ctf/ctf_classes/init.lua index da28846..9c449cb 100644 --- a/mods/ctf/ctf_classes/init.lua +++ b/mods/ctf/ctf_classes/init.lua @@ -5,7 +5,7 @@ ctf_classes = { dofile(minetest.get_modpath("ctf_classes") .. "/api.lua") dofile(minetest.get_modpath("ctf_classes") .. "/gui.lua") -dofile(minetest.get_modpath("ctf_classes") .. "/regen.lua") +dofile(minetest.get_modpath("ctf_classes") .. "/medic.lua") dofile(minetest.get_modpath("ctf_classes") .. "/ranged.lua") dofile(minetest.get_modpath("ctf_classes") .. "/items.lua") dofile(minetest.get_modpath("ctf_classes") .. "/flags.lua") diff --git a/mods/ctf/ctf_classes/regen.lua b/mods/ctf/ctf_classes/medic.lua similarity index 60% rename from mods/ctf/ctf_classes/regen.lua rename to mods/ctf/ctf_classes/medic.lua index 44f67a4..b34aec8 100644 --- a/mods/ctf/ctf_classes/regen.lua +++ b/mods/ctf/ctf_classes/medic.lua @@ -63,3 +63,37 @@ minetest.register_globalstep(function(delta) regen_update() end) + +local bandage_on_use = minetest.registered_items["ctf_bandages:bandage"].on_use +minetest.override_item("ctf_bandages:bandage", { + on_use = function(stack, user, pointed_thing) + if pointed_thing.type ~= "object" then + return + end + local object = pointed_thing.ref + if not object:is_player() then + return + end + local pname = object:get_player_name() + local name = user:get_player_name() + if ctf.player(pname).team == ctf.player(name).team then + local hp = object:get_hp() + local limit = ctf_bandages.heal_percent * object:get_properties().hp_max + if hp > 0 and hp < limit then + local main, match = ctf_stats.player(name) + if main and match then + local reward = 5 + main.score = main.score + reward + match.score = match.score + reward + + hud_score.new(name, { + name = "ctf_stats:heal_score", + color = "0x00FF00", + value = reward + }) + end + end + end + return bandage_on_use(stack, user, pointed_thing) + end +}) diff --git a/mods/ctf/ctf_classes/mod.conf b/mods/ctf/ctf_classes/mod.conf index ba549d8..f0714a9 100644 --- a/mods/ctf/ctf_classes/mod.conf +++ b/mods/ctf/ctf_classes/mod.conf @@ -1,3 +1,3 @@ name = ctf_classes -depends = ctf, ctf_flag, ctf_colors, ctf_map_core, ctf_bandages, physics, shooter, hpregen, give_initial_stuff, dropondie, crafting +depends = ctf, ctf_flag, ctf_colors, ctf_map_core, ctf_stats, ctf_bandages, physics, shooter, hpregen, give_initial_stuff, dropondie, crafting description = Adds classes, including knight, shooter, and medic