Garry's Mod Wiki

GM:PlayerNoClip

boolean GM:PlayerNoClip( Player ply, boolean desiredState )
This hook is predicted. This means that in singleplayer, it will not be called in the Client realm.

Description

Called when a player tries to switch noclip mode.

Arguments

1 Player ply
The person who entered/exited noclip
2 boolean desiredState
Represents the noclip state (on/off) the user will enter if this hook allows them to.

Returns

1 boolean
Return false to disallow the switch.

Example

Disable Noclip for all but admins.

local function DisableNoclip( ply ) return ply:IsAdmin() end hook.Add( "PlayerNoClip", "DisableNoclip", DisableNoclip )

Example

Get the player when they enter/exit no clip and display their status

hook.Add( "PlayerNoClip", "isInNoClip", function( ply, desiredNoClipState ) if ( desiredNoClipState ) then print( ply:Name() .. " wants to enter noclip." ) else print( ply:Name() .. " wants to leave noclip." ) end end )
Output: Player [1][Player1] true Player [1][Player2] false

Example

While keeping the default behaviour of admin-only noclip, the following example will also allow anyone to turn it off (if it's set on by a third-party administration addon, for example).

hook.Add( "PlayerNoClip", "FeelFreeToTurnItOff", function( ply, desiredState ) if ( desiredState == false ) then -- the player wants to turn noclip off return true -- always allow elseif ( ply:IsAdmin() ) then return true -- allow administrators to enter noclip end end )

Page Links


Special Pages


Wikis

?

Render Time: 34ms

DB GetPage 3
Generate Html 7
SaveChanges (1) 9
Render Body 0
Render Sidebar 12