Garry's Mod Wiki

Revision Difference

Vehicle:IsValidVehicle#564996

<function name="IsValidVehicle" parent="Vehicle" type="classfunc"> <description>Returns true if the vehicle object is a valid or not. This will return `false` when <page>Vehicle</page> functions are not usable on the vehicle.</description>⤶ <description>⤶ Determines whether a given <page>Vehicle</page> is in a valid Vehicle state.⤶ ⤶ It is possible, in uncommon circumstances, for a Vehicle to return `true` to <page>Global.IsValid</page> and to <page>Entity:IsVehicle</page> while being in an invalid Vehicle state. ⤶ This function exists to detect that situation.⤶ </description>⤶ <realm>Shared</realm> <rets> <ret name="" type="boolean">Is the vehicle a valid vehicle or not</ret>⤶ <ret name="" type="boolean">⤶ `true` if the Vehicle is in a valid state, or `false` if the Vehicle is in an invalid state.⤶ </ret>⤶ </rets> </function> ⤶ <example>⤶ <description>⤶ Below is an example demonstrating a way that a Vehicle can return `true` to <page>Global.IsValid</page> and <page>Entity:IsVehicle</page> but still be in an invalid Vehicle state.⤶ </description>⤶ <code>⤶ ⤶ -- 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 )⤶ </code> ⤶ </example>⤶