capturetheflag/mods/ctf/ctf_bandages/init.lua

47 lines
1.3 KiB
Lua
Raw Normal View History

2019-01-26 07:39:30 +00:00
--Inspired from Andrey's bandages mod
ctf_bandages = {}
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", {
description = "Bandage\n\n" ..
"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",
stack_max = 1,
2019-01-26 07:39:30 +00:00
on_use = function(itemstack, player, pointed_thing)
if pointed_thing.type ~= "object" then return end
2019-01-26 07:39:30 +00:00
local object = pointed_thing.ref
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()
2019-01-26 07:39:30 +00:00
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 hp_add = math.random(3,4)
kill_assist.add_heal_assist(pname, hp_add)
hp = hp + hp_add
if hp > limit then
hp = limit
2019-01-26 07:39:30 +00:00
end
2019-01-26 07:39:30 +00:00
object:set_hp(hp)
minetest.chat_send_player(pname, minetest.colorize("#C1FF44", name .. " has healed you!"))
2019-01-26 07:39:30 +00:00
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,
})