Garry's Mod Wiki

Entity:CallOnRemove

  Entity:CallOnRemove( string identifier, function removeFunc, ... )

Description

Causes a specified function to be run if the entity is removed by any means. This can later be undone by Entity:RemoveCallOnRemove if you need it to not run.

This hook is called clientside during full updates. See GM:EntityRemoved for more information.

Arguments

1 string identifier
Identifier that can be optionally used with Entity:RemoveCallOnRemove to undo this call on remove.
2 function removeFunc
Function to be called on remove.
Function argument(s):
1 Entity ent - The entity about to be removed.
2 vararg data - Data passed from the arguments to CallOnRemove.
3 vararg args
Optional arguments to pass to removeFunc. Do note that the first argument passed to the function will always be the entity being removed, and the arguments passed on here start after that.

Example

Stops an engine sound when the entity is removed

Entity:CallOnRemove( "StopEngineSound", function( ent ) ent:StopSound( "enginenoise.wav" ) end )