2019-01-26 07:39:30 +00:00
|
|
|
--Inspired from Andrey's bandages mod
|
|
|
|
|
2020-05-02 09:36:06 +00:00
|
|
|
ctf_bandages = {}
|
2021-02-09 00:03:03 +00:00
|
|
|
ctf_bandages.heal_percent = 0.75 -- Percentage of total HP to be healed
|
2019-01-26 07:39:30 +00:00
|
|
|
|
|
|
|
minetest.register_craftitem("ctf_bandages:bandage", {
|
2020-05-03 06:40:59 +00:00
|
|
|
description = "Bandage\n\n" ..
|
2020-05-03 06:03:24 +00:00
|
|
|
"Heals teammates for 3-4 HP until target's HP is equal to " ..
|
|
|
|
ctf_bandages.heal_percent * 100 .. "% of their maximum HP",
|
2019-01-26 07:39:30 +00:00
|
|
|
inventory_image = "ctf_bandages_bandage.png",
|
2020-10-24 22:20:16 +00:00
|
|
|
stack_max = 1,
|
2019-01-26 07:39:30 +00:00
|
|
|
on_use = function(itemstack, player, pointed_thing)
|
2021-02-09 00:03:03 +00:00
|
|
|
if pointed_thing.type ~= "object" then return end
|
|
|
|
|
2019-01-26 07:39:30 +00:00
|
|
|
local object = pointed_thing.ref
|
2021-02-09 00:03:03 +00:00
|
|
|
if not object:is_player() then return end
|
|
|
|
|
2019-01-26 07:39:30 +00:00
|
|
|
local pname = object:get_player_name()
|
|
|
|
local name = player:get_player_name()
|
2021-02-09 00:03:03 +00:00
|
|
|
|
2019-01-26 07:39:30 +00:00
|
|
|
if ctf.player(pname).team == ctf.player(name).team then
|
|
|
|
local hp = object:get_hp()
|
2021-02-09 00:03:03 +00:00
|
|
|
local limit = ctf_bandages.heal_percent * object:get_properties().hp_max
|
|
|
|
|
2021-03-29 21:00:46 +00:00
|
|
|
if hp <= 0 then
|
|
|
|
hud_event.new(name, {
|
|
|
|
name = "ctf_bandages:dead",
|
|
|
|
color = "warning",
|
|
|
|
value = pname .. " is dead!",
|
|
|
|
})
|
|
|
|
elseif hp >= limit then
|
|
|
|
hud_event.new(name, {
|
|
|
|
name = "ctf_bandages:limit",
|
|
|
|
color = "warning",
|
|
|
|
value = pname .. " already has " .. limit .. " HP!",
|
|
|
|
})
|
|
|
|
else
|
2021-02-09 00:03:03 +00:00
|
|
|
local hp_add = math.random(3,4)
|
|
|
|
|
|
|
|
kill_assist.add_heal_assist(pname, hp_add)
|
|
|
|
hp = hp + hp_add
|
|
|
|
|
2020-05-02 09:36:06 +00:00
|
|
|
if hp > limit then
|
|
|
|
hp = limit
|
2019-01-26 07:39:30 +00:00
|
|
|
end
|
2021-02-09 00:03:03 +00:00
|
|
|
|
2019-01-26 07:39:30 +00:00
|
|
|
object:set_hp(hp)
|
2021-03-29 21:00:46 +00:00
|
|
|
hud_event.new(pname, {
|
|
|
|
name = "ctf_bandages:heal",
|
|
|
|
color = 0xC1FF44,
|
|
|
|
value = name .. " healed you!",
|
|
|
|
})
|
2019-01-26 07:39:30 +00:00
|
|
|
end
|
|
|
|
else
|
2021-03-29 21:00:46 +00:00
|
|
|
hud_event.new(name, {
|
|
|
|
name = "ctf_bandages:team",
|
|
|
|
color = "warning",
|
|
|
|
value = pname .. " isn't in your team!",
|
|
|
|
})
|
2019-01-26 07:39:30 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|