Garry's Mod Wiki

Entity:DeleteOnRemove

  Entity:DeleteOnRemove( Entity entityToRemove )

Description

Whenever the entity is removed, entityToRemove will be removed also.

Arguments

1 Entity entityToRemove
The entity to be removed

Example

Creates a second chair in spawned jeeps that is removed when the jeep is removed

hook.Add("PlayerSpawnedVehicle", "VehicleUpgrade", function(ply,vehicle) if vehicle:GetClass() == "prop_vehicle_jeep" then local seat = ents.Create( 'prop_vehicle_prisoner_pod' ) seat:SetModel( "models/nova/jeep_seat.mdl" ) seat:SetPos( vehicle:LocalToWorld(Vector(21,-32,18)) ) seat:SetAngles( vehicle:LocalToWorldAngles(Angle(0,-3.5,0)) ) seat:Spawn() seat:SetKeyValue( "limitview", 0 ) table.Merge( seat, { HandleAnimation = function(_,ply) return ply:SelectWeightedSequence( ACT_HL2MP_SIT ) end } ) gamemode.Call( "PlayerSpawnedVehicle", ply, seat ) vehicle.PassengerSeat = seat vehicle:DeleteOnRemove(seat) //<-- constraint.Weld(seat, vehicle) end end)