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
This commit is contained in:
parent
6515f1e189
commit
49f4e6fd47
6 changed files with 92 additions and 23 deletions
|
@ -437,6 +437,86 @@ minetest.register_on_joinplayer(function(player)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local kill_assists = {}
|
||||||
|
function ctf.clear_assists(victim)
|
||||||
|
if kill_assists[victim] and kill_assists[victim]["is_empty"] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
kill_assists[victim] = {}
|
||||||
|
kill_assists[victim]["is_empty"] = true
|
||||||
|
kill_assists[victim]["players"] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function ctf.add_assist(victim, attacker, damage)-- player names
|
||||||
|
kill_assists[victim]["players"][attacker] = (kill_assists[victim]["players"][attacker] or 0) + damage
|
||||||
|
kill_assists[victim]["is_empty"] = false
|
||||||
|
end
|
||||||
|
|
||||||
|
function ctf.add_heal_assist(victim, healed_hp)
|
||||||
|
if kill_assists[victim] and kill_assists[victim]["is_empty"] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not kill_assists[victim] then
|
||||||
|
ctf.clear_assists(victim)
|
||||||
|
end
|
||||||
|
for name, damage in pairs(kill_assists[victim]["players"]) do
|
||||||
|
kill_assists[victim]["players"][name] = math.max(damage - healed_hp, 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ctf.reward_assists(victim, killer, reward, is_suicide)
|
||||||
|
local hitLength = 0
|
||||||
|
for a,b in pairs(kill_assists[victim]["players"]) do
|
||||||
|
hitLength = hitLength + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if hitLength > 0 then
|
||||||
|
for name, damage in pairs(kill_assists[victim]["players"]) do
|
||||||
|
local playerExists = minetest.get_player_by_name(name)
|
||||||
|
if playerExists and name ~= victim then
|
||||||
|
local hpClass = {
|
||||||
|
knight = 30,
|
||||||
|
shooter = 16,
|
||||||
|
medic = 20
|
||||||
|
}
|
||||||
|
local victimClass = minetest.get_player_by_name(victim):get_meta():to_table().fields["ctf_classes:class"]
|
||||||
|
local playerHP_max = (hpClass[victimClass] or hpClass.shooter)-8
|
||||||
|
local standard = 0
|
||||||
|
local percentofhelp = damage / playerHP_max
|
||||||
|
if name ~= killer then
|
||||||
|
standard = 0.5
|
||||||
|
percentofhelp = math.min(percentofhelp, 0.75)
|
||||||
|
else
|
||||||
|
percentofhelp = math.min(percentofhelp, 1)
|
||||||
|
end
|
||||||
|
if percentofhelp >= standard then
|
||||||
|
local main, match = ctf_stats.player(name)
|
||||||
|
local newReward = math.floor((reward * percentofhelp)*100)/100
|
||||||
|
match.score = match.score + newReward
|
||||||
|
main.score = main.score + newReward
|
||||||
|
if newReward < 1 then
|
||||||
|
newReward = 1
|
||||||
|
end
|
||||||
|
local colour = "0x00FFFF"
|
||||||
|
if name == killer then
|
||||||
|
colour = "0x00FF00"
|
||||||
|
main.kills = main.kills + 1
|
||||||
|
match.kills = match.kills + 1
|
||||||
|
match.kills_since_death = match.kills_since_death + 1
|
||||||
|
end
|
||||||
|
local _ = hud_score.new(name, {
|
||||||
|
name = "ctf_stats:kill_score",
|
||||||
|
color = colour,
|
||||||
|
value = newReward
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
ctf_stats.request_save()
|
||||||
|
ctf.clear_assists(victim)
|
||||||
|
end
|
||||||
|
|
||||||
-- Disable friendly fire.
|
-- Disable friendly fire.
|
||||||
ctf.registered_on_killedplayer = {}
|
ctf.registered_on_killedplayer = {}
|
||||||
function ctf.register_on_killedplayer(func)
|
function ctf.register_on_killedplayer(func)
|
||||||
|
@ -473,6 +553,8 @@ minetest.register_on_punchplayer(function(player, hitter,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ctf.add_assist(pname, hname, damage)
|
||||||
|
|
||||||
local hp = player:get_hp()
|
local hp = player:get_hp()
|
||||||
if hp == 0 then
|
if hp == 0 then
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -24,7 +24,9 @@ minetest.register_craftitem("ctf_bandages:bandage", {
|
||||||
local limit = ctf_bandages.heal_percent *
|
local limit = ctf_bandages.heal_percent *
|
||||||
object:get_properties().hp_max
|
object:get_properties().hp_max
|
||||||
if hp > 0 and hp < limit then
|
if hp > 0 and hp < limit then
|
||||||
hp = hp + math.random(3,4)
|
local hp_add = math.random(3,4)
|
||||||
|
ctf.add_heal_assist(pname, hp_add)
|
||||||
|
hp = hp + hp_add
|
||||||
if hp > limit then
|
if hp > limit then
|
||||||
hp = limit
|
hp = limit
|
||||||
end
|
end
|
||||||
|
|
|
@ -418,28 +418,9 @@ local function calculateKillReward(victim, killer, toolcaps)
|
||||||
end
|
end
|
||||||
|
|
||||||
ctf.register_on_killedplayer(function(victim, killer, _, toolcaps)
|
ctf.register_on_killedplayer(function(victim, killer, _, toolcaps)
|
||||||
-- Suicide is not encouraged here at CTF
|
|
||||||
if victim == killer then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local main, match = ctf_stats.player(killer)
|
|
||||||
if main and match then
|
|
||||||
local reward = calculateKillReward(victim, killer, toolcaps)
|
local reward = calculateKillReward(victim, killer, toolcaps)
|
||||||
main.kills = main.kills + 1
|
|
||||||
main.score = main.score + reward
|
|
||||||
match.kills = match.kills + 1
|
|
||||||
match.score = match.score + reward
|
|
||||||
match.kills_since_death = match.kills_since_death + 1
|
|
||||||
_needs_save = true
|
|
||||||
|
|
||||||
reward = math.floor(reward * 100) / 100
|
reward = math.floor(reward * 100) / 100
|
||||||
|
ctf.reward_assists(victim, killer, reward, (victim == killer))
|
||||||
hud_score.new(killer, {
|
|
||||||
name = "ctf_stats:kill_score",
|
|
||||||
color = "0x00FF00",
|
|
||||||
value = reward
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_dieplayer(function(player)
|
minetest.register_on_dieplayer(function(player)
|
||||||
|
|
|
@ -153,6 +153,7 @@ minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
if player then
|
if player then
|
||||||
player:hud_remove(potential_cowards[k].hud or 0)
|
player:hud_remove(potential_cowards[k].hud or 0)
|
||||||
|
ctf.clear_assists(k)
|
||||||
end
|
end
|
||||||
|
|
||||||
potential_cowards[k] = nil
|
potential_cowards[k] = nil
|
||||||
|
|
|
@ -16,8 +16,10 @@ local function regen_all()
|
||||||
local newhp = oldhp + hpregen.amount
|
local newhp = oldhp + hpregen.amount
|
||||||
if newhp > player:get_properties().hp_max then
|
if newhp > player:get_properties().hp_max then
|
||||||
newhp = player:get_properties().hp_max
|
newhp = player:get_properties().hp_max
|
||||||
|
ctf.clear_assists(player:get_player_name())
|
||||||
end
|
end
|
||||||
if oldhp ~= newhp then
|
if oldhp ~= newhp then
|
||||||
|
ctf.add_heal_assist(player:get_player_name(), hpregen.amount)
|
||||||
player:set_hp(newhp)
|
player:set_hp(newhp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -117,6 +117,7 @@ minetest.register_globalstep(function(dtime)
|
||||||
if pstat then
|
if pstat then
|
||||||
local hp = player:get_hp()
|
local hp = player:get_hp()
|
||||||
if hp < pstat.regen_max then
|
if hp < pstat.regen_max then
|
||||||
|
ctf.add_heal_assist(name, regen_step)
|
||||||
player:set_hp(math.min(hp + regen_step, pstat.regen_max))
|
player:set_hp(math.min(hp + regen_step, pstat.regen_max))
|
||||||
else
|
else
|
||||||
stop_healing(player)
|
stop_healing(player)
|
||||||
|
|
Loading…
Reference in a new issue