Garry's Mod Wiki

GM:EntityKeyValue

  string GM:EntityKeyValue( Entity ent, string key, string value )

Description

Called when a key-value pair is set on an entity, either by the engine (for example when map spawns) or Entity:SetKeyValue.

See ENTITY:KeyValue for a hook that works for scripted entities.

See WEAPON:KeyValue for a hook that works for scripted weapons.

Arguments

1 Entity ent
Entity that the keyvalue is being set on
2 string key
Key of the key/value pair
3 string value
Value of the key/value pair

Returns

1 string
If set, the value of the key-value pair will be overridden by this string.

Example

Remove infodecal entities similar to the blue graffiti text behind the big building with numbered floors on gm_construct.
The texture keyvalue cannot be retrieved from infodecal entities.

local unwantedDecals = { ["decals/decalgraffiti031a"] = true, -- etc. } hook.Add( "EntityKeyValue", "remove_unwanted_decals", function( ent, key, value ) if ( key == "texture" and IsValid( ent ) and ent:GetClass() == "infodecal" ) then if ( unwantedDecals[value] ) then -- set a targetname to make the decal remain and not appear automatically: ent:SetName( "remove_unwanted_decals" ) end end end ) local function remove_unwanted_decals() -- remove the decals instead of just keeping them invisible: for _, decal in ipairs( ents.FindByClass( "infodecal" ) ) do if ( decal:GetName() == "remove_unwanted_decals" ) then decal:Remove() end end end hook.Add( "InitPostEntity", "remove_unwanted_decals", remove_unwanted_decals ) hook.Add( "PostCleanupMap", "remove_unwanted_decals", remove_unwanted_decals )