Garry's Mod Wiki

GM:IsSpawnpointSuitable

  boolean GM:IsSpawnpointSuitable( Player ply, Entity spawnpoint, boolean makeSuitable )

Description

Check if a player can spawn at a certain spawnpoint.

Arguments

1 Player ply
The player who is spawned
2 Entity spawnpoint
The spawnpoint entity (on the map).
3 boolean makeSuitable
If this is true, it'll kill any players blocking the spawnpoint.

Returns

1 boolean
Return true to indicate that the spawnpoint is suitable (Allow for the player to spawn here), false to prevent spawning.

Example

This will check if anyone is blocking the spawnpoint. If someone is, then it'll, depending on the bMakeSuitable value, kill the player, or return false.

hook.Add( "IsSpawnpointSuitable", "CheckSpawnPoint", function( ply, spawnpointent, bMakeSuitable ) local Pos = spawnpointent:GetPos() -- Note that we're searching the default hull size here for a player in the way of our spawning. -- This seems pretty rough, seeing as our player's hull could be different.. but it should do the job. -- (HL2DM kills everything within a 128 unit radius) local Ents = ents.FindInBox( Pos + Vector( -16, -16, 0 ), Pos + Vector( 16, 16, 72 ) ) if ( ply:Team() == TEAM_SPECTATOR or ply:Team() == TEAM_UNASSIGNED ) then return true end local Blockers = 0 for _, v in ipairs( Ents ) do if ( v:IsPlayer() and v:Alive() ) then Blockers = Blockers + 1 if ( bMakeSuitable ) then v:Kill() end end end if ( bMakeSuitable ) then return true end if ( Blockers > 0 ) then return false end return true end )
Output: true or false