Spawn points in GMod maps: entities for Sandbox, DarkRP and TTT
Which spawn points a GMod map needs for Sandbox, DarkRP and TTT, how GMod picks a spawn and what happens when spawns are missing or too few.
For Sandbox and DarkRP a map needs several info_player_start entities, for TTT info_player_deathmatch, in each case at least as many as players can spawn at the same time. DarkRP's job spawns and jail positions are not part of the map. Admins set them in game and the server stores them in its database. If there are no spawn entities at all, players usually end up at the map origin. If there are too few, the spawn logic kills players who are standing on a spawn.
How GMod picks a spawn point
The selection is written in Lua, in the function GM:PlayerSelectSpawn of the base gamemode (gamemodes/base/gamemode/player.lua). Sandbox uses it unchanged, DarkRP calls it and adds to it, TTT replaces it with its own. On the first spawn the function collects all entities of these classes:
info_player_startandgmod_player_startinfo_player_deathmatchinfo_player_combineandinfo_player_rebelfrom Half-Life 2: Deathmatchinfo_player_terroristandinfo_player_counterterroristfrom Counter-Strike: Sourceinfo_player_teamspawnfrom Team Fortress 2- further classes from other Source games, such as
info_player_alliesandinfo_player_axis
In a gamemode without teams they are all equal. That is why the spawns of maps from other games work in Sandbox without changes. In Hammer, GMod's own FGD only knows info_player_start. info_player_deathmatch comes with the ttt.fgd in the folder gamemodes/terrortown.
After that the selection works like this:
- If at least one spawn has the "Master" flag (spawnflag 1), GMod always takes the first spawn with that flag and skips the random draw.
- Otherwise the function draws a random spawn, as many times as there are spawns. A spawn outside the world is skipped. So are the spawn that was used last and the one this player used last, as long as the map has more than one spawn.
- For each candidate,
GM:IsSpawnpointSuitablechecks whether a living player is standing in a box of 32 × 32 × 64 units at the spawn. If the box is free, the player spawns there. - The last attempt is forced. Every player standing in the box is killed.
The player takes the view direction from the angles of the entity.
How many spawns a map needs
The rules for mappers follow from that:
- At least as many spawns as slots, preferably more. The function draws with repetition and does not try every spawn exactly once. The more free spawns there are, the less often it reaches the forced last attempt.
- A single spawn is the worst case. The first attempt is then also the last. Whoever stands on the spawn dies as soon as another player spawns.
- Keep your distance. The check box is 32 units wide. If two spawns are closer together, a player on one of them also blocks the other.
- No Master flag on multiplayer maps. The flag is meant for single-player maps. If it is set, everyone spawns at that point, and whoever stands there is killed every time.
- Place it in free space. The model Hammer shows for
info_player_startis roughly player sized, so you can see whether a player fits.
If the last attempt lands on the most recently used spawn, the check is skipped and the function returns it anyway. If a player is still standing there, the two end up inside each other.
If there is no spawn entity at all, the base gamemode prints [PlayerSelectSpawn] Error! No spawn points! to the console and returns no spawn. According to the Valve Developer Community wiki, Source games then usually put the player at the map origin (0 0 0). For a BSP, the Map Scanner checks whether a spawnpoint is present.
Sandbox, DarkRP and TTT compared
| Gamemode | Spawn entity in the map | Also required | If it is missing |
|---|---|---|---|
| Sandbox | info_player_start | nothing | usually a spawn at the origin, deaths at the spawn if there are too few |
| DarkRP | info_player_start | jail positions, optionally job spawns, both set in game | no arrests without a jail position |
| TTT | info_player_deathmatch | weapon and ammo entities | error No spawn entity found!, makeshift spawns if there are too few |
DarkRP is based on Sandbox and first calls the selection of the base gamemode. So the map needs ordinary spawn entities. After that DarkRP only replaces the position:
/setspawn <job>replaces all spawns of a job with your location,/addspawn <job>adds one,/removespawn <job>deletes them.<job>is the command name of the job, for examplecp. They are reserved for admins./jailposreplaces all jail positions with your location,/addjailposadds another one. An admin may do this and, as long asGM.Config.chiefjailposis enabled, so may the police chief.
DarkRP stores these positions in the server database under the name of the map. If the BSP gets a new file name, DarkRP no longer finds them. Without a jail position DarkRP refuses arrests with You cannot arrest people since there are no jail positions set!. Before placing the player, DarkRP looks for a free spot around the target, up to 600 units away. The kill logic of the base gamemode still runs before that, because the spawn entity is chosen first. A DarkRP map therefore needs enough info_player_start entities as well. What else it should offer is covered in choosing a DarkRP map and in the overview of roleplay map types.
TTT collects info_player_deathmatch and the team spawns of other games. It only uses info_player_start when nothing else exists, and the TTT documentation advises against it. If the spawns are not enough, TTT creates makeshift spawns 36 units next to existing ones and reports TTT WARNING: Map has too few spawn points. Leave room around every spawn: TTT only checks that the spot lies inside the world and that no player is standing there. Above a drop the player spawns in mid-air. Weapons get into the map through ttt_random_weapon, ttt_random_ammo or fixed weapon classes. Everything else is in building TTT maps.
Entities in garrysmod.fgd that are often overlooked
| Entity | Purpose | Note |
|---|---|---|
lua_run | runs Lua code (keyvalue Code, inputs RunCode and RunPassedCode) | the Map Scanner reports it as a risky entity |
env_skypaint | controls the colours of the sky | requires the skybox material painted in the Map Properties |
func_nav_blocker, func_nav_avoid, func_nav_prefer | blocks nav mesh areas or weights them | only affects bots that use the nav mesh, see navmesh and AI nodes |
trigger_catapult | launches players and physics objects | speed set separately through playerSpeed and physicsSpeed |
beam_spotlight | spotlight with a visible beam | entirely client side, not synced between clients |
What server owners can change without a recompile
If a map you bought lacks spawns, that can be solved on the server. In DarkRP the chat commands above are enough. TTT loads a rearm script maps/<mapname>_ttt.txt that replaces weapons and, with the setting replacespawns, the spawns too, as long as ttt_use_weapon_spawn_scripts is enabled. For all other cases you create additional spawn entities in Lua. Read the coordinates in game with getpos. The command reports the position of your eyes, so for a standing player subtract 64 units from the Z value. The file belongs in lua/autorun/server/:
hook.Add( "InitPostEntity", "extra_spawns", function()
local spawn = ents.Create( "info_player_start" )
if ( not IsValid( spawn ) ) then return end
spawn:SetPos( Vector( 512, -128, 64 ) )
spawn:SetAngles( Angle( 0, 90, 0 ) )
spawn:Spawn()
end )
The limits of this approach:
- The base gamemode remembers the spawn list after the first spawn. New entities have to exist before that, hence
InitPostEntity. game.CleanUpMapremoves most entities and only restores those of the map. So you create Lua spawns again in thePostCleanupMaphook.- The coordinates apply to exactly one version of the map. After an update you check every position.
- Lua does not change geometry. A tight spawn room stays tight.
FAQ
Can a map use the same spawns for Sandbox, DarkRP and TTT?
Yes, with info_player_deathmatch. The base gamemode accepts the class just like info_player_start, and the TTT documentation names it as the usual spawn entity. If you mix both classes, Sandbox and DarkRP use all spawns, TTT only the info_player_deathmatch ones.
Why do players die at the spawn without anyone shooting?
That is the forced last attempt of the spawn selection: GMod kills the player who is in the way. More spawns with more distance between them fix it.
Do DarkRP spawns still apply after a map update?
Only if the file name stays the same, because the positions are tied to the name of the map. Even then you have to check them, because rooms may have moved.