Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. // Spawn Point class
  2. local spawnPoint = {
  3.     pos = Vector(0,0,0),
  4. };
  5.  
  6. function spawnPoint:SetPos(pos)
  7.     self.pos = pos;
  8. end
  9.  
  10. function spawnPoint:GetPos()
  11.     return self.pos;
  12. end
  13. function spawnManager:GenerateSpawnPoint(pos)
  14.  
  15.     local newSpawnPoint = table.Copy(spawnPoint);
  16.     newSpawnPoint:SetPos(pos);
  17.    
  18.     return newSpawnPoint;
  19. end
  20.  
  21. // Select spawn
  22. function spawnManager:SelectSpawn(ply)
  23.    
  24.     // Team / Job based spawn locations
  25.     local teamNum = ply:Team();
  26.     if (self.spawnTable[teamNum]) then // if there is a valid spawn then return a vector
  27.        
  28.         local positions = self.spawnTable[teamNum];
  29.         local bestPosition = nil;
  30.        
  31.         for tNum, pos in next, positions do
  32.            
  33.             local isGoodPosition = true;
  34.             for k, v in next, ents.GetAll() do
  35.                 if (!v:IsPlayer() && v:GetClass() != "prop_physics") then
  36.                     continue;
  37.                 end
  38.            
  39.                 if (v:GetPos():Distance(pos) < smart_spawnmanager_config.spawnRadius) then
  40.                     isGoodPosition = false;
  41.                 end
  42.             end
  43.             if (isGoodPosition) then
  44.                 bestPosition = pos;
  45.                 //print("Best position found!");
  46.                 break;
  47.             end
  48.         end
  49.        
  50.         if (bestPosition != nil) then
  51.             return self:GenerateSpawnPoint(bestPosition);
  52.         end
  53.     end
  54.    
  55.     // All purpose spawn locations
  56.     if (self.spawnTable["all"]) then
  57.         //print("all");
  58.         local positions = self.spawnTable["all"];
  59.         local bestPosition = positions[1];
  60.    
  61.         for vK, pos in next, positions do
  62.        
  63.             local isGoodPosition = true;
  64.             for k, v in next, ents.GetAll() do  
  65.                 if (!v:IsPlayer() && v:GetClass() != "prop_physics") then
  66.                     continue;
  67.                 end
  68.                
  69.                 if (v:GetPos():Distance(pos) < smart_spawnmanager_config.spawnRadius) then
  70.                     isGoodPosition = false;
  71.                 end
  72.             end
  73.             if (isGoodPosition) then
  74.                 bestPosition = pos;
  75.                 //print("Best   ALL PURPOSE position found!");
  76.                 break;
  77.             end
  78.         end
  79.        
  80.         return self:GenerateSpawnPoint(bestPosition);
  81.     end
  82.    
  83.    
  84.     return nil;
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement