Implemented team damage restriction (fixes #88)

This commit is contained in:
Timo Smit 2019-02-05 14:46:28 +01:00
parent 0c82ea21c5
commit 26e38bca7d
5 changed files with 50 additions and 12 deletions

View file

@ -30,6 +30,7 @@ maxbots = 10
[admin]
history = 1
maxrenames = 80
maxteamdamage = 0.8
[balancer]
mindif = 2

View file

@ -27,6 +27,16 @@ local admin = {}
local playerRenames = {}
function admin.checkDamage(clientId)
local teamDamage = et.gentity_get(clientId, "sess.team_damage_given")
local totalDamage = teamDamage + et.gentity_get(clientId, "sess.damage_given")
local teamDamagePercentage = teamDamage / totalDamage
if teamDamage > 250 and totalDamage > 500 and teamDamagePercentage > settings.get("g_maxTeamDamage") then
admin.kickPlayer(clientId, -1337, "Too much team damage.")
end
end
function admin.putPlayer(clientId, teamId)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "forceteam "..clientId.." "..util.getTeamCode(teamId)..";")
end
@ -89,6 +99,26 @@ function admin.onClientDisconnect(clientId)
end
events.handle("onClientDisconnect", admin.onClientDisconnect)
function admin.onPlayerDamage(victimId, attackerId, damage, damageFlags, meansOfDeath)
local victimTeam = tonumber(et.gentity_get(victimId, "sess.sessionTeam"))
local attackerTeam = tonumber(et.gentity_get(attackerId, "sess.sessionTeam"))
if attackerId and attackerId ~= victimId and attackerTeam == victimTeam then
admin.checkDamage(attackerId)
end
end
events.handle("onPlayerDamage", admin.onPlayerDamage)
function admin.onPlayerDeath(victimId, attackerId, meansOfDeath)
local victimTeam = tonumber(et.gentity_get(victimId, "sess.sessionTeam"))
local attackerTeam = tonumber(et.gentity_get(attackerId, "sess.sessionTeam"))
if attackerId and attackerId ~= victimId and attackerTeam == victimTeam then
admin.checkDamage(attackerId)
end
end
events.handle("onPlayerDeath", admin.onPlayerDeath)
function admin.onClientNameChange(clientId, oldName, newName)
-- rename filter
if not playerRenames[clientId] or playerRenames[clientId]["last"] < os.time() - 60 then

View file

@ -345,31 +345,31 @@ function sprees.onPlayerSpreeEnd(clientId, causeId, type)
end
end
function sprees.onPlayerDeath(victimId, killerId, mod)
if killerId == 1022 then -- killed by map
function sprees.onPlayerDeath(victimId, attackerId, meansOfDeath)
if attackerId == 1022 then -- killed by map
events.trigger("onPlayerSpreeEnd", victimId)
events.trigger("onPlayerSpree", victimId, sprees.RECORD_DEATH)
elseif victimId == killerId then -- suicides
elseif victimId == attackerId then -- suicides
-- happens when a bot disconnects, it selfkills before leaving, thus emptying the
-- player data table, resulting in errors. I'm sorry for your spree records, bots.
if not players.isConnected(victimId) then return end
events.trigger("onPlayerSpreeEnd", victimId, killerId)
events.trigger("onPlayerSpreeEnd", victimId, attackerId)
events.trigger("onPlayerSpree", victimId, sprees.RECORD_DEATH)
else -- regular kills
if et.gentity_get(victimId, "sess.sessionTeam") == et.gentity_get(killerId, "sess.sessionTeam") then
if et.gentity_get(victimId, "sess.sessionTeam") == et.gentity_get(attackerId, "sess.sessionTeam") then
-- teamkill handling
events.trigger("onPlayerSpreeEnd", victimId, killerId)
events.trigger("onPlayerSpreeEnd", victimId, attackerId)
events.trigger("onPlayerSpree", victimId, sprees.RECORD_DEATH)
else
events.trigger("onPlayerSpreeEnd", killerId, victimId, sprees.RECORD_DEATH)
events.trigger("onPlayerSpree", killerId, sprees.RECORD_KILL)
events.trigger("onPlayerSpreeEnd", attackerId, victimId, sprees.RECORD_DEATH)
events.trigger("onPlayerSpree", attackerId, sprees.RECORD_KILL)
-- happens when a bot disconnects, it selfkills before leaving, thus emptying the
-- player data table, resulting in errors. I'm sorry for your spree records, bots.
if not players.isConnected(victimId) then return end
events.trigger("onPlayerSpreeEnd", victimId, killerId)
events.trigger("onPlayerSpreeEnd", victimId, attackerId)
events.trigger("onPlayerSpree", victimId, sprees.RECORD_DEATH)
end
end

View file

@ -216,8 +216,13 @@ function et_Print(consoleText)
end
end
function et_Obituary(victimId, killerId, mod)
events.trigger("onPlayerDeath", victimId, killerId, mod)
-- legacy only
function et_Damage(victimId, attackerId, damage, damageFlags, meansOfDeath)
events.trigger("onPlayerDamage", victimId, attackerId, damage, damageFlags, meansOfDeath)
end
function et_Obituary(victimId, attackerId, meansOfDeath)
events.trigger("onPlayerDeath", victimId, attackerId, meansOfDeath)
end
function et_ClientSpawn(clientId, revived)

View file

@ -49,6 +49,7 @@ local data = {
["g_voteNextMapTimeout"] = 0,
["g_restrictedVotes"] = "",
["g_renameLimit"] = 80,
["g_maxTeamDamage"] = 80,
["g_debugWolfAdmin"] = 0,
["omnibot_maxbots"] = 10,
["db_type"] = "sqlite3",
@ -85,7 +86,8 @@ local cfgStructure = {
},
["admin"] = {
["history"] = "g_playerHistory",
["maxrenames"] = "g_renameLimit"
["maxrenames"] = "g_renameLimit",
["maxteamdamage"] = "g_maxTeamDamage"
},
["balancer"] = {
["mindif"] = "g_evenerMinDifference",