Advertisement
clark

TTT Stats by Clark

Apr 30th, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.42 KB | None | 0 0
  1.  
  2. local TraitorRoundNumber = 0
  3. local TerrorRoundNumber = 0
  4. local TeamKills = 0
  5. local TraitorKills =  0
  6. local DetectiveKills = 0
  7. local InnocentKills = 0
  8. local KnifeKills = 0
  9. local TotalKills =0
  10. local TotalDeaths =0
  11.  
  12. timer.Simple(10, function()
  13.     tmysql.query( "SELECT * FROM `stats_server`", function( SQLTable )
  14.         if !SQLTable or #SQLTable == 0 then print("STATS -> Couldnt find server stats.") return end
  15.         if SQLTable and SQLTable[1][1] then
  16.             TraitorRoundNumber = SQLTable[1][1]
  17.             TerrorRoundNumber = SQLTable[1][2]
  18.             TeamKills = SQLTable[1][3]
  19.             TraitorKills =  SQLTable[1][4]
  20.             DetectiveKills = SQLTable[1][5]
  21.             InnocentKills = SQLTable[1][6]
  22.             KnifeKills = SQLTable[1][7]
  23.             TotalKills = SQLTable[1][8]
  24.             TotalDeaths = SQLTable[1][9]
  25.             print("STATS -> Found server stats.")
  26.         else
  27.             print("STATS -> Couldnt find server stats.")
  28.         end
  29.     end)
  30. end)
  31.  
  32.  
  33. function SQLHandle( result, _, error )
  34.     if error and error != 0 then
  35.         print( "SQL ERROR: " .. error )
  36.     end
  37. end
  38.  
  39. hook.Add("TTTEndRound", "Stats.TTTEndRound", function( team )
  40.     if team == WIN_TRAITOR then
  41.         TraitorRoundNumber = TraitorRoundNumber + 1
  42.     elseif team == WIN_INNOCENT or team == WIN_TIMELIMIT then
  43.         TerrorRoundNumber = TerrorRoundNumber + 1
  44.     end
  45.     tmysql.query( "UPDATE stats_server SET terrorrounds='" .. TerrorRoundNumber .. "', traitorrounds= '" .. TraitorRoundNumber .. "', teamkills= '" .. TeamKills .. "', traitorkills= '" .. TraitorKills .. "', detectivekills= '" .. DetectiveKills .. "', knifekills= '" .. KnifeKills .. "', totalkills= '" .. TotalKills .. "', totaldeaths= '" .. TotalDeaths .. "'", SQLHandle )
  46.     for k, v in pairs(player.GetAll()) do
  47.         if team == WIN_TRAITOR then
  48.             if v:IsRole(ROLE_TRAITOR) then
  49.                 v.TraitorRoundNumber = v.TraitorRoundNumber + 1
  50.             end
  51.         elseif team == WIN_INNOCENT or team == WIN_TIMELIMIT then
  52.             if !v:IsRole(ROLE_TRAITOR) then
  53.                 v.TerrorRoundNumber = v.TerrorRoundNumber + 1
  54.             end
  55.         end
  56.         if v:IsPlayer() then
  57.             timer.Simple(math.random(1,15), function()
  58.                 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 )
  59.             end)
  60.         end
  61.     end
  62. end)
  63.  
  64. hook.Add("PlayerInitialSpawn", "Stats.PlayerInitialSpawn", function( p )
  65.     tmysql.query("SELECT * FROM `stats_players` WHERE steamid = '" .. p:SteamID() .. "'", function( Args )
  66.         if !Args or #Args == 0 then
  67.             p.TraitorRoundNumber = 0
  68.             p.TerrorRoundNumber = 0
  69.             p.TeamKills = 0
  70.             p.TraitorKills = 0
  71.             p.DetectiveKills = 0
  72.             p.InnocentKills = 0
  73.             p.KnifeKills = 0
  74.             p.TotalKills = 0
  75.             p.TotalDeaths = 0
  76.             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 )
  77.         elseif p:SteamID() == Args[1][1] then
  78.             p.TraitorRoundNumber = Args[1][2]
  79.             p.TerrorRoundNumber = Args[1][3]
  80.             p.TeamKills = Args[1][4]
  81.             p.TraitorKills = Args[1][5]
  82.             p.DetectiveKills = Args[1][6]
  83.             p.InnocentKills = Args[1][7]
  84.             p.KnifeKills = Args[1][8]
  85.             p.TotalKills = Args[1][9]
  86.             p.TotalDeaths = Args[1][10]
  87.         end
  88.     end)
  89. end)
  90.  
  91. hook.Add("PlayerDeath", "Stats.PlayerDeath", function( v, w, k )
  92.     if v:IsPlayer() and k:IsPlayer() then
  93.         if !k:IsRole(ROLE_TRAITOR) and !k:IsRole(ROLE_DETECTIVE) then
  94.             if !v:IsRole(ROLE_TRAITOR) and !v:IsRole(ROLE_DETECTIVE) and v != k and k:IsPlayer() then
  95.                 TeamKills = TeamKills + 1
  96.                 k.TeamKills = k.TeamKills + 1
  97.             elseif v:IsRole(ROLE_TRAITOR) then
  98.                 TraitorKills = TraitorKills + 1
  99.                 k.TraitorKills = k.TraitorKills + 1
  100.             elseif v:IsRole(ROLE_DETECTIVE) then
  101.                 DetectiveKills = DetectiveKills + 1
  102.                 k.DetectiveKills = k.DetectiveKills + 1
  103.             end
  104.         elseif k:IsRole(ROLE_TRAITOR) then
  105.             if !v:IsRole(ROLE_TRAITOR) and !v:IsRole(ROLE_DETECTIVE) then
  106.                 InnocentKills = InnocentKills + 1
  107.                 k.InnocentKills = k.InnocentKills + 1
  108.             elseif v:IsRole(ROLE_TRAITOR) and v != k and k:IsPlayer() then
  109.                 TeamKills = TeamKills + 1
  110.                 k.TeamKills = k.TeamKills + 1
  111.             elseif v:IsRole(ROLE_DETECTIVE) then
  112.                 DetectiveKills = DetectiveKills + 1
  113.                 k.DetectiveKills = k.DetectiveKills + 1
  114.             end
  115.         elseif k:IsRole(ROLE_DETECTIVE) then
  116.             if !v:IsRole(ROLE_TRAITOR) and !v:IsRole(ROLE_DETECTIVE) then
  117.                 InnocentKills = InnocentKills + 1
  118.                 k.InnocentKills = k.InnocentKills + 1
  119.             elseif v:IsRole(ROLE_TRAITOR) then
  120.                 TraitorKills = TraitorKills + 1
  121.                 k.TraitorKills = k.TraitorKills + 1
  122.             elseif v:IsRole(ROLE_DETECTIVE) and v != k and k:IsPlayer() then
  123.                 TeamKills = TeamKills + 1
  124.                 k.TeamKills = k.TeamKills + 1
  125.             end
  126.         end
  127.         if IsValid(w) and w:GetClass() == "weapon_ttt_knife" then
  128.             KnifeKills = KnifeKills + 1
  129.             k.KnifeKills = k.KnifeKills + 1
  130.         end
  131.         if v != k and k:IsValid() then
  132.             TotalDeaths = TotalDeaths + 1
  133.             v.TotalDeaths = v.TotalDeaths + 1
  134.             TotalKills = TotalKills + 1
  135.             k.TotalKills = k.TotalKills + 1
  136.         end
  137.     end
  138. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement