Garry's Mod Wiki

GM:CanEditVariable

  boolean GM:CanEditVariable( Entity ent, Player ply, string key, string value, table editor )

Description

Called when a variable is about to be edited on an Entity (called by Edit Properties... menu), to determine if the edit should be permitted.

See Editable entities for more details about the system.

By default, Sandbox will also call ENTITY:CanEditVariables if no hook returns a value.

Arguments

1 Entity ent
The entity being edited.
2 Player ply
The player doing the editing.
3 string key
The name of the variable.
4 string value
The new value, as a string which will later be converted to its appropriate type.
5 table editor
The edit table defined in Entity:NetworkVar.

Returns

1 boolean
Return false to disallow editing.

Example

From base/gamemode/variable_edit.lua.

Makes Edit Properties... right click property admin only.

hook.Add( "CanEditVariable", "AdminEditVar", function( ent, ply, key, val, editor ) if ( !ply:IsAdmin() ) then return false end -- Do not return anything when allowed, to allow other hooks to run and potentially block the edit end )