Revision Difference
GM:EntityKeyValue#553110
<function name="EntityKeyValue" parent="GM" type="hook">
<ishook>yes</ishook>⤶
<description>
Called when a key-value pair is set on an entity, either by the engine (for example when map spawns) or <page>Entity:SetKeyValue</page>.
See <page>ENTITY:KeyValue</page> for a hook that works for scripted entities.
See <page>WEAPON:KeyValue</page> for a hook that works for scripted weapons.
</description>
<realm>Shared</realm>
<predicted>No</predicted>⤶
<args>
<arg name="ent" type="Entity">Entity that the keyvalue is being set on</arg>
<arg name="key" type="string">Key of the key/value pair</arg>
<arg name="value" type="string">Value of the key/value pair</arg>
</args>
<rets>
<ret name="" type="string">If set, the value of the key-value pair will be overridden by this string.</ret>
</rets>
</function>
<example>
<description>Remove [`infodecal`](https://developer.valvesoftware.com/wiki/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.</description>
<code>
local unwantedDecals = {
["decals/decalgraffiti031a"] = true,
-- etc.
}
hook.Add( "EntityKeyValue", "remove_unwanted_decals", function( decal, key, value )
if key == "texture" and IsValid( decal ) and decal:GetClass() == "infodecal" then
if unwantedDecals[value] then
-- set a targetname to make the decal remain and not appear automatically:
decal: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 )
</code>
</example>