-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paths_leaderboard.lua
199 lines (169 loc) · 5.57 KB
/
s_leaderboard.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
db = dbConnect("sqlite", "database.db")
function startResource()
dbExec(db, "CREATE TABLE IF NOT EXISTS top_killers(nick, kills, deaths)")
dbExec(db, "CREATE TABLE IF NOT EXISTS top_killers_kd(nick, kills, deaths, kd)")
dbExec(db, "CREATE TABLE IF NOT EXISTS top_zkillers(nick, kills)")
dbExec(db, "CREATE TABLE IF NOT EXISTS top_alive(nick, alive)")
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), startResource)
function ShowTopKillers()
allData = {}
local data = dbQuery(db, "SELECT * FROM top_killers_kd ORDER BY kd DESC LIMIT 50")
local result = dbPoll(data, -1)
local counter = 1
for ind, val in ipairs( result ) do
local killer = {}
killer.id = counter
killer.nick = val.nick
killer.kills = val.kills
killer.deaths = val.deaths
if val.kd > 0 then
killer.kd = val.kd
else
killer.kd = 0
end
allData[killer.id] = killer
counter = counter +1
end
triggerClientEvent ( source, "Leaderboard:createGui", source, allData )
end
addEvent("ShowTopKillers", true)
addEventHandler("ShowTopKillers", getRootElement(), ShowTopKillers)
function ShowTopZKillers()
allData = {}
local data = dbQuery(db, "SELECT * FROM top_zkillers ORDER BY kills DESC LIMIT 50")
local result = dbPoll(data, -1)
local counter = 1
for ind, val in ipairs( result ) do
local killer = {}
killer.id = counter
killer.nick = val.nick
killer.kills = val.kills
allData[killer.id] = killer
counter = counter +1
end
triggerClientEvent ( source, "Leaderboard:showZkillersC", source, allData )
end
addEvent("ShowTopZKillers", true)
addEventHandler("ShowTopZKillers", getRootElement(), ShowTopZKillers)
function ShowTopATime()
allData = {}
local data = dbQuery(db, "SELECT * FROM top_alive ORDER BY alive DESC LIMIT 50")
local result = dbPoll(data, -1)
local counter = 1
for ind, val in ipairs( result ) do
local killer = {}
killer.id = counter
killer.nick = val.nick
killer.alive = val.alive
allData[killer.id] = killer
counter = counter +1
end
triggerClientEvent ( source, "Leaderboard:ShowTopATimeC", source, allData )
end
addEvent("ShowTopATime", true)
addEventHandler("ShowTopATime", getRootElement(), ShowTopATime)
function round2(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
function updateKdRatio()
local data = dbQuery(db, "SELECT * FROM top_killers ORDER BY kills DESC LIMIT 50")
local result = dbPoll(data, -1)
dbExec(db, "DELETE FROM top_killers_kd WHERE kills < 99999999")
for ind, val in ipairs( result ) do
local kd = val.kills / val.deaths
local kd = round2(kd, 2)
dbExec(db, "INSERT INTO top_killers_kd (nick, kills, deaths, kd) VALUES (?, ?, ?, ?)", val.nick, val.kills, val.deaths, kd)
end
end
setTimer(updateKdRatio, 600000, 0) -- 10 min
function checkExistKiller(nick)
local data = dbQuery(db, "SELECT * FROM top_killers WHERE nick = ?", nick)
local result = dbPoll(data, -1)
if next(result) == nil then
return false
else
return true
end
end
function checkExistSurvivor(nick)
local data = dbQuery(db, "SELECT * FROM top_alive WHERE nick = ?", nick)
local result = dbPoll(data, -1)
if next(result) == nil then
return false
else
return true
end
end
function checkAliveTimeBigger(nick, minutes)
local data = dbQuery(db, "SELECT * FROM top_alive WHERE nick = ?", nick)
local result = dbPoll(data, -1)
for ind, val in ipairs( result ) do
if tonumber(val.alive) < tonumber(minutes) then
return true
else
return false
end
end
end
function kilLDayZPlayer (killer,headshot,weapon)
if killer and getElementType(source) == "player" then
local killerNick = getPlayerName ( killer )
local deadNick = getPlayerName ( source )
local alive = getElementData(source, "alivetime")
if checkExistSurvivor(deadNick) == true then
if checkAliveTimeBigger(deadNick, alive) == true then
dbExec(db, "UPDATE top_alive SET alive = ? WHERE nick = ?", alive, deadNick)
end
else
if alive > 10 then
dbExec(db, "INSERT INTO top_alive(nick, alive) VALUES(?,?)", deadNick, alive)
end
end
if checkExistKiller(killerNick) == false then
dbExec(db, "INSERT INTO top_killers(nick, kills, deaths) VALUES(?,1,0)",
killerNick)
if checkExistKiller(deadNick) == false then
dbExec(db, "INSERT INTO top_killers(nick, kills, deaths) VALUES(?,0,1)",
deadNick)
else
dbExec(db, "UPDATE top_killers SET deaths = deaths +1 WHERE nick = ?",
deadNick)
end
else
dbExec(db, "UPDATE top_killers SET kills = kills +1 WHERE nick = ?",
killerNick)
if checkExistKiller(deadNick) == false then
dbExec(db, "INSERT INTO top_killers(nick, kills, deaths) VALUES(?,0,1)",
deadNick)
else
dbExec(db, "UPDATE top_killers SET deaths = deaths +1 WHERE nick = ?",
deadNick)
end
end
end
end
addEvent("kilLDayZPlayer",true)
addEventHandler("kilLDayZPlayer",getRootElement(),kilLDayZPlayer)
function checkExistZombieKiller(nick)
local data = dbQuery(db, "SELECT * FROM top_zkillers WHERE nick = ?", nick)
local result = dbPoll(data, -1)
if next(result) == nil then
return false
else
return true
end
end
addEventHandler("onElementDataChange",getRootElement(), function(dataName, oldValue)
if dataName == "zombieskilled" and oldValue > 0 and getElementType(source) == "player" and getElementData(source, "logedin") then
local killerNick = getPlayerName ( source )
if checkExistZombieKiller(killerNick) == false then
dbExec(db, "INSERT INTO top_zkillers(nick, kills) VALUES(?,1)",
killerNick)
else
dbExec(db, "UPDATE top_zkillers SET kills = kills +1 WHERE nick = ?",
killerNick)
end
end
end)