Revision Difference
GM:PlayerNoClip#528438
<function name="PlayerNoClip" parent="GM" type="hook">
<ishook>yes</ishook>
<description>Called when a player tries to switch noclip mode.</description>
<realm>Shared</realm>
<predicted>Yes</predicted>
<args>
<arg name="ply" type="Player">The person who entered/exited noclip</arg>
<arg name="desiredState" type="boolean">Represents the noclip state (on/off) the user will enter if this hook allows them to.</arg>
</args>
<rets>
<ret name="" type="boolean">Return false to disallow the switch.</ret>
</rets>
</function>
<example>
<description>Disable Noclip for all but admins.</description>⤶
<code>⤶
local function DisableNoclip( ply )⤶
return ply:IsAdmin()⤶
end⤶
hook.Add( "PlayerNoClip", "DisableNoclip", DisableNoclip )⤶
</code>⤶
⤶
</example>⤶
⤶
⤶
<example>⤶
<description>Get the player when they enter/exit no clip and display their status</description>
<code>
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 )
</code>
<outputfixedwidth>Fixed width</outputfixedwidth>⤶
<output>
```⤶
Player [1][Player1] true
Player [1][Player2] false
```⤶
</output>
</example>
⤶
⤶
<example>⤶
<description>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).</description>⤶
⤶
<example>⤶
<description>While keeping the default behavior 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).</description>⤶
<code>
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 )
</code>
</example>