Advertisement
HK47

New custom spawnpoints

Nov 7th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.33 KB | None | 0 0
  1. if CLIENT then
  2.     local function add_wf(data)
  3.         local ply = data:ReadEntity()
  4.         local model = data:ReadString()
  5.         local pos = data:ReadVector()
  6.        
  7.         if ply.clientm and ply.clientm:IsValid() then ply.clientm:Remove() end
  8.         ply.clientm = ClientsideModel(model)
  9.        
  10.         if not ply.clientm and not ply.clientm:IsValid() then return end
  11.         local cache_model = ply.clientm
  12.        
  13.         ply.clientm:SetPos(pos)
  14.         ply.clientm:SetSequence(ply:GetSequence())
  15.         ply.clientm:SetModelScale(1.2, 0)
  16.         ply.clientm:SetRenderMode(RENDERMODE_TRANSALPHA)
  17.         ply.clientm:SetMaterial("models/vortigaunt/pupil")
  18.        
  19.         local a = 255
  20.        
  21.         hook.Add("Think", "remove_wireframe_tws" .. ply:EntIndex(), function()
  22.             if not ply:IsValid() then
  23.                 if cache_model and cache_model:IsValid() then cache_model:Remove() end
  24.                 hook.Remove("Think", "remove_wireframe_tws" .. ply:EntIndex())
  25.             end
  26.        
  27.             if ply.clientm and ply.clientm:IsValid() then
  28.                 if a <= 0 then ply.clientm:Remove() hook.Remove("Think", "remove_wireframe_tws" .. ply:EntIndex()) return end
  29.            
  30.                 a = a - 0.5
  31.                 ply.clientm:SetColor(Color(255, 255, 255, a))
  32.                 ply.clientm:SetAngles(Angle(0, CurTime() * 150, 0))
  33.             end
  34.         end)
  35.     end
  36.    
  37.     usermessage.Hook("make_wireframe_tws", add_wf)
  38.    
  39.     cl_spawnpnts = {}
  40.    
  41.     usermessage.Hook("tws_clear", function() cl_spawnpnts = {} end)
  42.    
  43.     usermessage.Hook("tws_update", function(data)
  44.         local k = data:ReadString()
  45.         local v = data:ReadVector()
  46.        
  47.         table.insert(cl_spawnpnts, { name = k, pos = v })
  48.     end)
  49.    
  50.     local function OpenMenu()
  51.         local current = { name = "Nil", pos = Vector(0, 0, 0) }
  52.        
  53.         local win = vgui.Create("DFrame")
  54.         win:SetSize(600, 450)
  55.         win:Center()
  56.         win:SetTitle("Spawnpoints manager | " .. game.GetMap())
  57.         win:MakePopup()
  58.         win.Paint = function()
  59.             if win and IsValid(win) then
  60.                 local w = win:GetWide()
  61.                 local t = win:GetTall()
  62.                    
  63.                 draw.RoundedBox(0, 0, 0, w, t, Color(0, 0, 0, 230))
  64.             end
  65.         end
  66.        
  67.         local lab = vgui.Create("DLabel", win)
  68.         lab:SetPos(230, 40)
  69.         lab:SetFont("Trebuchet24")
  70.         lab.Think = function() if current.name then lab:SetText("Point: " .. current.name) lab:SizeToContents() end end
  71.        
  72.         local lab = vgui.Create("DLabel", win)
  73.         lab:SetPos(230, 70)
  74.         lab:SetFont("Trebuchet24")
  75.         lab.Think = function() if current.pos then lab:SetText("Pos: " .. tostring(current.pos)) lab:SizeToContents() end end
  76.        
  77.         local del = vgui.Create("DButton", win)
  78.         del:SetPos(230, 110)
  79.         del:SetSize(100, 25)
  80.         del:SetText("Delete spawn point")
  81.         del.DoClick = function()
  82.             net.Start("tws_removeptn")
  83.                 net.WriteString(current.name)
  84.                 net.WriteEntity(LocalPlayer())
  85.             net.SendToServer()
  86.            
  87.             win:Close()
  88.             timer.Simple(0.1, function() if IsValid(LocalPlayer()) then OpenMenu() end end)
  89.         end
  90.        
  91.         local lst = vgui.Create("DListView", win)
  92.         lst:SetSize(200, 400)
  93.         lst:SetPos(15, 35)
  94.         lst:AddColumn("Spawnpoint")
  95.        
  96.         for k, v in pairs(cl_spawnpnts) do
  97.             lst:AddLine(v.name)
  98.         end
  99.        
  100.         lst.OnClickLine = function(parent, line, isselected)
  101.             for k, v in pairs(cl_spawnpnts) do
  102.                 if line:GetValue(1) == v.name then current = v break end
  103.             end
  104.            
  105.             hook.Add("CalcView", "tws_viewing" .. LocalPlayer():EntIndex(), function()
  106.                 if not win then hook.Remove("CalcView", "tws_viewing" .. LocalPlayer():EntIndex()) return end
  107.                 if not IsValid(win) then hook.Remove("CalcView", "tws_viewing" .. LocalPlayer():EntIndex()) return end
  108.                 if LocalPlayer():KeyPressed(IN_ATTACK) then hook.Remove("CalcView", "tws_viewing" .. LocalPlayer():EntIndex()) return end
  109.            
  110.                 local pos
  111.                
  112.                 for k, v in pairs(cl_spawnpnts) do
  113.                     if line:GetValue(1) == v.name then pos = v.pos + Vector(0, 0, 50) break end
  114.                 end
  115.                
  116.                 if not pos then hook.Remove("CalcView", "tws_viewing" .. LocalPlayer():EntIndex()) return end
  117.            
  118.                 local view = {}
  119.                
  120.                 view.origin = pos
  121.                 view.angles = Angle(0, CurTime() * 20, 0)
  122.                 view.fov = 90
  123.                      
  124.                 return view
  125.             end)
  126.            
  127.             hook.Add("ShouldDrawLocalPlayer", "tws_shldviewingself" .. LocalPlayer():EntIndex(), function(ply)
  128.                 if not win then hook.Remove("ShouldDrawLocalPlayer", "tws_shldviewingself" .. LocalPlayer():EntIndex()) return end
  129.                 if not IsValid(win) then hook.Remove("ShouldDrawLocalPlayer", "tws_shldviewingself" .. LocalPlayer():EntIndex()) return end
  130.                
  131.                 return true
  132.             end)
  133.         end
  134.     end
  135.    
  136.     usermessage.Hook("tws_mngr", OpenMenu)
  137.  
  138.     return
  139. end
  140.  
  141. function GetSpawnpoints()
  142.     return file.Find("spawnpoints_tws/"  .. game.GetMap() .. "/" .. "*.txt", "DATA")
  143. end
  144.  
  145. function UpdateSpawnpoints()
  146.     umsg.Start("tws_clear")
  147.     umsg.End()
  148.    
  149.     local sp = GetSpawnpoints()
  150.    
  151.     for i = 1, #sp do
  152.         local ptn = string.Explode(".", sp[i])
  153.        
  154.         umsg.Start("tws_update")
  155.             umsg.String(ptn[1])
  156.             umsg.Vector(GetSpawnptnPos(ptn[1]))
  157.         umsg.End()
  158.     end
  159. end
  160.  
  161. function ExSpawnptn(name)
  162.     return file.Exists("spawnpoints_tws/" .. game.GetMap() .. "/" .. name .. ".txt", "DATA")
  163. end
  164.  
  165. function GetSpawnptnPos(name)
  166.     if ExSpawnptn(name) then
  167.         local pos = file.Read("spawnpoints_tws/" .. game.GetMap() .. "/" .. name .. ".txt", "DATA")
  168.         pos = string.Explode(" ", pos)
  169.        
  170.         local num = {}
  171.         for i = 1, 3 do num[i] = pos[i] end
  172.      
  173.         return Vector(num[1], num[2], num[3])
  174.     else
  175.         return false
  176.     end
  177. end
  178.  
  179. function DelSpawnPoint(name, ply)
  180.     if ExSpawnptn(name) then
  181.         file.Delete("spawnpoints_tws/" .. game.GetMap() .. "/" .. name .. ".txt")
  182.         UpdateSpawnpoints()
  183.            
  184.         ply:ChatPrint(name .. " spawnpoints was deleted!")
  185.     end
  186. end
  187.  
  188. function AddSpawnPoint(name, ply)
  189.     if ExSpawnptn(name) then ply:ChatPrint("This spawnpoint is already existst!") return end
  190.    
  191.     file.Write("spawnpoints_tws/" .. game.GetMap() .. "/" .. name .. ".txt", tostring(ply:GetEyeTrace().HitPos))
  192.     UpdateSpawnpoints()
  193. end
  194.  
  195. util.AddNetworkString("tws_addptn")
  196. util.AddNetworkString("tws_removeptn")
  197.  
  198. /**********
  199.     Removing spawnpoint
  200. **********/
  201. net.Receive("tws_removeptn", function()
  202.     local name = net.ReadString()
  203.     local ply = net.ReadEntity()
  204.    
  205.     DelSpawnPoint(name, ply)
  206. end)
  207.  
  208. /**********
  209.     Adding spawnpoint
  210. **********/
  211. net.Receive("tws_addptn", function()
  212.     local name = net.ReadString()
  213.     local ply = net.ReadEntity()
  214.    
  215.     AddSpawnPoint(name, ply)
  216. end)
  217.  
  218. if not file.Exists("spawnpoints_tws", "DATA") then
  219.     file.CreateDir("spawnpoints_tws")
  220. end
  221.  
  222. if not file.Exists("spawnpoints_tws/" .. game.GetMap(), "DATA") then
  223.     file.CreateDir("spawnpoints_tws/" .. game.GetMap())
  224. else
  225.     UpdateSpawnpoints()
  226. end
  227.  
  228.  
  229. hook.Add("PlayerSay", "custom_spawnp_tws", function(ply, text, team)
  230.     if not ply:IsAdmin() then return end
  231.    
  232.     local str = string.Explode(" ", text)
  233.    
  234.     if str[1] == "/mngr" then
  235.         UpdateSpawnpoints()
  236.        
  237.         umsg.Start("tws_mngr")
  238.         umsg.End()
  239.     end
  240.    
  241.     if str[1] == "/delsptn" then
  242.         DelSpawnPoint(str[2], ply)
  243.        
  244.         return ""
  245.     end
  246.    
  247.     if str[1] == "/addsptn" then
  248.         AddSpawnPoint(str[2], ply)
  249.    
  250.         ply:ChatPrint(str[2] .. " spawnpoint is done!")
  251.        
  252.         return ""
  253.     end
  254.    
  255.     if str[1] == "/showptn" then
  256.         for k, v in pairs(GetSpawnpoints()) do
  257.             ply:ChatPrint(v)
  258.         end
  259.        
  260.         return ""
  261.     end
  262. end)
  263.  
  264. hook.Add("PlayerSpawn", "ply_spawn_tws", function(ply)
  265.     local tbl = table.Random(GetSpawnpoints())
  266.    
  267.     if not tbl then return end
  268.    
  269.     tbl = string.Explode(".", tbl)
  270.     tbl = tbl[1]
  271.    
  272.     if GetSpawnptnPos(tbl) then ply:SetPos(GetSpawnptnPos(tbl)) ply:SetEyeAngles(Angle(0, 0, 0)) end
  273. end)
  274.  
  275. hook.Add("PlayerSpawn", "tws_spawnprotect", function(ply)
  276.     if CLIENT then return end
  277.    
  278.     ply:GodEnable()
  279.     ply:ChatPrint("TEST")
  280.    
  281.     local model = ply:GetModel()
  282.     local pos = ply:GetPos()
  283.    
  284.     umsg.Start("make_wireframe_tws")
  285.         umsg.Entity(ply)
  286.         umsg.String(model)
  287.         umsg.Vector(pos)
  288.     umsg.End()
  289.    
  290.     timer.Simple(6, function()
  291.         if IsValid(ply) then
  292.             ply:GodDisable()
  293.         end
  294.     end)
  295. end)
  296.  
  297. //blocker
  298.  
  299. hook.Add("PlayerSpawnSENT", "blocker_tws", function(ply, class)
  300.     if class == "sent_ball" then return false end
  301.     return true
  302. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement