Entity.CallOnRemove

From GMod Wiki

Jump to: navigation, search
Function
Syntax Entity:CallOnRemove( String name, Function removeFunc, Var argument, ... )
Description:
Whenever the entity is removed by any means, this function will be called.
Returns: nil
In Object: Entity
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Entity.CallOnRemove]Entity.CallOnRemove [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionEach time a prop is removed it screams.
Used onNewerServer.png
Code
local function OhNo(prop,n) -- The first argument is the entity, the rest is the arguments
    local sound
    if n <10 then
        sound = "vo/npc/male01/pain0"..n..".wav"
    else
        n = n-9
        sound = "vo/npc/male01/ow0"..n..".wav"
    end
    prop:EmitSound(sound,100,170) -- Emitting the sound with a high pitch because it's funnier!
end
 
local LastSound
hook.Add("OnEntityCreated","ScreamingProps", function( prop )
    if ( prop:GetClass() == "prop_physics" ) then --If it's a prop then...
 
    local n
 
    n = math.random(1,11)
    while n == LastSound do
        n = math.random(1,11)   --Select a random sound
    end
 
    LastSound = n   
 
    prop:CallOnRemove("ScreamingProps",OhNo,n) --Call the OhNo function with the sound as an argument when removed
    end
end)
 
OutputOw!


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox