Gamemode.IsSpawnpointSuitable

From GMod Wiki

Jump to: navigation, search
Event Hook
Hook NameIsSpawnpointSuitable
SyntaxGM:IsSpawnpointSuitable( Player player, Entity spawnpointent, Boolean bMakeSuitable )
DescriptionDetermine whether a spawn-point is suitable or obstructed
ReturnsBoolean
Lua StateNewerServer.png
BBCode[b][url=wiki.garrysmod.com/?title=Gamemode.IsSpawnpointSuitable]Gamemode.IsSpawnpointSuitable [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionPrints "Hello, world!" if a randomly chosen info_player_start is suitable for spawning
Used onNewerServer.png
Code
 
    local SpawnEnts = ents.FindByClass("info_player_start")
    local RandomSpawn = math.random(#SpawnEnts)
    if (GAMEMODE:IsSpawnpointSuitable( pl, SpawnEnts[RandomSpawn], false)) then
        print("Hello, world!")
    end
 
OutputN/A


DescriptionFunction that finds a random suitable info_player_start, or makes a spawn suitable if it reaches the last iteration of the for loop
Used onNewerServer.png
Code
 
function GM:FindSuitableSpawn()
    local SpawnEnts = ents.FindByClass("info_player_start")
    for i=0, 6 do
        local RandomSpawn = math.random(#SpawnEnts)
        if (self:IsSpawnpointSuitable( pl, SpawnEnts[RandomSpawn], i==6)) then
            return SpawnEnts[RandomSpawn]
        end
    end
    return SpawnEnts[RandomSpawn]
end
OutputEntity info_player_start


Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox