mirror of
https://github.com/etlegacy/wolfadmin.git
synced 2024-11-10 06:41:53 +00:00
Implemented kill and death spree in standalone mode (refs #61)
* messages can be disabled per-type through g_spreeMessages * records can be disabled through g_spreeRecords
This commit is contained in:
parent
179ac058cb
commit
a5067afd67
9 changed files with 349 additions and 224 deletions
|
@ -22,6 +22,7 @@ set g_renameInterval 60
|
||||||
|
|
||||||
set g_playerHistory 1
|
set g_playerHistory 1
|
||||||
|
|
||||||
|
set g_spreeMessages 1
|
||||||
set g_spreeRecords 1
|
set g_spreeRecords 1
|
||||||
set g_botRecords 1
|
set g_botRecords 1
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,16 @@
|
||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local auth = require (wolfa_getLuaPath()..".auth.auth")
|
local auth = require (wolfa_getLuaPath()..".auth.auth")
|
||||||
|
|
||||||
local db = require (wolfa_getLuaPath()..".db.db")
|
local db = require (wolfa_getLuaPath()..".db.db")
|
||||||
|
|
||||||
local commands = require (wolfa_getLuaPath()..".commands.commands")
|
local commands = require (wolfa_getLuaPath()..".commands.commands")
|
||||||
|
|
||||||
local game = require (wolfa_getLuaPath()..".game.game")
|
local game = require (wolfa_getLuaPath()..".game.game")
|
||||||
local sprees = require (wolfa_getLuaPath()..".game.sprees")
|
local sprees = require (wolfa_getLuaPath()..".game.sprees")
|
||||||
|
|
||||||
|
local settings = require (wolfa_getLuaPath()..".util.settings")
|
||||||
|
|
||||||
function commandResetSprees(clientId, command, map)
|
function commandResetSprees(clientId, command, map)
|
||||||
if not db.isconnected() then
|
if not db.isconnected() then
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsprees: ^9spree records are disabled.\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsprees: ^9spree records are disabled.\";")
|
||||||
|
@ -40,4 +45,4 @@ function commandResetSprees(clientId, command, map)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
commands.addadmin("resetsprees", commandResetSprees, auth.PERM_READCONFIG, "resets the spree records")
|
commands.addadmin("resetsprees", commandResetSprees, auth.PERM_READCONFIG, "resets the spree records", nil, (settings.get("g_spreeRecords") == 0))
|
||||||
|
|
|
@ -16,8 +16,11 @@
|
||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local auth = require (wolfa_getLuaPath()..".auth.auth")
|
local auth = require (wolfa_getLuaPath()..".auth.auth")
|
||||||
|
|
||||||
local commands = require (wolfa_getLuaPath()..".commands.commands")
|
local commands = require (wolfa_getLuaPath()..".commands.commands")
|
||||||
|
|
||||||
local db = require (wolfa_getLuaPath()..".db.db")
|
local db = require (wolfa_getLuaPath()..".db.db")
|
||||||
|
|
||||||
local sprees = require (wolfa_getLuaPath()..".game.sprees")
|
local sprees = require (wolfa_getLuaPath()..".game.sprees")
|
||||||
|
|
||||||
function commandShowSprees(clientId, command)
|
function commandShowSprees(clientId, command)
|
||||||
|
@ -29,17 +32,13 @@ function commandShowSprees(clientId, command)
|
||||||
|
|
||||||
local records = sprees.get()
|
local records = sprees.get()
|
||||||
|
|
||||||
if not (records["ksrecord"] or records["dsrecord"] or records["rsrecord"]) 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
|
||||||
if records["ksrecord"] and records["ksrecord"] > 0 then
|
for i = 0, sprees.RECORD_NUM - 1 do
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsprees: ^9longest kill spree (^7"..records["ksrecord"].."^9) by ^7"..records["ksname"].."^9.\";")
|
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.\";")
|
||||||
end
|
end
|
||||||
if records["dsrecord"] and records["dsrecord"] > 0 then
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsprees: ^9longest death spree (^7"..records["dsrecord"].."^9) by ^7"..records["dsname"].."^9.\";")
|
|
||||||
end
|
|
||||||
if records["rsrecord"] and records["rsrecord"] > 0 then
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsprees: ^9longest revive spree (^7"..records["rsrecord"].."^9) by ^7"..records["rsname"].."^9.\";")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -259,19 +259,7 @@ function mysql.getrecords(mapid)
|
||||||
local row = cur:fetch({}, "a")
|
local row = cur:fetch({}, "a")
|
||||||
|
|
||||||
while row do
|
while row do
|
||||||
local typestr = ""
|
table.insert(records, tables.copy(row))
|
||||||
|
|
||||||
if tonumber(row["type"]) == constants.RECORD_KILL then
|
|
||||||
typestr = "ks"
|
|
||||||
elseif tonumber(row["type"]) == constants.RECORD_DEATH then
|
|
||||||
typestr = "ds"
|
|
||||||
elseif tonumber(row["type"]) == constants.RECORD_REVIVE then
|
|
||||||
typestr = "rs"
|
|
||||||
end
|
|
||||||
|
|
||||||
records[typestr.."player"] = tonumber(row["player_id"])
|
|
||||||
records[typestr.."record"] = tonumber(row["record"])
|
|
||||||
|
|
||||||
row = cur:fetch({}, "a")
|
row = cur:fetch({}, "a")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -292,26 +280,11 @@ end
|
||||||
function mysql.getrecord(mapid, recordtype)
|
function mysql.getrecord(mapid, recordtype)
|
||||||
cur = assert(con:execute("SELECT * FROM `record` WHERE `map_id`="..tonumber(mapid).." AND `type`="..tonumber(recordtype)..""))
|
cur = assert(con:execute("SELECT * FROM `record` WHERE `map_id`="..tonumber(mapid).." AND `type`="..tonumber(recordtype)..""))
|
||||||
|
|
||||||
local row = cur:fetch({}, "a")
|
local record = cur:fetch({}, "a")
|
||||||
cur:close()
|
cur:close()
|
||||||
|
|
||||||
if row then
|
|
||||||
local record, typestr = {}, ""
|
|
||||||
|
|
||||||
if tonumber(row["type"]) == constants.RECORD_KILL then
|
|
||||||
typestr = "ks"
|
|
||||||
elseif tonumber(row["type"]) == constants.RECORD_DEATH then
|
|
||||||
typestr = "ds"
|
|
||||||
elseif tonumber(row["type"]) == constants.RECORD_REVIVE then
|
|
||||||
typestr = "rs"
|
|
||||||
end
|
|
||||||
|
|
||||||
record[typestr.."player"] = tonumber(row["player"])
|
|
||||||
record[typestr.."record"] = tonumber(row["record"])
|
|
||||||
|
|
||||||
return record
|
return record
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function mysql.isconnected()
|
function mysql.isconnected()
|
||||||
return (con ~= nil)
|
return (con ~= nil)
|
||||||
|
|
|
@ -442,19 +442,7 @@ function sqlite3.getrecords(mapid)
|
||||||
local row = cur:fetch({}, "a")
|
local row = cur:fetch({}, "a")
|
||||||
|
|
||||||
while row do
|
while row do
|
||||||
local typestr = ""
|
table.insert(records, tables.copy(row))
|
||||||
|
|
||||||
if tonumber(row["type"]) == constants.RECORD_KILL then
|
|
||||||
typestr = "ks"
|
|
||||||
elseif tonumber(row["type"]) == constants.RECORD_DEATH then
|
|
||||||
typestr = "ds"
|
|
||||||
elseif tonumber(row["type"]) == constants.RECORD_REVIVE then
|
|
||||||
typestr = "rs"
|
|
||||||
end
|
|
||||||
|
|
||||||
records[typestr.."player"] = tonumber(row["player_id"])
|
|
||||||
records[typestr.."record"] = tonumber(row["record"])
|
|
||||||
|
|
||||||
row = cur:fetch({}, "a")
|
row = cur:fetch({}, "a")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -475,26 +463,11 @@ end
|
||||||
function sqlite3.getrecord(mapid, recordtype)
|
function sqlite3.getrecord(mapid, recordtype)
|
||||||
cur = assert(con:execute("SELECT * FROM `record` WHERE `map_id`="..tonumber(mapid).." AND `type`="..tonumber(recordtype)..""))
|
cur = assert(con:execute("SELECT * FROM `record` WHERE `map_id`="..tonumber(mapid).." AND `type`="..tonumber(recordtype)..""))
|
||||||
|
|
||||||
local row = cur:fetch({}, "a")
|
local record = cur:fetch({}, "a")
|
||||||
cur:close()
|
cur:close()
|
||||||
|
|
||||||
if row then
|
|
||||||
local record, typestr = {}, ""
|
|
||||||
|
|
||||||
if tonumber(row["type"]) == constants.RECORD_KILL then
|
|
||||||
typestr = "ks"
|
|
||||||
elseif tonumber(row["type"]) == constants.RECORD_DEATH then
|
|
||||||
typestr = "ds"
|
|
||||||
elseif tonumber(row["type"]) == constants.RECORD_REVIVE then
|
|
||||||
typestr = "rs"
|
|
||||||
end
|
|
||||||
|
|
||||||
record[typestr.."player"] = tonumber(row["player"])
|
|
||||||
record[typestr.."record"] = tonumber(row["record"])
|
|
||||||
|
|
||||||
return record
|
return record
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function sqlite3.isconnected()
|
function sqlite3.isconnected()
|
||||||
return (con ~= nil)
|
return (con ~= nil)
|
||||||
|
|
|
@ -20,52 +20,146 @@ local db = require (wolfa_getLuaPath()..".db.db")
|
||||||
local game = require (wolfa_getLuaPath()..".game.game")
|
local game = require (wolfa_getLuaPath()..".game.game")
|
||||||
|
|
||||||
local players = require (wolfa_getLuaPath()..".players.players")
|
local players = require (wolfa_getLuaPath()..".players.players")
|
||||||
-- local stats = require (wolfa_getLuaPath()..".players.stats")
|
|
||||||
|
|
||||||
|
local bits = require (wolfa_getLuaPath()..".util.bits")
|
||||||
local constants = require (wolfa_getLuaPath()..".util.constants")
|
local constants = require (wolfa_getLuaPath()..".util.constants")
|
||||||
local events = require (wolfa_getLuaPath()..".util.events")
|
local events = require (wolfa_getLuaPath()..".util.events")
|
||||||
local files = require (wolfa_getLuaPath()..".util.files")
|
|
||||||
local settings = require (wolfa_getLuaPath()..".util.settings")
|
local settings = require (wolfa_getLuaPath()..".util.settings")
|
||||||
|
|
||||||
local sprees = {}
|
local sprees = {}
|
||||||
|
|
||||||
local revivespreeMessages = {
|
sprees.RECORD_KILL = 0
|
||||||
[3] = {
|
sprees.RECORD_DEATH = 1
|
||||||
["msg"] = "^dis on a ^2revive spree^d!",
|
sprees.RECORD_REVIVE = 2
|
||||||
["sound"] = "",
|
sprees.RECORD_NUM = 3
|
||||||
},
|
|
||||||
[5] = {
|
local spreeNames = {
|
||||||
["msg"] = "^dis a ^2revive magnet^d!",
|
[sprees.RECORD_KILL] = "kill",
|
||||||
["sound"] = "",
|
[sprees.RECORD_DEATH] = "death",
|
||||||
},
|
[sprees.RECORD_REVIVE] = "revive"
|
||||||
[10] = {
|
|
||||||
["msg"] = "^dis a ^2syringe maniac^d!",
|
|
||||||
["sound"] = "",
|
|
||||||
},
|
|
||||||
[15] = {
|
|
||||||
["msg"] = "^dis the new ^2Dr. Frankenstein^d!",
|
|
||||||
["sound"] = "",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local spreeMessagesByType = {
|
||||||
|
[sprees.RECORD_KILL] = {
|
||||||
|
{
|
||||||
|
["amount"] = 5,
|
||||||
|
["msg"] = "^dis on a ^2killing spree^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 10,
|
||||||
|
["msg"] = "^dis on a ^2rampage^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 15,
|
||||||
|
["msg"] = "^dis ^2dominating^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 20,
|
||||||
|
["msg"] = "^drevels in his ^2bloodbath^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 25,
|
||||||
|
["msg"] = "^dis a walking ^2slaughterhouse^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 30,
|
||||||
|
["msg"] = "^dwreaks ^2havoc ^dupon his foes^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 35,
|
||||||
|
["msg"] = "^dcuts through enemies like a ^2god ^2of ^2war^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 40,
|
||||||
|
["msg"] = "^dis the ^2prophet of doom^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[sprees.RECORD_DEATH] = {
|
||||||
|
{
|
||||||
|
["amount"] = 5,
|
||||||
|
["msg"] = "^dmust be having a bad day!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 10,
|
||||||
|
["msg"] = "^dhis day just got worse!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 15,
|
||||||
|
["msg"] = "^dtries to kill with flowers!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 20,
|
||||||
|
["msg"] = "^dis getting his ass kicked!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 25,
|
||||||
|
["msg"] = "^dis a death magnet!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 30,
|
||||||
|
["msg"] = "^dneeds remedial combat training!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 40,
|
||||||
|
["msg"] = "^dstill can't kill shit!",
|
||||||
|
["sound"] = ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[sprees.RECORD_REVIVE] = {
|
||||||
|
{
|
||||||
|
["amount"] = 3,
|
||||||
|
["msg"] = "^dis on a ^2revive spree^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 5,
|
||||||
|
["msg"] = "^dis a ^2health dealer^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 10,
|
||||||
|
["msg"] = "^dis a ^2perfect nurse^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 15,
|
||||||
|
["msg"] = "^dis a ^2syringe maniac^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["amount"] = 25,
|
||||||
|
["msg"] = "^dis the new ^2Dr. Frankenstein^d!",
|
||||||
|
["sound"] = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
local spreeMessages = {}
|
||||||
|
|
||||||
local playerSprees = {}
|
local playerSprees = {}
|
||||||
local currentRecords -- cached version
|
local currentRecords = {} -- cached version
|
||||||
local currentMapId
|
local currentMapId
|
||||||
|
|
||||||
|
function sprees.getRecordNameByType(type)
|
||||||
|
return spreeNames[type]
|
||||||
|
end
|
||||||
|
|
||||||
function sprees.get()
|
function sprees.get()
|
||||||
local records = currentRecords
|
return currentRecords
|
||||||
|
|
||||||
if records["ksrecord"] and records["ksrecord"] > 0 then
|
|
||||||
records["ksname"] = db.getlastalias(records["ksplayer"])["alias"]
|
|
||||||
end
|
|
||||||
if records["dsrecord"] and records["dsrecord"] > 0 then
|
|
||||||
records["dsname"] = db.getlastalias(records["dsplayer"])["alias"]
|
|
||||||
end
|
|
||||||
if records["rsrecord"] and records["rsrecord"] > 0 then
|
|
||||||
records["rsname"] = db.getlastalias(records["rsplayer"])["alias"]
|
|
||||||
end
|
|
||||||
|
|
||||||
return records
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function sprees.reset(truncate)
|
function sprees.reset(truncate)
|
||||||
|
@ -75,10 +169,11 @@ function sprees.reset(truncate)
|
||||||
db.removerecords(currentMapId)
|
db.removerecords(currentMapId)
|
||||||
end
|
end
|
||||||
|
|
||||||
currentRecords = db.getrecords(currentMapId)
|
currentRecords = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function sprees.load()
|
function sprees.load()
|
||||||
|
if db.isconnected() and settings.get("g_spreeRecords") ~= 0 then
|
||||||
local map = db.getmap(game.getMap())
|
local map = db.getmap(game.getMap())
|
||||||
|
|
||||||
if map then
|
if map then
|
||||||
|
@ -89,143 +184,222 @@ function sprees.load()
|
||||||
currentMapId = db.getmap(game.getMap())["id"]
|
currentMapId = db.getmap(game.getMap())["id"]
|
||||||
end
|
end
|
||||||
|
|
||||||
currentRecords = db.getrecords(currentMapId)
|
local records = db.getrecords(currentMapId)
|
||||||
|
|
||||||
return db.getrecordscount(currentMapId)
|
for _, record in ipairs(records) do
|
||||||
|
currentRecords[record["type"]] = {
|
||||||
|
["player"] = tonumber(record["player_id"]),
|
||||||
|
["record"] = tonumber(record["record"])
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function sprees.oninit(levelTime, randomSeed, restartMap)
|
for i = 0, sprees.RECORD_NUM - 1 do
|
||||||
if
|
spreeMessages[i] = {}
|
||||||
(db.isconnected() and settings.get("g_spreeRecords") ~= 0)
|
|
||||||
then
|
for _, spree in ipairs(spreeMessagesByType[i]) do
|
||||||
|
spreeMessages[i][spree["amount"]] = spree
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function sprees.save()
|
||||||
|
if db.isconnected() and settings.get("g_spreeRecords") ~= 0 then
|
||||||
|
for i = 0, sprees.RECORD_NUM - 1 do
|
||||||
|
if currentRecords[i] and currentRecords[i]["record"] > 0 then
|
||||||
|
if db.getrecord(currentMapId, i) then
|
||||||
|
db.updaterecord(currentMapId, os.time(), i, currentRecords[i]["record"], currentRecords[i]["player"])
|
||||||
|
else
|
||||||
|
db.addrecord(currentMapId, os.time(), i, currentRecords[i]["record"], currentRecords[i]["player"])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function sprees.printRecords()
|
||||||
|
if db.isconnected() and settings.get("g_spreeRecords") ~= 0 then
|
||||||
|
for i = 0, sprees.RECORD_NUM - 1 do
|
||||||
|
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.\";")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function sprees.onGameInit(levelTime, randomSeed, restartMap)
|
||||||
sprees.load()
|
sprees.load()
|
||||||
|
|
||||||
events.handle("onGameStateChange", sprees.ongamestatechange)
|
events.handle("onGameStateChange", sprees.onGameStateChange)
|
||||||
end
|
end
|
||||||
end
|
events.handle("onGameInit", sprees.onGameInit)
|
||||||
events.handle("onGameInit", sprees.oninit)
|
|
||||||
|
|
||||||
function sprees.onconnect(clientId, firstTime, isBot)
|
function sprees.onClientConnect(clientId, firstTime, isBot)
|
||||||
playerSprees[clientId] = {["kill"] = 0, ["death"] = 0, ["revive"] = 0}
|
playerSprees[clientId] = {}
|
||||||
end
|
|
||||||
events.handle("onClientConnect", sprees.onconnect)
|
|
||||||
|
|
||||||
function sprees.ondisconnect(clientId)
|
for i = 0, sprees.RECORD_NUM - 1 do
|
||||||
|
playerSprees[clientId][i] = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
events.handle("onClientConnect", sprees.onClientConnect)
|
||||||
|
|
||||||
|
function sprees.onClientDisconnect(clientId)
|
||||||
playerSprees[clientId] = nil
|
playerSprees[clientId] = nil
|
||||||
end
|
end
|
||||||
events.handle("onClientDisconnect", sprees.ondisconnect)
|
events.handle("onClientDisconnect", sprees.onClientDisconnect)
|
||||||
|
|
||||||
function sprees.onteamchange(clientId, old, new)
|
function sprees.onClientTeamChange(clientId, old, new)
|
||||||
playerSprees[clientId] = {["kill"] = 0, ["death"] = 0, ["revive"] = 0}
|
events.trigger("onPlayerSpreeEnd", clientId, clientId)
|
||||||
end
|
end
|
||||||
|
|
||||||
function sprees.ongamestatechange(gameState)
|
function sprees.onGameStateChange(gameState)
|
||||||
if gameState == constants.GAME_STATE_RUNNING then
|
if gameState == constants.GAME_STATE_RUNNING then
|
||||||
events.handle("onClientTeamChange", sprees.onteamchange)
|
events.handle("onClientTeamChange", sprees.onClientTeamChange)
|
||||||
events.handle("onPlayerDeath", sprees.ondeath)
|
events.handle("onPlayerDeath", sprees.onPlayerDeath)
|
||||||
events.handle("onPlayerRevive", sprees.onrevive)
|
events.handle("onPlayerRevive", sprees.onPlayerRevive)
|
||||||
|
events.handle("onPlayerSpree", sprees.onPlayerSpree)
|
||||||
|
events.handle("onPlayerSpreeEnd", sprees.onPlayerSpreeEnd)
|
||||||
elseif gameState == constants.GAME_STATE_INTERMISSION then
|
elseif gameState == constants.GAME_STATE_INTERMISSION then
|
||||||
if currentRecords["ksrecord"] and currentRecords["ksrecord"] > 0 then
|
sprees.save()
|
||||||
if db.getrecord(currentMapId, constants.RECORD_KILL) then
|
sprees.printRecords()
|
||||||
db.updaterecord(currentMapId, os.time(), constants.RECORD_KILL, currentRecords["ksrecord"], currentRecords["ksplayer"])
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function sprees.onPlayerSpree(clientId, type, sourceId)
|
||||||
|
playerSprees[clientId][type] = playerSprees[clientId][type] + 1
|
||||||
|
|
||||||
|
local currentSpree = playerSprees[clientId][type]
|
||||||
|
|
||||||
|
if db.isconnected() and settings.get("g_spreeRecords") ~= 0 and
|
||||||
|
(settings.get("g_botRecords") == 1 or not players.isBot(clientId)) and
|
||||||
|
(not currentRecords[type] or currentSpree > currentRecords[type]["record"]) then
|
||||||
|
currentRecords[type] = {
|
||||||
|
["player"] = db.getplayerid(clientId),
|
||||||
|
["record"] = currentSpree
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local settingSpreeMessages = settings.get("g_spreeMessages")
|
||||||
|
if settingSpreeMessages ~= 0 and bits.hasbit(settingSpreeMessages, 2^type) then
|
||||||
|
local spreeMessage = spreeMessages[type][currentSpree]
|
||||||
|
|
||||||
|
if spreeMessage then
|
||||||
|
local msg = string.format("^1%s SPREE! ^*%s ^*%s ^d(^3%d ^d%ss in a row!)",
|
||||||
|
string.upper(spreeNames[type]),
|
||||||
|
players.getName(clientId),
|
||||||
|
spreeMessage["msg"],
|
||||||
|
currentSpree,
|
||||||
|
spreeNames[type])
|
||||||
|
|
||||||
|
if spreeMessage["sound"] and spreeMessage["sound"] ~= "" then
|
||||||
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound \"sound/"..spreeMessage["sound"].."\";")
|
||||||
|
end
|
||||||
|
|
||||||
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \""..msg.."\";")
|
||||||
|
elseif currentSpree % 5 == 0 then
|
||||||
|
local maxSpreeMessage = spreeMessagesByType[type][#spreeMessagesByType[type]]
|
||||||
|
|
||||||
|
local msg = string.format("^1%s SPREE! ^*%s ^*%s ^d(^3%d ^d%ss in a row!)",
|
||||||
|
string.upper(spreeNames[type]),
|
||||||
|
players.getName(clientId),
|
||||||
|
maxSpreeMessage["msg"],
|
||||||
|
currentSpree,
|
||||||
|
spreeNames[type])
|
||||||
|
|
||||||
|
if maxSpreeMessage["sound"] and maxSpreeMessage["sound"] ~= "" then
|
||||||
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound \"sound/"..maxSpreeMessage["sound"].."\";")
|
||||||
|
end
|
||||||
|
|
||||||
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \""..msg.."\";")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function sprees.onPlayerSpreeEnd(clientId, causeId, type)
|
||||||
|
if type == sprees.RECORD_DEATH then
|
||||||
|
if playerSprees[clientId][sprees.RECORD_DEATH] > spreeMessagesByType[sprees.RECORD_DEATH][1]["amount"] then
|
||||||
|
local msg = string.format("^7%s^d was the first victim of ^7%s ^dafter ^3%d ^d%ss!",
|
||||||
|
players.getName(causeId),
|
||||||
|
players.getName(clientId),
|
||||||
|
playerSprees[clientId][sprees.RECORD_DEATH],
|
||||||
|
spreeNames[sprees.RECORD_DEATH])
|
||||||
|
|
||||||
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \""..msg.."\";")
|
||||||
|
end
|
||||||
|
|
||||||
|
playerSprees[clientId][sprees.RECORD_DEATH] = 0
|
||||||
|
elseif type == nil then
|
||||||
|
for i = 0, sprees.RECORD_NUM - 1 do
|
||||||
|
if i ~= sprees.RECORD_DEATH then
|
||||||
|
if playerSprees[clientId][i] > spreeMessagesByType[i][1]["amount"] then
|
||||||
|
local msg = ""
|
||||||
|
|
||||||
|
if clientId == causeId then
|
||||||
|
msg = string.format("^7%s^d's spree (^3%d ^d%ss) was brought to an end by ^1himself^d!",
|
||||||
|
players.getName(clientId),
|
||||||
|
playerSprees[clientId][i],
|
||||||
|
spreeNames[i])
|
||||||
|
elseif causeId then
|
||||||
|
local prefix = ""
|
||||||
|
|
||||||
|
if et.gentity_get(clientId, "sess.sessionTeam") == et.gentity_get(causeId, "sess.sessionTeam") then
|
||||||
|
prefix = "^1TEAMMATE "
|
||||||
|
end
|
||||||
|
|
||||||
|
msg = string.format("^7%s^d's spree (^3%d ^d%ss) was brought to an end by %s^7%s^d!",
|
||||||
|
players.getName(clientId),
|
||||||
|
playerSprees[clientId][i],
|
||||||
|
spreeNames[i],
|
||||||
|
prefix,
|
||||||
|
players.getName(causeId))
|
||||||
else
|
else
|
||||||
db.addrecord(currentMapId, os.time(), constants.RECORD_KILL, currentRecords["ksrecord"], currentRecords["ksplayer"])
|
msg = string.format("^7%s^d's spree (^3%d ^d%ss) was brought to an end.",
|
||||||
|
players.getName(clientId),
|
||||||
|
playerSprees[clientId][i],
|
||||||
|
spreeNames[i])
|
||||||
end
|
end
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsprees: ^9longest kill spree (^7"..currentRecords["ksrecord"].."^9) by ^7"..db.getlastalias(currentRecords["ksplayer"])["alias"].."^9.\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \""..msg.."\";")
|
||||||
end
|
|
||||||
if currentRecords["dsrecord"] and currentRecords["dsrecord"] > 0 then
|
|
||||||
if db.getrecord(currentMapId, constants.RECORD_DEATH) then
|
|
||||||
db.updaterecord(currentMapId, os.time(), constants.RECORD_DEATH, currentRecords["dsrecord"], currentRecords["dsplayer"])
|
|
||||||
else
|
|
||||||
db.addrecord(currentMapId, os.time(), constants.RECORD_DEATH, currentRecords["dsrecord"], currentRecords["dsplayer"])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsprees: ^9longest death spree (^7"..currentRecords["dsrecord"].."^9) by ^7"..db.getlastalias(currentRecords["dsplayer"])["alias"].."^9.\";")
|
playerSprees[clientId][i] = 0
|
||||||
end
|
end
|
||||||
if currentRecords["rsrecord"] and currentRecords["rsrecord"] > 0 then
|
|
||||||
if db.getrecord(currentMapId, constants.RECORD_REVIVE) then
|
|
||||||
db.updaterecord(currentMapId, os.time(), constants.RECORD_REVIVE, currentRecords["rsrecord"], currentRecords["rsplayer"])
|
|
||||||
else
|
|
||||||
db.addrecord(currentMapId, os.time(), constants.RECORD_REVIVE, currentRecords["rsrecord"], currentRecords["rsplayer"])
|
|
||||||
end
|
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsprees: ^9longest revive spree (^7"..currentRecords["rsrecord"].."^9) by ^7"..db.getlastalias(currentRecords["rsplayer"])["alias"].."^9.\";")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function sprees.ondeath(victimId, killerId, mod)
|
function sprees.onPlayerDeath(victimId, killerId, mod)
|
||||||
if killerId == 1022 then -- killed by map
|
if killerId == 1022 then -- killed by map
|
||||||
playerSprees[victimId]["kill"] = 0
|
events.trigger("onPlayerSpreeEnd", victimId)
|
||||||
playerSprees[victimId]["death"] = playerSprees[victimId]["death"] + 1
|
events.trigger("onPlayerSpree", victimId, sprees.RECORD_DEATH)
|
||||||
playerSprees[victimId]["revive"] = 0
|
|
||||||
|
|
||||||
-- stats.set(victimId, "longestDeathSpree", stats.get(victimId, "currentDeathSpree") > stats.get(victimId, "longestDeathSpree") and stats.get(victimId, "currentDeathSpree") or stats.get(victimId, "longestDeathSpree"))
|
|
||||||
|
|
||||||
if (settings.get("g_botRecords") == 1 or not players.isBot(victimId)) and (not currentRecords["dsrecord"] or playerSprees[victimId]["death"] > currentRecords["dsrecord"]) then
|
|
||||||
currentRecords["dsplayer"] = db.getplayerid(victimId)
|
|
||||||
currentRecords["dsrecord"] = playerSprees[victimId]["death"]
|
|
||||||
end
|
|
||||||
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
|
||||||
|
|
||||||
playerSprees[victimId]["kill"] = 0
|
events.trigger("onPlayerSpreeEnd", victimId, killerId)
|
||||||
playerSprees[victimId]["death"] = playerSprees[victimId]["death"] + 1
|
events.trigger("onPlayerSpree", victimId, sprees.RECORD_DEATH)
|
||||||
playerSprees[victimId]["revive"] = 0
|
|
||||||
|
|
||||||
-- stats.set(victimId, "longestDeathSpree", stats.get(victimId, "currentDeathSpree") > stats.get(victimId, "longestDeathSpree") and stats.get(victimId, "currentDeathSpree") or stats.get(victimId, "longestDeathSpree"))
|
|
||||||
|
|
||||||
if (settings.get("g_botRecords") == 1 or not players.isBot(victimId)) and (not currentRecords["dsrecord"] or playerSprees[victimId]["death"] > currentRecords["dsrecord"]) then
|
|
||||||
currentRecords["dsplayer"] = db.getplayerid(victimId)
|
|
||||||
currentRecords["dsrecord"] = playerSprees[victimId]["death"]
|
|
||||||
end
|
|
||||||
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("onPlayerSpree", victimId, sprees.RECORD_DEATH)
|
||||||
else
|
else
|
||||||
playerSprees[killerId]["kill"] = playerSprees[killerId]["kill"] + 1
|
events.trigger("onPlayerSpreeEnd", killerId, victimId, sprees.RECORD_DEATH)
|
||||||
playerSprees[victimId]["death"] = 0
|
events.trigger("onPlayerSpree", killerId, sprees.RECORD_KILL)
|
||||||
|
|
||||||
-- stats.set(killerId, "longestKillSpree", stats.get(killerId, "currentKillSpree") > stats.get(killerId, "longestKillSpree") and stats.get(killerId, "currentKillSpree") or stats.get(killerId, "longestKillSpree"))
|
|
||||||
|
|
||||||
if (settings.get("g_botRecords") == 1 or not players.isBot(killerId)) and (not currentRecords["ksrecord"] or playerSprees[killerId]["kill"] > currentRecords["ksrecord"]) then
|
|
||||||
currentRecords["ksplayer"] = db.getplayerid(killerId)
|
|
||||||
currentRecords["ksrecord"] = playerSprees[killerId]["kill"]
|
|
||||||
end
|
|
||||||
|
|
||||||
-- 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
|
||||||
|
|
||||||
playerSprees[victimId]["kill"] = 0
|
events.trigger("onPlayerSpreeEnd", victimId, killerId)
|
||||||
playerSprees[victimId]["death"] = playerSprees[victimId]["death"] + 1
|
events.trigger("onPlayerSpree", victimId, sprees.RECORD_DEATH)
|
||||||
playerSprees[victimId]["revive"] = 0
|
|
||||||
|
|
||||||
-- stats.set(victimId, "longestDeathSpree", stats.get(victimId, "currentDeathSpree") > stats.get(victimId, "longestDeathSpree") and stats.get(victimId, "currentDeathSpree") or stats.get(victimId, "longestDeathSpree"))
|
|
||||||
|
|
||||||
if (settings.get("g_botRecords") == 1 or not players.isBot(victimId)) and (not currentRecords["dsrecord"] or playerSprees[victimId]["death"] > currentRecords["dsrecord"]) then
|
|
||||||
currentRecords["dsplayer"] = db.getplayerid(victimId)
|
|
||||||
currentRecords["dsrecord"] = playerSprees[victimId]["death"]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function sprees.onrevive(clientMedic, clientVictim)
|
function sprees.onPlayerRevive(clientMedic, clientVictim)
|
||||||
playerSprees[clientMedic]["revive"] = playerSprees[clientMedic]["revive"] + 1
|
events.trigger("onPlayerSpree", clientMedic, sprees.RECORD_REVIVE)
|
||||||
-- stats.set(clientMedic, "longestReviveSpree", stats.get(clientMedic, "currentReviveSpree") > stats.get(clientMedic, "longestReviveSpree") and stats.get(clientMedic, "currentReviveSpree") or stats.get(clientMedic, "longestReviveSpree"))
|
|
||||||
|
|
||||||
if revivespreeMessages[playerSprees[clientMedic]["revive"]] then
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^1REVIVE SPREE! ^*"..players.getName(clientMedic).." ^*"..revivespreeMessages[playerSprees[clientMedic]["revive"]]["msg"].." ^d(^3"..playerSprees[clientMedic]["revive"].." ^drevives in a row!)\";")
|
|
||||||
end
|
|
||||||
|
|
||||||
if (settings.get("g_botRecords") == 1 or not players.isBot(clientMedic)) and (not currentRecords["rsrecord"] or playerSprees[clientMedic]["revive"] > currentRecords["rsrecord"]) then
|
|
||||||
currentRecords["rsplayer"] = db.getplayerid(clientMedic)
|
|
||||||
currentRecords["rsrecord"] = playerSprees[clientMedic]["revive"]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return sprees
|
return sprees
|
||||||
|
|
|
@ -71,8 +71,4 @@ constants.VOTE_TYPES = { "antilag", "balancedteams", "comp", "friendlyfire", "ga
|
||||||
"surrender", "swapteams", "timelimit", "warmupdamage"
|
"surrender", "swapteams", "timelimit", "warmupdamage"
|
||||||
}
|
}
|
||||||
|
|
||||||
constants.RECORD_KILL = 0
|
|
||||||
constants.RECORD_DEATH = 1
|
|
||||||
constants.RECORD_REVIVE = 2
|
|
||||||
|
|
||||||
return constants
|
return constants
|
|
@ -125,6 +125,9 @@ events.add("onPlayerRevive")
|
||||||
|
|
||||||
events.add("onPlayerSkillUpdate")
|
events.add("onPlayerSkillUpdate")
|
||||||
|
|
||||||
|
events.add("onPlayerSpree")
|
||||||
|
events.add("onPlayerSpreeEnd")
|
||||||
|
|
||||||
events.add("onServerCommand")
|
events.add("onServerCommand")
|
||||||
|
|
||||||
return events
|
return events
|
||||||
|
|
|
@ -25,6 +25,7 @@ local data = {
|
||||||
["g_fileGreetings"] = "greetings.cfg",
|
["g_fileGreetings"] = "greetings.cfg",
|
||||||
["g_fileRules"] = "rules.cfg",
|
["g_fileRules"] = "rules.cfg",
|
||||||
["g_playerHistory"] = 1,
|
["g_playerHistory"] = 1,
|
||||||
|
["g_spreeMessages"] = 7,
|
||||||
["g_spreeRecords"] = 1,
|
["g_spreeRecords"] = 1,
|
||||||
["g_botRecords"] = 1,
|
["g_botRecords"] = 1,
|
||||||
["g_announceRevives"] = 1,
|
["g_announceRevives"] = 1,
|
||||||
|
|
Loading…
Reference in a new issue