· 8 years ago · Apr 23, 2018, 10:52 PM
1local DB = dbConnect("sqlite", ":/TOP1.db")
2
3function onStart( )
4 dbExec(DB, "CREATE TABLE IF NOT EXISTS TOP1 (Nombre STRING, TotalK INTEGER, TotalD INTEGER)")
5 --dbExec(DB, "CREATE TABLE IF NOT EXISTS TOPGrupal (Nombre STRING, TotalK INTEGER, TotalD INTEGER )")
6end
7addEventHandler("onResourceStart", getResourceRootElement( getThisResource()), onStart)
8
9function getList()
10 Jugadores = {}
11 --Grupos = {}
12
13 -- Top asesinatos (Personal)
14 local QH = dbQuery(DB, "SELECT * FROM TOP1 ORDER BY TotalK DESC LIMIT 100")
15 local AsesinatosJ = dbPoll(QH, - 1)
16
17 if AsesinatosJ[1] then
18 for k, v in ipairs(AsesinatosJ) do
19 Jugadores[k] = {v.Nombre, v.TotalK, v.TotalD}
20
21 end
22 end
23
24 --Top asesinatos (Grupo)
25
26 --[[local QH = dbQuery(DB, "SELECT * FROM TOPGrupal ORDER BY TotalK DESC LIMIT 10")
27 local AsesinatosG = dbPoll(QH, - 1)
28
29 if AsesinatosG[1] then
30 for k, v in ipairs(AsesinatosG) do
31 Grupos[k] = {v.Nombre, v.TotalK..'/'..v.TotalD}
32 end
33 end]]
34
35 triggerClientEvent(source, "sendTOPList", source, Jugadores)--, Grupos
36end
37addEvent('requestTOPList', true)
38addEventHandler('requestTOPList', root, getList)
39
40function addPlayerKill(Jugador)
41 local Cuenta = Jugador:getAccount()
42 local Nombre = Cuenta:getName()
43 if not Cuenta:isGuest() then
44 local QH = DB:query( "SELECT * FROM TOP1 WHERE Nombre=?", Nombre)
45 local Resultado = dbPoll(QH, -1)
46
47 if #Resultado == 0 then
48 DB:exec("INSERT INTO TOP1 (Nombre, TotalK, TotalD) VALUES(?,?,?)", Nombre, 1, 0)
49 else
50 local actualKills = Resultado[1].TotalK
51 local newKills = tonumber(actualKills) + 1
52 DB:exec("UPDATE TOP1 SET TotalK=? WHERE Nombre=?", newKills, Nombre)
53 end
54 end
55end
56
57function addPlayerDeath(Jugador)
58 local Cuenta = Jugador:getAccount()
59 local Nombre = Cuenta:getName()
60
61 if not Cuenta:isGuest() then
62 local QH = DB:query( "SELECT * FROM TOP1 WHERE Nombre=?", Nombre)
63 local Resultado = dbPoll(QH, -1)
64
65 if #Resultado == 0 then
66 DB:exec("INSERT INTO TOP1 (Nombre, TotalK, TotalD) VALUES(?,?,?)", Nombre, 0, 1)
67 else
68 local actualDeaths = Resultado[1].TotalD
69 local newDeaths = tonumber(actualDeaths) + 1
70 DB:exec("UPDATE TOP TOP1 TotalD=? WHERE Nombre=?", newDeaths, Nombre)
71 end
72 end
73end
74--[[
75function addGroupKill(Grupo)
76 local QH = DB:query( "SELECT TotalK FROM TOPGrupal WHERE Nombre=?", Grupo)
77 local Resultado = dbPoll(QH, -1)
78
79 if #Resultado == 0 then
80 DB:exec("INSERT INTO TOPGrupal (Nombre, TotalK, TotalD) VALUES(?,?,?)", Grupo, 1, 0)
81 else
82 local actualKills = Resultado[1].TotalK
83 local newKills = tonumber(actualKills) + 1
84 DB:exec("UPDATE TOPGrupal SET TotalK=? WHERE Nombre=?", newKills, Grupo)
85 end
86end
87function addGroupDeath(Grupo)
88 local QH = DB:query("SELECT TotalD FROM TOPGrupal WHERE Nombre=?", Grupo)
89 local Resultado = dbPoll(QH, -1)
90
91 if #Resultado == 0 then
92 DB:exec("INSERT INTO TOPGrupal (Nombre, TotalK, TotalD) VALUES(?,?,?)", Grupo, 0, 1)
93 else
94 local actualDeaths = Resultado[1].TotalD
95 local newDeaths = tonumber(actualDeaths) + 1
96 DB:exec("UPDATE TOPGrupal SET TotalD=? WHERE Nombre=?", newDeaths, Grupo)
97 end
98end]]
99
100function onWats(Info)
101 if Info.Suicidio then return end
102
103 local Cuenta = source:getAccount()
104 if not Cuenta:isGuest() then
105 addPlayerDeath(source, 1)
106 --[[Añade Muerte de Grupo
107 local playerGang = getElementData(source, "gang")
108 if playerGang then
109 addGroupDeath(playerGang)
110 end]]
111
112 if not isElement(Info.Atacante) then return end
113
114 addPlayerKill(Info.Atacante)
115 --[[ Añade Kills de Grupo
116 local playerGang2 = getElementData(Info.Atacante, "gang")
117 if playerGang2 then
118 addGroupKill(playerGang2)
119 end]]
120 end
121end
122addEvent('kilLDayZPlayer', true)
123addEventHandler('kilLDayZPlayer', getRootElement(), onWats)