Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- TODO:
- Make it send the difference only instead of the entire table of suggestions
- nero commands
- ratings, maybe have the suggestions start at a low alpha and make them gain alpha the higher rated they are
- ]]
- ms.MapSuggestions = {}
- if CLIENT then
- local enabled = CreateClientConVar("draw_map_suggestions", "0", false)
- datastream.Hook("mapsuggestions", function(_,_,_,tbl)
- ms.MapSuggestions = tbl
- for key, value in pairs(tbl) do
- if value.text then
- local player = player.GetByUniqueID(value.uniqueid)
- value.markup = markup.Parse("<font=Trebuchet19>"..value.text.."</font>\n-<font=HudHintTextSmall>"..(IsValid(player) and player:Nick() or value.by).."\n"..key.."</font>")
- end
- end
- end)
- hook.Add("HUDPaint", "mapsuggestions", function()
- if --[[ enabled:GetBool() and ]] ms.MapSuggestions then
- for crc, data in pairs(ms.MapSuggestions) do
- if data.endpos:Distance(LocalPlayer():EyePos()) > 1000 then continue end
- local start_pos = (LerpVector(0.9, data.startpos, data.endpos)):ToScreen()
- local end_pos = data.endpos:ToScreen()
- if end_pos.x > 0 and end_pos.x < ScrW() and end_pos.y > 0 and end_pos.y < ScrH() then
- data.markup:Draw(end_pos.x,end_pos.y)
- surface.SetDrawColor(255,255,255,255)
- surface.DrawLine(start_pos.x, start_pos.y, end_pos.x, end_pos.y)
- end
- end
- end
- end)
- else
- function AddMapSuggestion(ply, suggestion)
- local tbl = {
- by = ply:Nick(),
- uniqueid = ply:UniqueID(),
- startpos = ply:GetShootPos(),
- endpos = ply:GetEyeTrace().HitPos,
- text = suggestion,
- }
- local id = util.CRC(ply:UniqueID()..suggestion)
- file.Write(
- "mapsuggestions/"..id..".txt",
- glon.encode(tbl)
- )
- ms.MapSuggestions[id] = tbl
- datastream.StreamToClients(player.GetAll(), "mapsuggestions", ms.MapSuggestions)
- end
- function LoadMapSuggestions()
- for key, value in pairs(file.Find("mapsuggestions/*.txt")) do
- ms.MapSuggestions[value:Left(-5)] = glon.decode(file.Read("mapsuggestions/"..value))
- end
- datastream.StreamToClients(player.GetAll(), "mapsuggestions", ms.MapSuggestions)
- end
- function ClearMapSuggestions()
- for key, value in pairs(file.Find("mapsuggestions/*.txt")) do
- file.Delete("mapsuggestions/"..value)
- ms.MapSuggestions[id] = nil
- end
- datastream.StreamToClients(player.GetAll(), "mapsuggestions", ms.MapSuggestions)
- end
- function DeleteMapSuggestion(id)
- file.Delete("mapsuggestions/"..id..".txt")
- ms.MapSuggestions[id] = nil
- datastream.StreamToClients(player.GetAll(), "mapsuggestions", ms.MapSuggestions)
- end
- function DeleteFromPlayerTrace(ply)
- for key, value in pairs(ms.MapSuggestions) do
- if value.endpos:Distance(ply:GetEyeTrace().HitPos) < 100 then
- DeleteMapSuggestion(key)
- break end
- end
- end
- concommand.Add("delete_map_suggestion", function(ply,_,args)
- if not ply:IsAdmin() then return end
- if args[1] then
- DeleteMapSuggestion(args[1])
- else
- DeleteFromPlayerTrace(ply)
- end
- end)
- concommand.Add("get_map_suggestions", function(ply)
- datastream.StreamToClients(ply, ms.MapSuggestions)
- end)
- LoadMapSuggestions()
- end
Add Comment
Please, Sign In to add comment