Advertisement
Guest User

Admin popups hook usage example

a guest
Jan 23rd, 2016
5,426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. if SERVER then
  2.     if not file.Exists("caseclaims.txt","DATA") then
  3.         file.Write("caseclaims.txt","[]")
  4.     end
  5.    
  6.     local caseclaims = util.JSONToTable(file.Read("caseclaims.txt","DATA"))
  7.    
  8.     local function tabletofile()
  9.         file.Write("caseclaims.txt",util.TableToJSON(caseclaims))
  10.     end
  11.    
  12.     hook.Add("ASayPopupClaim","StoreClaims",function(admin,noob)
  13.         -- insert if it doesn't exist
  14.         caseclaims[admin:SteamID()] = caseclaims[admin:SteamID()] or {
  15.             name = admin:Nick(),
  16.             claims = 0,
  17.             lastclaim = os.time()
  18.         }
  19.         -- update it
  20.         caseclaims[admin:SteamID()] = {
  21.             name = admin:Nick(),
  22.             claims = caseclaims[admin:SteamID()].claims + 1,
  23.             lastclaim = os.time()
  24.         }
  25.        
  26.         tabletofile()
  27.     end)
  28.    
  29.     util.AddNetworkString("ViewClaims")
  30.    
  31.     net.Receive("ViewClaims",function(len,ply)
  32.         local sid = net.ReadString()
  33.         net.Start("ViewClaims")
  34.             net.WriteTable(caseclaims)
  35.             net.WriteString(sid)
  36.         net.Send(ply)
  37.     end)
  38.    
  39. end
  40.  
  41. if CLIENT then
  42.    
  43.     net.Receive("ViewClaims",function(len)
  44.         local tbl = net.ReadTable()
  45.         local steamid = net.ReadString()
  46.         if steamid and steamid ~= "" and steamid ~= " " then
  47.             local v = tbl[steamid]
  48.             print(v.name.." - "..v.claims.." - last claim "..string.NiceTime(os.time() - v.lastclaim).." ago")
  49.         else
  50.             for k,v in pairs(tbl) do
  51.                 print(v.name.." - "..v.claims.." - last claim "..string.NiceTime(os.time() - v.lastclaim).." ago")
  52.             end
  53.         end
  54.        
  55.     end)
  56.    
  57.     concommand.Add("viewclaims",function(pl,cmd,args)
  58.         net.Start("ViewClaims")
  59.             net.WriteString(table.concat(args,""))
  60.         net.SendToServer()
  61.     end)
  62.    
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement