Garry's Mod Wiki

Revision Difference

GM:IsSpawnpointSuitable#527807

<function name="IsSpawnpointSuitable" parent="GM" type="hook"> <ishook>yes</ishook> <description>Check if a player can spawn at a certain spawnpoint.</description> <realm>Server</realm> <predicted>No</predicted> <args> <arg name="ply" type="Player">The player who is spawned</arg> <arg name="spawnpoint" type="Entity">The spawnpoint entity (on the map)</arg> <arg name="makeSuitable" type="boolean">If this is true, it'll kill any players blocking the spawnpoint</arg>⤶ <arg name="spawnpoint" type="Entity">The spawnpoint entity (on the map).</arg> <arg name="makeSuitable" type="boolean">If this is true, it'll kill any players blocking the spawnpoint.</arg>⤶ </args> <rets> <ret name="" type="boolean">Return true to indicate that the spawnpoint is suitable (Allow for the player to spawn here), false to prevent spawning</ret>⤶ <ret name="" type="boolean">Return true to indicate that the spawnpoint is suitable (Allow for the player to spawn here), false to prevent spawning.</ret>⤶ </rets> </function> <example> <description>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.</description> <code> function GM:IsSpawnpointSuitable( ply, spawnpointent, bMakeSuitable ) local Pos = spawnpointent:GetPos() 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⤶ -- 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 k, v in pairs( Ents ) do if ( IsValid( v ) && v:GetClass() == "player" && v:Alive() ) then Blockers = Blockers + 1 for _, v in ipairs( Ents ) do if ( v:IsPlayer() and v:Alive() ) then Blockers = Blockers + 1 if ( bMakeSuitable ) then v:Kill() end end end end if ( bMakeSuitable ) then return true end if ( Blockers > 0 ) then return false end return true ⤶ end⤶ return true end⤶ </code> <output>true or false</output> ⤶ </example></example>