capturetheflag/mods/ctf/ctf_bandages/init.lua
Anthony-De 49f4e6fd47
Add kill assists (#755)
* Update teams.lua

* Update teams.lua and init.lua

* Update teams.lua and init.lua

* Update teams.lua and init.lua

* Update teams.lua and init.lua Kill assist implemented

* Update init.lua Remove unused variables

* Added ctf.clearAssists function
Only awards those who did more that 50% of damage
Clears attackers stats after suicide

* Remove unused variable

* Minor modifications

renamed ctf.clearAssists to ctf.clear_assists
changed playerName to player

* Cap assist points

* Reaching full health while in combat clears assist data

* split points between assisting players by damage done

* Reworked assist data storage to work with a table rather than player metadata

* Fix lua check

* Removed duplicate scoring

* Change kill assist color

* Health regen subtracts from assist.
Suicide gives assist points

* Fixed accessing nil value for max_hp

* Corrected max_hp

* hardcode hp list for max hp
2021-02-01 08:24:29 -08:00

44 lines
1.3 KiB
Lua

--Inspired from Andrey's bandages mod
ctf_bandages = {}
ctf_bandages.heal_percent = 0.75 --Percentage of total HP to be healed
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",
inventory_image = "ctf_bandages_bandage.png",
stack_max = 1,
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()
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)
ctf.add_heal_assist(pname, hp_add)
hp = hp + hp_add
if hp > limit then
hp = limit
end
object:set_hp(hp)
minetest.chat_send_player(pname, minetest.colorize("#C1FF44", name .. " has healed you!"))
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,
})