Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TraitorRoundNumber = 0
- local TerrorRoundNumber = 0
- local TeamKills = 0
- local TraitorKills = 0
- local DetectiveKills = 0
- local InnocentKills = 0
- local KnifeKills = 0
- local TotalKills =0
- local TotalDeaths =0
- timer.Simple(10, function()
- tmysql.query( "SELECT * FROM `stats_server`", function( SQLTable )
- if !SQLTable or #SQLTable == 0 then print("STATS -> Couldnt find server stats.") return end
- if SQLTable and SQLTable[1][1] then
- TraitorRoundNumber = SQLTable[1][1]
- TerrorRoundNumber = SQLTable[1][2]
- TeamKills = SQLTable[1][3]
- TraitorKills = SQLTable[1][4]
- DetectiveKills = SQLTable[1][5]
- InnocentKills = SQLTable[1][6]
- KnifeKills = SQLTable[1][7]
- TotalKills = SQLTable[1][8]
- TotalDeaths = SQLTable[1][9]
- print("STATS -> Found server stats.")
- else
- print("STATS -> Couldnt find server stats.")
- end
- end)
- end)
- function SQLHandle( result, _, error )
- if error and error != 0 then
- print( "SQL ERROR: " .. error )
- end
- end
- hook.Add("TTTEndRound", "Stats.TTTEndRound", function( team )
- if team == WIN_TRAITOR then
- TraitorRoundNumber = TraitorRoundNumber + 1
- elseif team == WIN_INNOCENT or team == WIN_TIMELIMIT then
- TerrorRoundNumber = TerrorRoundNumber + 1
- end
- tmysql.query( "UPDATE stats_server SET terrorrounds='" .. TerrorRoundNumber .. "', traitorrounds= '" .. TraitorRoundNumber .. "', teamkills= '" .. TeamKills .. "', traitorkills= '" .. TraitorKills .. "', detectivekills= '" .. DetectiveKills .. "', knifekills= '" .. KnifeKills .. "', totalkills= '" .. TotalKills .. "', totaldeaths= '" .. TotalDeaths .. "'", SQLHandle )
- for k, v in pairs(player.GetAll()) do
- if team == WIN_TRAITOR then
- if v:IsRole(ROLE_TRAITOR) then
- v.TraitorRoundNumber = v.TraitorRoundNumber + 1
- end
- elseif team == WIN_INNOCENT or team == WIN_TIMELIMIT then
- if !v:IsRole(ROLE_TRAITOR) then
- v.TerrorRoundNumber = v.TerrorRoundNumber + 1
- end
- end
- if v:IsPlayer() then
- timer.Simple(math.random(1,15), function()
- tmysql.query( "UPDATE stats_players SET terrorrounds='" .. v.TerrorRoundNumber .. "', traitorrounds= '" .. v.TraitorRoundNumber .. "', teamkills= '" .. v.TeamKills .. "', traitorkills= '" .. v.TraitorKills .. "', detectivekills= '" .. v.DetectiveKills .. "', knifekills= '" .. v.KnifeKills .. "', totalkills= '" .. v.TotalKills .. "', totaldeaths= '" .. v.TotalDeaths .. "' WHERE steamid = '" .. v:SteamID() .. "'", SQLHandle )
- end)
- end
- end
- end)
- hook.Add("PlayerInitialSpawn", "Stats.PlayerInitialSpawn", function( p )
- tmysql.query("SELECT * FROM `stats_players` WHERE steamid = '" .. p:SteamID() .. "'", function( Args )
- if !Args or #Args == 0 then
- p.TraitorRoundNumber = 0
- p.TerrorRoundNumber = 0
- p.TeamKills = 0
- p.TraitorKills = 0
- p.DetectiveKills = 0
- p.InnocentKills = 0
- p.KnifeKills = 0
- p.TotalKills = 0
- p.TotalDeaths = 0
- tmysql.query( "INSERT INTO stats_players (steamid, terrorrounds, traitorrounds, teamkills, traitorkills, detectivekills, knifekills, totalkills, totaldeaths) VALUES('" .. tmysql.escape(p:SteamID()) .. "', '" .. p.TerrorRoundNumber .. "', '" .. p.TraitorRoundNumber .. "', '" .. p.TeamKills .. "', '" .. p.TraitorKills .. "', '" .. p.DetectiveKills .. "', '" .. p.KnifeKills .. "', '" .. p.TotalKills .. "', '" .. p.TotalDeaths .. "')", SQLHandle )
- elseif p:SteamID() == Args[1][1] then
- p.TraitorRoundNumber = Args[1][2]
- p.TerrorRoundNumber = Args[1][3]
- p.TeamKills = Args[1][4]
- p.TraitorKills = Args[1][5]
- p.DetectiveKills = Args[1][6]
- p.InnocentKills = Args[1][7]
- p.KnifeKills = Args[1][8]
- p.TotalKills = Args[1][9]
- p.TotalDeaths = Args[1][10]
- end
- end)
- end)
- hook.Add("PlayerDeath", "Stats.PlayerDeath", function( v, w, k )
- if v:IsPlayer() and k:IsPlayer() then
- if !k:IsRole(ROLE_TRAITOR) and !k:IsRole(ROLE_DETECTIVE) then
- if !v:IsRole(ROLE_TRAITOR) and !v:IsRole(ROLE_DETECTIVE) and v != k and k:IsPlayer() then
- TeamKills = TeamKills + 1
- k.TeamKills = k.TeamKills + 1
- elseif v:IsRole(ROLE_TRAITOR) then
- TraitorKills = TraitorKills + 1
- k.TraitorKills = k.TraitorKills + 1
- elseif v:IsRole(ROLE_DETECTIVE) then
- DetectiveKills = DetectiveKills + 1
- k.DetectiveKills = k.DetectiveKills + 1
- end
- elseif k:IsRole(ROLE_TRAITOR) then
- if !v:IsRole(ROLE_TRAITOR) and !v:IsRole(ROLE_DETECTIVE) then
- InnocentKills = InnocentKills + 1
- k.InnocentKills = k.InnocentKills + 1
- elseif v:IsRole(ROLE_TRAITOR) and v != k and k:IsPlayer() then
- TeamKills = TeamKills + 1
- k.TeamKills = k.TeamKills + 1
- elseif v:IsRole(ROLE_DETECTIVE) then
- DetectiveKills = DetectiveKills + 1
- k.DetectiveKills = k.DetectiveKills + 1
- end
- elseif k:IsRole(ROLE_DETECTIVE) then
- if !v:IsRole(ROLE_TRAITOR) and !v:IsRole(ROLE_DETECTIVE) then
- InnocentKills = InnocentKills + 1
- k.InnocentKills = k.InnocentKills + 1
- elseif v:IsRole(ROLE_TRAITOR) then
- TraitorKills = TraitorKills + 1
- k.TraitorKills = k.TraitorKills + 1
- elseif v:IsRole(ROLE_DETECTIVE) and v != k and k:IsPlayer() then
- TeamKills = TeamKills + 1
- k.TeamKills = k.TeamKills + 1
- end
- end
- if IsValid(w) and w:GetClass() == "weapon_ttt_knife" then
- KnifeKills = KnifeKills + 1
- k.KnifeKills = k.KnifeKills + 1
- end
- if v != k and k:IsValid() then
- TotalDeaths = TotalDeaths + 1
- v.TotalDeaths = v.TotalDeaths + 1
- TotalKills = TotalKills + 1
- k.TotalKills = k.TotalKills + 1
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement