Advertisement
HK47

spawnpoints fixed

Oct 26th, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.18 KB | None | 0 0
  1. if CLIENT then return end
  2.  
  3. SPAWNPOINTS_TWS = {}
  4.  
  5. if not file.Exists("spawnpoints_tws", "DATA") then
  6.     file.CreateDir("spawnpoints_tws")
  7. end
  8.  
  9. if not file.Exists("spawnpoints_tws/" .. game.GetMap(), "DATA") then
  10.     file.CreateDir("spawnpoints_tws/" .. game.GetMap())
  11. else
  12.     local sp = file.Find("spawnpoints_tws/"  .. game.GetMap() .. "/" .. "*.txt", "DATA")
  13.    
  14.     for i = 1, #sp do
  15.         table.insert(SPAWNPOINTS_TWS, sp[i])
  16.     end
  17. end
  18.  
  19.  
  20. hook.Add("PlayerSay", "custom_spawnp_tws", function(ply, text, team)
  21.     if not ply:IsAdmin() then return end
  22.    
  23.     local str = string.Explode(" ", text)
  24.    
  25.     if str[1] == "/delspawnpoint" then
  26.         if file.Exists("spawnpoints_tws/" .. game.GetMap() .. "/" .. str[2] .. ".txt", "DATA") then
  27.             file.Delete("spawnpoints_tws/" .. game.GetMap() .. "/" .. str[2] .. ".txt")
  28.            
  29.             table.RemoveByValue(SPAWNPOINTS_TWS, str[2] .. ".txt")
  30.            
  31.             ply:ChatPrint(str[2] .. " spawnpoints was deleted!")
  32.         end
  33.     end
  34.    
  35.     if str[1] == "/addspawnpoint" then
  36.         if file.Exists("spawnpoints_tws/" .. game.GetMap() .. "/" .. str[2] .. ".txt", "DATA") then ply:ChatPrint("This spawnpoint is already existst!") return end
  37.    
  38.         file.Write("spawnpoints_tws/" .. game.GetMap() .. "/" .. str[2] .. ".txt", tostring(ply:GetEyeTrace().HitPos))
  39.    
  40.         table.insert(SPAWNPOINTS_TWS, str[2] .. ".txt")
  41.    
  42.         ply:ChatPrint(str[2] .. " spawnpoint is done!")
  43.     end
  44.    
  45.     if str[1] == "/printallsp" then
  46.         for k, v in pairs(SPAWNPOINTS_TWS) do
  47.             ply:ChatPrint(v .. " " .. file.Read("spawnpoints_tws/" .. game.GetMap() .. "/" .. v, "DATA"))
  48.         end
  49.     end
  50. end)
  51.  
  52. hook.Add("PlayerSpawn", "ply_spawn_tws", function(ply)
  53.     local tbl = table.Random(SPAWNPOINTS_TWS)
  54.    
  55.     if not tbl then return end
  56.     if not file.Exists("spawnpoints_tws/" .. game.GetMap() .. "/" .. tbl, "DATA") then return end
  57.  
  58.     local pos = file.Read("spawnpoints_tws/" .. game.GetMap() .. "/" .. tbl, "DATA")
  59.     pos = string.Explode(" ", pos)
  60.    
  61.     local num = {}
  62.     for i = 1, 3 do num[i] = pos[i] end
  63.  
  64.     ply:SetPos(Vector(num[1], num[2], num[3]))
  65. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement