Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.71 KB | None | 0 0
  1. if not SERVER then return end
  2.  
  3. local function PlaceWeapon(swep, pos, ang)
  4.    local cls = swep and WEPS.GetClass(swep)
  5.    if not cls then return end
  6.  
  7.    -- Create the weapon, somewhat in the air in case the spot hugs the ground.
  8.    local ent = ents.Create(cls)
  9.    pos.z = pos.z + 3
  10.    ent:SetPos(pos)
  11.    ent:SetAngles(VectorRand():Angle())
  12.    ent:Spawn()
  13.  
  14.    -- Create some associated ammo (if any)
  15.    if ent.AmmoEnt then
  16.       for i=1, math.random(0,3) do
  17.          local ammo = ents.Create(ent.AmmoEnt)
  18.  
  19.          if IsValid(ammo) then
  20.             pos.z = pos.z + 2
  21.             ammo:SetPos(pos)
  22.             ammo:SetAngles(VectorRand():Angle())
  23.             ammo:Spawn()
  24.             ammo:PhysWake()
  25.          end
  26.       end
  27.    end
  28.  
  29.    return ent
  30. end
  31.  
  32. local function SpawnWeps()
  33.     if #player.GetAll() == 0 then return end
  34.  
  35.     for k,v in pairs(ents.GetAll()) do
  36.        if IsValid(v) and v.AutoSpawnable and not IsValid(v:GetOwner()) then
  37.           v:Remove()
  38.        end
  39.     end
  40.  
  41.     local spot_classes = {
  42.         ["info_player_teamspawn"] = true,
  43.         ["team_control_point"] = true,
  44.         ["team_control_point_master"] = true,
  45.         ["team_control_point_round"] = true,
  46.         ["item_ammopack_full"] = true,
  47.         ["item_ammopack_medium"] = true,
  48.         ["item_ammopack_small"] = true,
  49.         ["item_healthkit_full"] = true,
  50.         ["item_healthkit_medium"] = true,
  51.         ["item_healthkit_small"] = true,
  52.         ["item_teamflag"] = true,
  53.         ["game_intro_viewpoint"] = true,
  54.         ["info_observer_point"] = true,
  55.         ["info_player_terrorist"] = true,
  56.         ["info_player_counterterrorist"] = true,
  57.         ["hostage_entity"] = true,
  58.         ["info_player_deathmatch"] = true,
  59.     }
  60.  
  61.     local spots = {}
  62.     for _, e in pairs(ents.GetAll()) do
  63.         if( spot_classes[e:GetClass()] ) then
  64.             table.insert(spots, e)
  65.         end
  66.     end
  67.  
  68.    local spawnables = ents.TTT.GetSpawnableSWEPs()
  69.  
  70.    local max = #spots*3
  71.  
  72.    local num = 0
  73.    local w = nil
  74.    for k, v in RandomPairs(spots) do
  75.       w = table.Random(spawnables)
  76.       if w and IsValid(v) and util.IsInWorld(v:GetPos()) then
  77.          local spawned = PlaceWeapon(w, v:GetPos(), v:GetAngles())
  78.  
  79.          num = num + 1
  80.          if spawned and spawned.IsGrenade then
  81.             w = table.Random(spawnables)
  82.             if w then
  83.                PlaceWeapon(w, v:GetPos(), v:GetAngles())
  84.             end
  85.          end
  86.       end
  87.  
  88.       if num > max then
  89.          return
  90.       end
  91.    end
  92. end
  93.  
  94.  
  95. local function SpawnPlayer( ply )
  96.     ply:SetTeam( TEAM_TERROR )
  97.     ply:Spawn()
  98. end
  99.  
  100. timer.Simple(60, function()
  101.     timer.Create( "FG_Wait", 60, 0, function()
  102.         if GAMEMODE.round_state ~= ROUND_WAIT then return end
  103.        
  104.         SpawnWeps()
  105.     end)
  106.      
  107.      
  108.     hook.Add("Think", "FG_Wait", function()
  109.         if GAMEMODE.round_state ~= ROUND_WAIT then return end
  110.      
  111.         for k, ply in pairs(player.GetAll()) do
  112.             if not ply:Alive() or ply:Team() == TEAM_SPEC then
  113.                 SpawnPlayer( ply )
  114.             end
  115.         end
  116.     end)
  117.      
  118.     hook.Add("PlayerInitialSpawn", "FG_Wait", function(ply)
  119.         if GAMEMODE.round_state ~= ROUND_WAIT then return end
  120.        
  121.         timer.Simple(1, SpawnWeps)
  122.     end)
  123.      
  124.     hook.Add("PlayerDeath", "FG_Wait", function( ply, inflictor, attacker )
  125.         if GAMEMODE.round_state ~= ROUND_WAIT then return end
  126.      
  127.         for k,ent in pairs(ents.GetAll()) do
  128.             if ent:GetClass() == "prop_ragdoll" then
  129.                 if ent.sid == ply:SteamID() and CurTime() - ent.time > 0.1 then
  130.                     ent:Remove()
  131.                 end
  132.             end
  133.         end
  134.     end)
  135. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement