Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Spawn Point class
- local spawnPoint = {
- pos = Vector(0,0,0),
- };
- function spawnPoint:SetPos(pos)
- self.pos = pos;
- end
- function spawnPoint:GetPos()
- return self.pos;
- end
- function spawnManager:GenerateSpawnPoint(pos)
- local newSpawnPoint = table.Copy(spawnPoint);
- newSpawnPoint:SetPos(pos);
- return newSpawnPoint;
- end
- // Select spawn
- function spawnManager:SelectSpawn(ply)
- // Team / Job based spawn locations
- local teamNum = ply:Team();
- if (self.spawnTable[teamNum]) then // if there is a valid spawn then return a vector
- local positions = self.spawnTable[teamNum];
- local bestPosition = nil;
- for tNum, pos in next, positions do
- local isGoodPosition = true;
- for k, v in next, ents.GetAll() do
- if (!v:IsPlayer() && v:GetClass() != "prop_physics") then
- continue;
- end
- if (v:GetPos():Distance(pos) < smart_spawnmanager_config.spawnRadius) then
- isGoodPosition = false;
- end
- end
- if (isGoodPosition) then
- bestPosition = pos;
- //print("Best position found!");
- break;
- end
- end
- if (bestPosition != nil) then
- return self:GenerateSpawnPoint(bestPosition);
- end
- end
- // All purpose spawn locations
- if (self.spawnTable["all"]) then
- //print("all");
- local positions = self.spawnTable["all"];
- local bestPosition = positions[1];
- for vK, pos in next, positions do
- local isGoodPosition = true;
- for k, v in next, ents.GetAll() do
- if (!v:IsPlayer() && v:GetClass() != "prop_physics") then
- continue;
- end
- if (v:GetPos():Distance(pos) < smart_spawnmanager_config.spawnRadius) then
- isGoodPosition = false;
- end
- end
- if (isGoodPosition) then
- bestPosition = pos;
- //print("Best ALL PURPOSE position found!");
- break;
- end
- end
- return self:GenerateSpawnPoint(bestPosition);
- end
- return nil;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement