GM:EntityKeyValue
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
Returns
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( 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 )