capturetheflag/mods/ctf/ctf_bandages/init.lua

37 lines
1.1 KiB
Lua
Raw Normal View History

2019-01-26 07:39:30 +00:00
--Inspired from Andrey's bandages mod
local healing_limit = 15
minetest.register_craftitem("ctf_bandages:bandage", {
2020-03-13 21:58:42 +00:00
description = "Bandage\n\nHeals teammates for 3-4 HP until HP is equal to "..healing_limit,
2019-01-26 07:39:30 +00:00
inventory_image = "ctf_bandages_bandage.png",
on_use = function(itemstack, player, 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 = 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
hp = hp + math.random(3,4)
if hp > healing_limit then
hp = healing_limit
end
object:set_hp(hp)
itemstack:take_item()
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,
})