diff --git a/garrysmod/gamemodes/base/gamemode/player.lua b/garrysmod/gamemodes/base/gamemode/player.lua index 98b6342dc4..f803426a8b 100644 --- a/garrysmod/gamemodes/base/gamemode/player.lua +++ b/garrysmod/gamemodes/base/gamemode/player.lua @@ -361,93 +361,95 @@ end Name: gamemode:PlayerSelectSpawn( player ) Desc: Find a spawn point entity for this player -----------------------------------------------------------]] -function GM:PlayerSelectSpawn( pl, transiton ) +GM.SpawnPointClasses = { + "info_player_start", + "info_player_deathmatch", + "info_player_combine", + "info_player_rebel", - -- If we are in transition, do not reset player's position - if ( transiton ) then return end + -- Portal 2 Coop + "info_player_coop", - if ( self.TeamBased ) then + -- CS Maps + "info_player_counterterrorist", + "info_player_terrorist", - local ent = self:PlayerSelectTeamSpawn( pl:Team(), pl ) - if ( IsValid( ent ) ) then return ent end + -- DOD Maps + "info_player_axis", + "info_player_allies", - end + -- (Old) GMod Maps + "gmod_player_start", - -- Save information about all of the spawn points - -- in a team based game you'd split up the spawns - if ( !IsTableOfEntitiesValid( self.SpawnPoints ) ) then + -- TF Maps + "info_player_teamspawn", - self.LastSpawnPoint = 0 - self.SpawnPoints = ents.FindByClass( "info_player_start" ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_deathmatch" ) ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_combine" ) ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_rebel" ) ) + -- INS Maps + "ins_spawnpoint", - -- Portal 2 Coop - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_coop_spawn" ) ) + -- AOC Maps + "aoc_spawnpoint", - -- CS Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_counterterrorist" ) ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_terrorist" ) ) + -- Dystopia Maps + "dys_spawn_point", - -- DOD Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_axis" ) ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_allies" ) ) + -- PVKII Maps + "info_player_pirate", + "info_player_viking", + "info_player_knight", - -- (Old) GMod Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "gmod_player_start" ) ) + -- DIPRIP Maps + "diprip_start_team_blue", + "diprip_start_team_red", - -- TF Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_teamspawn" ) ) + -- OB Maps + "info_player_red", + "info_player_blue", - -- INS Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "ins_spawnpoint" ) ) + -- SYN Maps + "info_player_coop", - -- AOC Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "aoc_spawnpoint" ) ) + -- ZPS Maps + "info_player_human", + "info_player_zombie", - -- Dystopia Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "dys_spawn_point" ) ) + -- ZM Maps + "info_player_zombiemaster", - -- PVKII Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_pirate" ) ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_viking" ) ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_knight" ) ) + -- FOF Maps + "info_player_fof", + "info_player_desperado", + "info_player_vigilante", - -- DIPRIP Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "diprip_start_team_blue" ) ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "diprip_start_team_red" ) ) + -- L4D Maps + "info_survivor_rescue", + --"info_survivor_position", -- Removing this one for the time being, c1m4_atrium has one of these in a box under the map - -- OB Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_red" ) ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_blue" ) ) + -- NEOTOKYO Maps + "info_player_attacker", + "info_player_defender", - -- SYN Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_coop" ) ) + -- Fortress Forever Maps + "info_ff_teamspawn" +} +function GM:PlayerSelectSpawn( pl, transiton ) - -- ZPS Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_human" ) ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_zombie" ) ) + -- If we are in transition, do not reset player's position + if ( transiton ) then return end - -- ZM Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_zombiemaster" ) ) + if ( self.TeamBased ) then - -- FOF Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_fof" ) ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_desperado" ) ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_vigilante" ) ) + local ent = self:PlayerSelectTeamSpawn( pl:Team(), pl ) + if ( IsValid( ent ) ) then return ent end - -- L4D Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_survivor_rescue" ) ) - -- Removing this one for the time being, c1m4_atrium has one of these in a box under the map - --self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_survivor_position" ) ) + end - -- NEOTOKYO Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_attacker" ) ) - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_defender" ) ) + -- Save information about all of the spawn points + -- in a team based game you'd split up the spawns + if ( !IsTableOfEntitiesValid( self.SpawnPoints ) ) then - -- Fortress Forever Maps - self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_ff_teamspawn" ) ) + self.LastSpawnPoint = 0 + self.SpawnPoints = ents.FindByClasses( self.SpawnPointClasses ) end diff --git a/garrysmod/lua/includes/extensions/ents.lua b/garrysmod/lua/includes/extensions/ents.lua index afa3563181..9b9284ef3e 100644 --- a/garrysmod/lua/includes/extensions/ents.lua +++ b/garrysmod/lua/includes/extensions/ents.lua @@ -20,6 +20,25 @@ function ents.FindByClassAndParent( classname, entity ) end +function ents.FindByClasses( classes ) + + local classHash = {} + + for _, class in ipairs( classes ) do + classHash[class] = true + end + + local found = {} + + for _, ent in ipairs( ents.GetAll() ) do + if ( classHash[ent:GetClass()] ) then + table.insert( found, ent ) + end + end + + return found +end + local inext = ipairs( {} ) local EntityCache = nil