2019-01-26 13:09:30 +05:30
|
|
|
--Inspired from Andrey's bandages mod
|
|
|
|
|
2020-05-02 15:06:06 +05:30
|
|
|
ctf_bandages = {}
|
2021-02-08 19:03:03 -05:00
|
|
|
ctf_bandages.heal_percent = 0.75 -- Percentage of total HP to be healed
|
2019-01-26 13:09:30 +05:30
|
|
|
|
|
|
|
minetest.register_craftitem("ctf_bandages:bandage", {
|
2020-05-03 12:10:59 +05:30
|
|
|
description = "Bandage\n\n" ..
|
2020-05-03 11:33:24 +05:30
|
|
|
"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 13:09:30 +05:30
|
|
|
inventory_image = "ctf_bandages_bandage.png",
|
2020-10-24 16:20:16 -06:00
|
|
|
stack_max = 1,
|
2019-01-26 13:09:30 +05:30
|
|
|
on_use = function(itemstack, player, pointed_thing)
|
2021-02-08 19:03:03 -05:00
|
|
|
if pointed_thing.type ~= "object" then return end
|
|
|
|
|
2019-01-26 13:09:30 +05:30
|
|
|
local object = pointed_thing.ref
|
2021-02-08 19:03:03 -05:00
|
|
|
if not object:is_player() then return end
|
|
|
|
|
2019-01-26 13:09:30 +05:30
|
|
|
local pname = object:get_player_name()
|
|
|
|
local name = player:get_player_name()
|
2021-02-08 19:03:03 -05:00
|
|
|
|
2019-01-26 13:09:30 +05:30
|
|
|
if ctf.player(pname).team == ctf.player(name).team then
|
|
|
|
local hp = object:get_hp()
|
2021-02-08 19:03:03 -05:00
|
|
|
local limit = ctf_bandages.heal_percent * object:get_properties().hp_max
|
|
|
|
|
2020-05-02 15:06:06 +05:30
|
|
|
if hp > 0 and hp < limit then
|
2021-02-08 19:03:03 -05:00
|
|
|
local hp_add = math.random(3,4)
|
|
|
|
|
|
|
|
kill_assist.add_heal_assist(pname, hp_add)
|
|
|
|
hp = hp + hp_add
|
|
|
|
|
2020-05-02 15:06:06 +05:30
|
|
|
if hp > limit then
|
|
|
|
hp = limit
|
2019-01-26 13:09:30 +05:30
|
|
|
end
|
2021-02-08 19:03:03 -05:00
|
|
|
|
2019-01-26 13:09:30 +05:30
|
|
|
object:set_hp(hp)
|
2019-07-13 06:48:48 +05:30
|
|
|
minetest.chat_send_player(pname, minetest.colorize("#C1FF44", name .. " has healed you!"))
|
2021-02-08 19:03:03 -05:00
|
|
|
|
2019-01-26 13:09:30 +05:30
|
|
|
return itemstack
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(name, pname .. " has " .. hp .. " HP. You can't heal them.")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(name, pname.." isn't in your team!")
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|