Advertisement
Guest User

sv_damageinfos.lua

a guest
Aug 19th, 2014
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 KB | None | 0 0
  1. util.AddNetworkString("DL_AskDamageInfos")
  2. util.AddNetworkString("DL_SendDamageInfos")
  3. util.AddNetworkString("DL_AskShootLogs")
  4. util.AddNetworkString("DL_SendShootLogs")
  5.  
  6. function Damagelog:shootCallback(weapon)
  7.     local owner = weapon.Owner
  8.     if GetRoundState() == ROUND_ACTIVE then
  9.         if self.ShootTables[self.CurrentRound][self.Time] then
  10.             local info = { owner:Nick(), weapon:GetClass() }
  11.             table.insert(self.ShootTables[self.CurrentRound][self.Time], info)         
  12.         else
  13.             table.insert(self.ShootTables[self.CurrentRound], self.Time, {})
  14.             local info = { owner:Nick(), weapon:GetClass() }
  15.             table.insert(self.ShootTables[self.CurrentRound][self.Time], info)
  16.         end
  17.     end
  18. end
  19.      
  20. function Damagelog:DamagelogInfos()
  21.     for k,v in pairs(weapons.GetList()) do     
  22.         if v.Base == "weapon_tttbase" then
  23.             if not v.PrimaryAttack then
  24.                 v.PrimaryAttack = function(wep)
  25.                     wep.BaseClass.PrimaryAttack(wep)
  26.                     if wep.BaseClass.CanPrimaryAttack(wep) and IsValid(wep.Owner) then
  27.                         self:shootCallback(wep)
  28.                     end
  29.                 end
  30.             else
  31.                 local oldprimary = v.PrimaryAttack
  32.                 v.PrimaryAttack = function(wep)
  33.                     oldprimary(wep)
  34.                     Damagelog:shootCallback(wep)
  35.                 end
  36.             end
  37.         end
  38.     end
  39. end
  40.    
  41. hook.Add("Initialize", "Initialize_DamagelogInfos", function() 
  42.     Damagelog:DamagelogInfos()
  43. end)
  44.  
  45. function Damagelog:SendDamageInfos(ply, t, att, victim, round)
  46.     local results = {}
  47.     local found = false
  48.     for k,v in pairs(self.ShootTables[round] or {}) do
  49.         if k >= t - 10 and k <= t then
  50.             for s,i in pairs(v) do
  51.                 if i[1] == victim or i[1] == att then
  52.                     if results[k] == nil then
  53.                         table.insert(results, k, {})
  54.                     end
  55.                     table.insert(results[k], i)
  56.                     found = true
  57.                 end
  58.             end
  59.         end
  60.     end
  61.     local beg = t - 10
  62.     if found then
  63.         net.Start("DL_SendDamageInfos")
  64.         net.WriteUInt(0,1)
  65.         net.WriteUInt(beg, 32)
  66.         net.WriteUInt(t, 32)
  67.         net.WriteTable(results)
  68.         net.WriteString(victim)
  69.         net.WriteString(att)
  70.         net.Send(ply)
  71.     else
  72.         net.Start("DL_SendDamageInfos")
  73.         net.WriteUInt(1,1)
  74.         net.WriteUInt(beg, 32)
  75.         net.WriteUInt(t, 32)
  76.         net.WriteString(victim)
  77.         net.WriteString(att)
  78.         net.Send(ply)
  79.     end
  80. end
  81.  
  82. net.Receive("DL_AskDamageInfos", function(_, ply)
  83.     local time = net.ReadUInt(32)
  84.     local attacker = net.ReadString()
  85.     local victim = net.ReadString()
  86.     local round = net.ReadUInt(32)
  87.     Damagelog:SendDamageInfos(ply, time, attacker, victim, round)
  88. end)
  89.  
  90. local orderedPairs = Damagelog.orderedPairs
  91. net.Receive("DL_AskShootLogs", function(_, ply)
  92.     if not ply:CanUseDamagelog() then return end
  93.     local data = Damagelog.ShootTables[net.ReadUInt(8)]
  94.     if not data then return end
  95.     data = table.Copy(data)
  96.     local count = table.Count(data)
  97.     local i = 0
  98.     if count <= 0 then
  99.         net.Start("DL_SendShootLogs")
  100.         net.WriteTable({"empty"})
  101.         net.WriteUInt(1, 1)
  102.         net.Send(ply)
  103.     else
  104.         for k,v in orderedPairs(data) do
  105.             i = i + 1
  106.             net.Start("DL_SendShootLogs")
  107.             net.WriteTable(v)
  108.             net.WriteUInt(i == count and 1 or 0, 1)
  109.             net.Send(ply)
  110.         end
  111.     end
  112. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement