Added new setting to ignore records when bots are online

* changed g_botRecords to bitflag
This commit is contained in:
Timo Smit 2019-02-11 12:48:16 +01:00
parent 9c799b8f4d
commit 1562e74489
2 changed files with 37 additions and 33 deletions

View file

@ -35,7 +35,7 @@ function commandShowSprees(clientId, command)
if #records == 0 then if #records == 0 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsprees: ^9there are no records for this map yet.\"") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsprees: ^9there are no records for this map yet.\"")
else else
for i = 0, sprees.RECORD_NUM - 1 do for i = 0, sprees.TYPE_NUM - 1 do
if records[i] and records[i]["record"] > 0 then if records[i] and records[i]["record"] > 0 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsprees: ^9longest "..sprees.getRecordNameByType(i).." spree (^7"..records[i]["record"].."^9) by ^7"..db.getLastAlias(records[i]["player"])["alias"].."^9.\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsprees: ^9longest "..sprees.getRecordNameByType(i).." spree (^7"..records[i]["record"].."^9) by ^7"..db.getLastAlias(records[i]["player"])["alias"].."^9.\";")
end end

View file

@ -31,28 +31,31 @@ local toml = wolfa_requireLib("toml")
local sprees = {} local sprees = {}
sprees.RECORD_KILL = 0 sprees.RECORD_BOTS = 1
sprees.RECORD_DEATH = 1 sprees.RECORD_PLAYER_BOTSON = 2
sprees.RECORD_REVIVE = 2
sprees.RECORD_NUM = 3
sprees.SOUND_PLAY_SELF = 0 sprees.SOUND_PLAY_SELF = 0
sprees.SOUND_PLAY_PUBLIC = 1 sprees.SOUND_PLAY_PUBLIC = 1
sprees.RECORD_KILL_NAME = "kill" sprees.TYPE_KILL = 0
sprees.RECORD_DEATH_NAME = "death" sprees.TYPE_DEATH = 1
sprees.RECORD_REVIVE_NAME = "revive" sprees.TYPE_REVIVE = 2
sprees.TYPE_NUM = 3
sprees.TYPE_KILL_NAME = "kill"
sprees.TYPE_DEATH_NAME = "death"
sprees.TYPE_REVIVE_NAME = "revive"
local spreeNames = { local spreeNames = {
[sprees.RECORD_KILL] = sprees.RECORD_KILL_NAME, [sprees.TYPE_KILL] = sprees.TYPE_KILL_NAME,
[sprees.RECORD_DEATH] = sprees.RECORD_DEATH_NAME, [sprees.TYPE_DEATH] = sprees.TYPE_DEATH_NAME,
[sprees.RECORD_REVIVE] = sprees.RECORD_REVIVE_NAME [sprees.TYPE_REVIVE] = sprees.TYPE_REVIVE_NAME
} }
local spreeTypes = { local spreeTypes = {
[sprees.RECORD_KILL_NAME] = sprees.RECORD_KILL, [sprees.TYPE_KILL_NAME] = sprees.TYPE_KILL,
[sprees.RECORD_DEATH_NAME] = sprees.RECORD_DEATH, [sprees.TYPE_DEATH_NAME] = sprees.TYPE_DEATH,
[sprees.RECORD_REVIVE_NAME] = sprees.RECORD_REVIVE [sprees.TYPE_REVIVE_NAME] = sprees.TYPE_REVIVE
} }
local spreeMessages = {} local spreeMessages = {}
@ -106,7 +109,7 @@ function sprees.load()
end end
end end
for i = 0, sprees.RECORD_NUM - 1 do for i = 0, sprees.TYPE_NUM - 1 do
spreeMessages[i] = {} spreeMessages[i] = {}
spreeMessagesByType[i] = {} spreeMessagesByType[i] = {}
end end
@ -174,7 +177,7 @@ end
function sprees.save() function sprees.save()
if db.isConnected() and settings.get("g_spreeRecords") ~= 0 then if db.isConnected() and settings.get("g_spreeRecords") ~= 0 then
for i = 0, sprees.RECORD_NUM - 1 do for i = 0, sprees.TYPE_NUM - 1 do
if currentRecords[i] and currentRecords[i]["record"] > 0 then if currentRecords[i] and currentRecords[i]["record"] > 0 then
if db.getRecord(currentMapId, i) then if db.getRecord(currentMapId, i) then
db.updateRecord(currentMapId, os.time(), i, currentRecords[i]["record"], currentRecords[i]["player"]) db.updateRecord(currentMapId, os.time(), i, currentRecords[i]["record"], currentRecords[i]["player"])
@ -188,7 +191,7 @@ end
function sprees.printRecords() function sprees.printRecords()
if db.isConnected() and settings.get("g_spreeRecords") ~= 0 then if db.isConnected() and settings.get("g_spreeRecords") ~= 0 then
for i = 0, sprees.RECORD_NUM - 1 do for i = 0, sprees.TYPE_NUM - 1 do
if currentRecords[i] and currentRecords[i]["record"] > 0 then if currentRecords[i] and currentRecords[i]["record"] > 0 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsprees: ^9longest "..sprees.getRecordNameByType(i).." spree (^7"..currentRecords[i]["record"].."^9) by ^7"..db.getLastAlias(currentRecords[i]["player"])["alias"].."^9.\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsprees: ^9longest "..sprees.getRecordNameByType(i).." spree (^7"..currentRecords[i]["record"].."^9) by ^7"..db.getLastAlias(currentRecords[i]["player"])["alias"].."^9.\";")
end end
@ -206,7 +209,7 @@ events.handle("onGameInit", sprees.onGameInit)
function sprees.onClientConnect(clientId, firstTime, isBot) function sprees.onClientConnect(clientId, firstTime, isBot)
playerSprees[clientId] = {} playerSprees[clientId] = {}
for i = 0, sprees.RECORD_NUM - 1 do for i = 0, sprees.TYPE_NUM - 1 do
playerSprees[clientId][i] = 0 playerSprees[clientId][i] = 0
end end
end end
@ -240,7 +243,8 @@ function sprees.onPlayerSpree(clientId, type, sourceId)
local currentSpree = playerSprees[clientId][type] local currentSpree = playerSprees[clientId][type]
if db.isConnected() and settings.get("g_spreeRecords") ~= 0 and if db.isConnected() and settings.get("g_spreeRecords") ~= 0 and
(settings.get("g_botRecords") == 1 or not players.isBot(clientId)) and (bits.hasbit(settings.get("g_botRecords"), sprees.RECORD_PLAYER_BOTSON) or tonumber(et.trap_Cvar_Get("omnibot_playing")) == 0) and
(bits.hasbit(settings.get("g_botRecords"), sprees.RECORD_BOTS) or not players.isBot(clientId)) and
(not currentRecords[type] or currentSpree > currentRecords[type]["record"]) then (not currentRecords[type] or currentSpree > currentRecords[type]["record"]) then
currentRecords[type] = { currentRecords[type] = {
["player"] = db.getPlayerId(clientId), ["player"] = db.getPlayerId(clientId),
@ -293,21 +297,21 @@ end
function sprees.onPlayerSpreeEnd(clientId, causeId, type) function sprees.onPlayerSpreeEnd(clientId, causeId, type)
local settingSpreeMessages = settings.get("g_spreeMessages") local settingSpreeMessages = settings.get("g_spreeMessages")
if type == sprees.RECORD_DEATH then if type == sprees.TYPE_DEATH then
if bits.hasbit(settingSpreeMessages, 2^type) and playerSprees[clientId][sprees.RECORD_DEATH] >= spreeMessagesByType[sprees.RECORD_DEATH][1]["amount"] then if bits.hasbit(settingSpreeMessages, 2^type) and playerSprees[clientId][sprees.TYPE_DEATH] >= spreeMessagesByType[sprees.TYPE_DEATH][1]["amount"] then
local msg = string.format("^7%s^d was the first victim of ^7%s ^dafter ^3%d ^d%ss!", local msg = string.format("^7%s^d was the first victim of ^7%s ^dafter ^3%d ^d%ss!",
players.getName(causeId), players.getName(causeId),
players.getName(clientId), players.getName(clientId),
playerSprees[clientId][sprees.RECORD_DEATH], playerSprees[clientId][sprees.TYPE_DEATH],
spreeNames[sprees.RECORD_DEATH]) spreeNames[sprees.TYPE_DEATH])
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \""..msg.."\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \""..msg.."\";")
end end
playerSprees[clientId][sprees.RECORD_DEATH] = 0 playerSprees[clientId][sprees.TYPE_DEATH] = 0
elseif type == nil then elseif type == nil then
for i = 0, sprees.RECORD_NUM - 1 do for i = 0, sprees.TYPE_NUM - 1 do
if i ~= sprees.RECORD_DEATH then if i ~= sprees.TYPE_DEATH then
if bits.hasbit(settingSpreeMessages, 2^i) and playerSprees[clientId][i] >= spreeMessagesByType[i][1]["amount"] then if bits.hasbit(settingSpreeMessages, 2^i) and playerSprees[clientId][i] >= spreeMessagesByType[i][1]["amount"] then
local msg = "" local msg = ""
@ -348,35 +352,35 @@ end
function sprees.onPlayerDeath(victimId, killerId, mod) function sprees.onPlayerDeath(victimId, killerId, mod)
if killerId == 1022 then -- killed by map if killerId == 1022 then -- killed by map
events.trigger("onPlayerSpreeEnd", victimId) events.trigger("onPlayerSpreeEnd", victimId)
events.trigger("onPlayerSpree", victimId, sprees.RECORD_DEATH) events.trigger("onPlayerSpree", victimId, sprees.TYPE_DEATH)
elseif victimId == killerId then -- suicides elseif victimId == killerId then -- suicides
-- happens when a bot disconnects, it selfkills before leaving, thus emptying the -- 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. -- player data table, resulting in errors. I'm sorry for your spree records, bots.
if not players.isConnected(victimId) then return end if not players.isConnected(victimId) then return end
events.trigger("onPlayerSpreeEnd", victimId, killerId) events.trigger("onPlayerSpreeEnd", victimId, killerId)
events.trigger("onPlayerSpree", victimId, sprees.RECORD_DEATH) events.trigger("onPlayerSpree", victimId, sprees.TYPE_DEATH)
else -- regular kills 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(killerId, "sess.sessionTeam") then
-- teamkill handling -- teamkill handling
events.trigger("onPlayerSpreeEnd", victimId, killerId) events.trigger("onPlayerSpreeEnd", victimId, killerId)
events.trigger("onPlayerSpree", victimId, sprees.RECORD_DEATH) events.trigger("onPlayerSpree", victimId, sprees.TYPE_DEATH)
else else
events.trigger("onPlayerSpreeEnd", killerId, victimId, sprees.RECORD_DEATH) events.trigger("onPlayerSpreeEnd", killerId, victimId, sprees.TYPE_DEATH)
events.trigger("onPlayerSpree", killerId, sprees.RECORD_KILL) events.trigger("onPlayerSpree", killerId, sprees.TYPE_KILL)
-- happens when a bot disconnects, it selfkills before leaving, thus emptying the -- 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. -- player data table, resulting in errors. I'm sorry for your spree records, bots.
if not players.isConnected(victimId) then return end if not players.isConnected(victimId) then return end
events.trigger("onPlayerSpreeEnd", victimId, killerId) events.trigger("onPlayerSpreeEnd", victimId, killerId)
events.trigger("onPlayerSpree", victimId, sprees.RECORD_DEATH) events.trigger("onPlayerSpree", victimId, sprees.TYPE_DEATH)
end end
end end
end end
function sprees.onPlayerRevive(clientMedic, clientVictim) function sprees.onPlayerRevive(clientMedic, clientVictim)
events.trigger("onPlayerSpree", clientMedic, sprees.RECORD_REVIVE) events.trigger("onPlayerSpree", clientMedic, sprees.TYPE_REVIVE)
end end
return sprees return sprees