Python1320

Untitled

Nov 25th, 2010
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.14 KB | None | 0 0
  1. --[[
  2.     TODO:
  3.         Make it send the difference only instead of the entire table of suggestions
  4.         nero commands
  5.         ratings, maybe have the suggestions start at a low alpha and make them gain alpha the higher rated they are
  6. ]]
  7.  
  8.  
  9. ms.MapSuggestions = {}
  10.  
  11. if CLIENT then
  12.     local enabled = CreateClientConVar("draw_map_suggestions", "0", false)
  13.  
  14.     datastream.Hook("mapsuggestions", function(_,_,_,tbl)
  15.         ms.MapSuggestions = tbl
  16.         for key, value in pairs(tbl) do
  17.             if value.text then
  18.                 local player = player.GetByUniqueID(value.uniqueid)
  19.                 value.markup = markup.Parse("<font=Trebuchet19>"..value.text.."</font>\n-<font=HudHintTextSmall>"..(IsValid(player) and player:Nick() or value.by).."\n"..key.."</font>")
  20.             end
  21.         end
  22.     end)
  23.    
  24.     hook.Add("HUDPaint", "mapsuggestions", function()
  25.         if --[[ enabled:GetBool() and ]] ms.MapSuggestions then    
  26.             for crc, data in pairs(ms.MapSuggestions) do
  27.                 if data.endpos:Distance(LocalPlayer():EyePos()) > 1000 then continue end
  28.                 local start_pos = (LerpVector(0.9, data.startpos, data.endpos)):ToScreen()
  29.                 local end_pos = data.endpos:ToScreen()
  30.                 if end_pos.x > 0 and end_pos.x < ScrW() and end_pos.y > 0 and end_pos.y < ScrH() then
  31.                     data.markup:Draw(end_pos.x,end_pos.y)
  32.                     surface.SetDrawColor(255,255,255,255)
  33.                     surface.DrawLine(start_pos.x, start_pos.y, end_pos.x, end_pos.y)
  34.                 end
  35.             end
  36.         end
  37.     end)
  38. else
  39.     function AddMapSuggestion(ply, suggestion)
  40.         local tbl = {
  41.             by = ply:Nick(),
  42.             uniqueid = ply:UniqueID(),
  43.             startpos = ply:GetShootPos(),
  44.             endpos = ply:GetEyeTrace().HitPos,
  45.             text = suggestion,
  46.         }
  47.        
  48.         local id = util.CRC(ply:UniqueID()..suggestion)
  49.        
  50.         file.Write(
  51.             "mapsuggestions/"..id..".txt",
  52.             glon.encode(tbl)
  53.         )
  54.        
  55.         ms.MapSuggestions[id] = tbl
  56.        
  57.         datastream.StreamToClients(player.GetAll(), "mapsuggestions", ms.MapSuggestions)
  58.     end
  59.    
  60.     function LoadMapSuggestions()
  61.         for key, value in pairs(file.Find("mapsuggestions/*.txt")) do
  62.             ms.MapSuggestions[value:Left(-5)] = glon.decode(file.Read("mapsuggestions/"..value))
  63.         end
  64.        
  65.         datastream.StreamToClients(player.GetAll(), "mapsuggestions", ms.MapSuggestions)
  66.     end
  67.    
  68.     function ClearMapSuggestions()
  69.         for key, value in pairs(file.Find("mapsuggestions/*.txt")) do
  70.             file.Delete("mapsuggestions/"..value)
  71.             ms.MapSuggestions[id] = nil
  72.         end
  73.         datastream.StreamToClients(player.GetAll(), "mapsuggestions", ms.MapSuggestions)
  74.     end
  75.    
  76.     function DeleteMapSuggestion(id)
  77.         file.Delete("mapsuggestions/"..id..".txt")
  78.         ms.MapSuggestions[id] = nil
  79.         datastream.StreamToClients(player.GetAll(), "mapsuggestions", ms.MapSuggestions)
  80.     end
  81.    
  82.     function DeleteFromPlayerTrace(ply)
  83.         for key, value in pairs(ms.MapSuggestions) do
  84.             if value.endpos:Distance(ply:GetEyeTrace().HitPos) < 100 then
  85.                 DeleteMapSuggestion(key)
  86.             break end
  87.         end
  88.     end
  89.    
  90.     concommand.Add("delete_map_suggestion", function(ply,_,args)
  91.         if not ply:IsAdmin() then return end
  92.         if args[1] then
  93.             DeleteMapSuggestion(args[1])
  94.         else
  95.             DeleteFromPlayerTrace(ply)
  96.         end
  97.     end)
  98.    
  99.     concommand.Add("get_map_suggestions", function(ply)
  100.         datastream.StreamToClients(ply, ms.MapSuggestions)
  101.     end)
  102.  
  103.     LoadMapSuggestions()
  104. end
Add Comment
Please, Sign In to add comment