Garry's Mod Wiki

Vehicle:IsValidVehicle

  boolean Vehicle:IsValidVehicle()

Description

Determines whether a given Vehicle is fully initialized.

It is possible, in uncommon circumstances, for a valid vehicle entity to be in an invalid state, such as before Entity:Spawn is called on the vehicle after creation.

If this function returns false, then the Vehicle functions are not usable on this vehicle, while Entity functions are.

Returns

1 boolean
true if the Vehicle is in a valid state, or false if the Vehicle is in an invalid state.

Example

Below is an example demonstrating a way that a Vehicle can return true to IsValid and Entity:IsVehicle but still be in an invalid Vehicle state.

-- Create a new jeep, but leave it in an unfinished state local jeep = ents.Create( "prop_vehicle_jeep" ) print( IsValid( jeep ) ) -- Prints "true" print( jeep:IsVehicle() ) -- Prints "true" print( jeep:IsValidVehicle() ) -- Prints "false" timer.Simple( 1, function() -- Finalize the jeep's creation and put it into a valid Vehicle state jeep:Spawn() print( jeep:IsValidVehicle() ) -- Prints "true" end )