/
sprees.lua
216 lines (177 loc) · 10.2 KB
/
sprees.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2018 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local constants = require "luascripts.wolfadmin.util.constants"
local events = require "luascripts.wolfadmin.util.events"
local settings = require "luascripts.wolfadmin.util.settings"
local files = require "luascripts.wolfadmin.util.files"
local db = require "luascripts.wolfadmin.db.db"
local game = require "luascripts.wolfadmin.game.game"
local stats = require "luascripts.wolfadmin.players.stats"
local sprees = {}
local revivespreeMessages = {
[3] = {
["msg"] = "^dis on a ^2revive spree^d!",
["sound"] = "",
},
[5] = {
["msg"] = "^dis a ^2revive magnet^d!",
["sound"] = "",
},
[10] = {
["msg"] = "^dis a ^2syringe maniac^d!",
["sound"] = "",
},
[15] = {
["msg"] = "^dis the new ^2Dr. Frankenstein^d!",
["sound"] = "",
},
}
local currentRecords -- cached version
local currentMapId
function sprees.get()
local records = 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
function sprees.reset(truncate)
if truncate then
db.removeallrecords()
else
db.removerecords(currentMapId)
end
currentRecords = db.getrecords(currentMapId)
end
function sprees.load()
local map = db.getmap(game.getMap())
if map then
currentMapId = map["id"]
db.updatemap(currentMapId, os.time())
else
db.addmap(game.getMap(), os.time())
currentMapId = db.getmap(game.getMap())["id"]
end
currentRecords = db.getrecords(currentMapId)
return db.getrecordscount(currentMapId)
end
function sprees.oninit(levelTime, randomSeed, restartMap)
if
(db.isconnected() and settings.get("g_spreeRecords") ~= 0)
then
sprees.load()
events.handle("onGameStateChange", sprees.ongamestatechange)
end
end
events.handle("onGameInit", sprees.oninit)
function sprees.onconnect(clientId, firstTime, isBot)
stats.set(clientId, "currentKillSpree", 0)
stats.set(clientId, "longestKillSpree", 0)
stats.set(clientId, "currentDeathSpree", 0)
stats.set(clientId, "longestDeathSpree", 0)
stats.set(clientId, "currentReviveSpree", 0)
stats.set(clientId, "longestReviveSpree", 0)
end
events.handle("onClientConnect", sprees.onconnect)
function sprees.ongamestatechange(gameState)
if gameState == constants.GAME_STATE_RUNNING then
events.handle("onPlayerDeath", sprees.ondeath)
events.handle("onPlayerRevive", sprees.onrevive)
elseif gameState == constants.GAME_STATE_INTERMISSION then
if currentRecords["ksrecord"] and currentRecords["ksrecord"] > 0 then
if db.getrecord(currentMapId, constants.RECORD_KILL) then
db.updaterecord(currentMapId, os.time(), constants.RECORD_KILL, currentRecords["ksrecord"], currentRecords["ksplayer"])
else
db.addrecord(currentMapId, os.time(), constants.RECORD_KILL, currentRecords["ksrecord"], currentRecords["ksplayer"])
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dsprees: ^9longest kill spree (^7"..currentRecords["ksrecord"].."^9) by ^7"..db.getlastalias(currentRecords["ksplayer"])["alias"].."^9.\";")
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
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dsprees: ^9longest death spree (^7"..currentRecords["dsrecord"].."^9) by ^7"..db.getlastalias(currentRecords["dsplayer"])["alias"].."^9.\";")
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, "chat \"^dsprees: ^9longest revive spree (^7"..currentRecords["rsrecord"].."^9) by ^7"..db.getlastalias(currentRecords["rsplayer"])["alias"].."^9.\";")
end
end
end
function sprees.ondeath(victimId, killerId, mod)
if killerId == 1022 then -- killed by map
stats.set(victimId, "currentKillSpree", 0)
stats.add(victimId, "currentDeathSpree", 1)
stats.set(victimId, "currentReviveSpree", 0)
stats.set(victimId, "longestDeathSpree", stats.get(victimId, "currentDeathSpree") > stats.get(victimId, "longestDeathSpree") and stats.get(victimId, "currentDeathSpree") or stats.get(victimId, "longestDeathSpree"))
elseif victimId == killerId 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 wolfa_isPlayer(victimId) then return end
stats.set(victimId, "currentKillSpree", 0)
stats.add(victimId, "currentDeathSpree", 1)
stats.set(victimId, "currentReviveSpree", 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 stats.get(victimId, "isBot")) and (not currentRecords["dsrecord"] or stats.get(victimId, "longestDeathSpree") > currentRecords["dsrecord"]) then
currentRecords["dsplayer"] = db.getplayerid(victimId)
currentRecords["dsrecord"] = stats.get(victimId, "longestDeathSpree")
end
else -- regular kills
if et.gentity_get(victimId, "sess.sessionTeam") == et.gentity_get(killerId, "sess.sessionTeam") then
-- teamkill handling
else
stats.add(killerId, "currentKillSpree", 1)
stats.set(killerId, "currentDeathSpree", 0)
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 stats.get(killerId, "isBot")) and (not currentRecords["ksrecord"] or stats.get(killerId, "longestKillSpree") > currentRecords["ksrecord"]) then
currentRecords["ksplayer"] = db.getplayerid(killerId)
currentRecords["ksrecord"] = stats.get(killerId, "longestKillSpree")
end
-- 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 wolfa_isPlayer(victimId) then return end
stats.set(victimId, "currentKillSpree", 0)
stats.add(victimId, "currentDeathSpree", 1)
stats.set(victimId, "currentReviveSpree", 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 stats.get(victimId, "isBot")) and (not currentRecords["dsrecord"] or stats.get(victimId, "longestDeathSpree") > currentRecords["dsrecord"]) then
currentRecords["dsplayer"] = db.getplayerid(victimId)
currentRecords["dsrecord"] = stats.get(victimId, "longestDeathSpree")
end
end
end
end
function sprees.onrevive(clientMedic, clientVictim)
stats.add(clientMedic, "currentReviveSpree", 1)
stats.set(clientMedic, "longestReviveSpree", stats.get(clientMedic, "currentReviveSpree") > stats.get(clientMedic, "longestReviveSpree") and stats.get(clientMedic, "currentReviveSpree") or stats.get(clientMedic, "longestReviveSpree"))
if revivespreeMessages[stats.get(clientMedic, "currentReviveSpree")] then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^1REVIVE SPREE! ^*"..stats.get(clientMedic, "playerName").." ^*"..revivespreeMessages[stats.get(clientMedic, "currentReviveSpree")]["msg"].." ^d(^3"..stats.get(clientMedic, "currentReviveSpree").." ^drevives in a row!)\";")
end
if (settings.get("g_botRecords") == 1 or not stats.get(clientMedic, "isBot")) and (not currentRecords["rsrecord"] or stats.get(clientMedic, "longestReviveSpree") > currentRecords["rsrecord"]) then
currentRecords["rsplayer"] = db.getplayerid(clientMedic)
currentRecords["rsrecord"] = stats.get(clientMedic, "longestReviveSpree")
end
end
return sprees