NetVehicle
This is the client-side class for NetVehicle.
Class Instance Methods
Inherited methods from NetObject
NetObject:SetData(key: string, value: any): boolean
Sets generic data on the object on the client. Value must be a number, string, bool, vec2, vec3, vec4, or quat. Returns true if the data was set successfully, false otherwise (for unsupported types).
Parameters:
key: string
- The key to store the data undervalue: any
- The value to store (must be a supported type)
Returns: boolean - true if the data was set successfully, false otherwise
Example:
local success = object:SetData("clientValue", 42)
if success then
print("Client data set successfully")
else
print("Failed to set client data")
end
NetObject:GetPosition(): vec3
Returns the position of the object.
Returns: vec3 - The position of the object
Example:
local position = object:GetPosition()
print("Object position: " .. tostring(position))
NetObject:GetRotation(): quat
Returns the rotation of the object.
Returns: quat - The rotation of the object
Example:
local rotation = object:GetRotation()
print("Object rotation: " .. tostring(rotation))
NetObject:GetEulerRotation(): vec3
Returns the Euler rotation of the object.
Returns: vec3 - Euler rotation
Example:
local eulerRotation = object:GetEulerRotation()
print("Object euler rotation: " .. tostring(eulerRotation))
NetObject:GetHealth(): number
Returns the current health of the object.
Returns: number - The current health of the object
Example:
local health = object:GetHealth()
print("Object health: " .. health)
NetObject:GetMaxHealth(): number
Returns the maximum health of the object.
Returns: number - The maximum health of the object
Example:
local maxHealth = object:GetMaxHealth()
print("Object max health: " .. maxHealth)
NetObject:GetVelocity(): vec3
Returns the velocity of the object.
Returns: vec3 - The velocity of the object
Example:
local velocity = object:GetVelocity()
print("Object velocity: " .. tostring(velocity))
NetObject:GetAngularVelocity(): vec3
Returns the angular velocity of the object.
Returns: vec3 - The angular velocity of the object
NetObject:GetNetId(): number
Returns the network ID of the object.
Returns: number - The network ID of the object
Example:
local netId = object:GetNetId()
print("Object network ID: " .. netId)
NetObject:GetData(key: string): any
Gets generic data from the object.
Parameters:
key: string
- The key of the data to retrieve
Returns: any - The stored data value
Example:
local value = object:GetData("customValue")
print("Retrieved value: " .. tostring(value))
NetObject:AsPlayer(): NetPlayer | nil
Returns a NetPlayer instance if the object is a player, otherwise returns nil. This is a safe way to cast a NetObject to a NetPlayer.
Returns: NetPlayer instance if the object is a player, nil otherwise
Example:
-- Safe casting to NetPlayer
local netObject = someNetObject -- Assume this is a NetObject instance
local player = netObject:AsPlayer()
if player then
print("This is a player: " .. player:GetNick())
else
print("This is not a player")
end
NetObject:AsVehicle(): NetVehicle | nil
Returns a NetVehicle instance if the object is a vehicle, otherwise returns nil. This is a safe way to cast a NetObject to a NetVehicle.
Returns: NetVehicle instance if the object is a vehicle, nil otherwise
Example:
-- Safe casting to NetVehicle
local netObject = someNetObject -- Assume this is a NetObject instance
local vehicle = netObject:AsVehicle()
if vehicle then
print("This is a vehicle at position: " .. tostring(vehicle:GetPosition()))
else
print("This is not a vehicle")
end
NetObject:AsMountedGun(): NetMountedGun | nil
Returns a NetMountedGun instance if the object is a mounted gun, otherwise returns nil. This is a safe way to cast a NetObject to a NetMountedGun.
Returns: NetMountedGun instance if the object is a mounted gun, nil otherwise
Example:
-- Safe casting to NetMountedGun
local netObject = someNetObject -- Assume this is a NetObject instance
local mountedGun = netObject:AsMountedGun()
if mountedGun then
print("This is a mounted gun with health: " .. mountedGun:GetHealth())
else
print("This is not a mounted gun")
end
NetObject:AsRigidObject(): NetRigidObject | nil
Returns a NetRigidObject instance if the object is a rigid object, otherwise returns nil. This is a safe way to cast a NetObject to a NetRigidObject.
Returns: NetRigidObject instance if the object is a rigid object, nil otherwise
Example:
-- Safe casting to NetRigidObject
local netObject = someNetObject -- Assume this is a NetObject instance
local rigidObject = netObject:AsRigidObject()
if rigidObject then
print("This is a rigid object with velocity: " .. tostring(rigidObject:GetVelocity()))
else
print("This is not a rigid object")
end
NetObject:AsNPC(): NetNPC | nil
Returns a NetNPC instance if the object is an NPC, otherwise returns nil. This is a safe way to cast a NetObject to a NetNPC.
Returns: NetNPC instance if the object is an NPC, nil otherwise
Example:
-- Safe casting to NetNPC
local netObject = someNetObject -- Assume this is a NetObject instance
local npc = netObject:AsNPC()
if npc then
print("This is an NPC with ID: " .. npc:GetId())
else
print("This is not an NPC")
end
NetObject:AsTether(): NetTether | nil
Returns a NetTether instance if the object is a tether, otherwise returns nil. This is a safe way to cast a NetObject to a NetTether.
Returns: NetTether instance if the object is a tether, nil otherwise
Example:
-- Safe casting to NetTether
local netObject = someNetObject -- Assume this is a NetObject instance
local tether = netObject:AsTether()
if tether then
print("This is a tether")
else
print("This is not a tether")
end
NetObject:GetType(): NetObjectType
Returns the network object type. Use the NetObjectType
enum to compare types.
Returns: The type of the network object as a NetObjectType enum value
Example:
-- Check object type
local netObject = someNetObject -- Assume this is a NetObject instance
local objectType = netObject:GetType()
if objectType == NetObjectType.Player then
print("This is a player object")
elseif objectType == NetObjectType.Vehicle then
print("This is a vehicle object")
end
NetVehicle:GetId(): number
Returns the ID of the vehicle.
Returns: number - The unique ID of the vehicle
Example:
local vehicleId = vehicle:GetId()
print("Vehicle ID: " .. vehicleId)
NetVehicle:GetVelocity(): vec3
Gets the vector3 velocity of the vehicle.
Returns: vec3 - The velocity vector of the vehicle
Example:
local velocity = vehicle:GetVelocity()
print("Vehicle velocity: " .. tostring(velocity))
NetVehicle:IsWheelDrifting(wheel: number, threshold: number): boolean
Returns true if the specified wheel is currently drifting, false otherwise. Wheel is the index of the wheel to check, and threshold is the threshold where it returns true. Threshold should be a value between 0 and 1 where a low value will detect drifting more easily.
Parameters:
wheel: number
- The index of the wheel to check (0-based)threshold: number
- The threshold for detecting drift (0-1)
Returns: boolean - true if the wheel is drifting, false otherwise
Example:
local isDrifting = vehicle:IsWheelDrifting(0, 0.5)
if isDrifting then
print("Front wheel is drifting!")
end
NetVehicle:GetNumberOfWheelsOnGround(): number
Returns the number of wheels of the vehicle that are currently touching the ground.
Returns: number - The number of wheels on the ground
Example:
local wheelsOnGround = vehicle:GetNumberOfWheelsOnGround()
print("Wheels on ground: " .. wheelsOnGround)
NetVehicle:SetCloak(enabled: bool): void
Enables or disables cloaked mode. When cloaked mode is enabled, the vehicle will become mostly invisible with a shine on them.
Parameters:
enabled: bool
- Whether to enable or disable cloaked mode
Example:
-- Enable cloaked mode
vehicle:SetCloak(true)
-- Disable cloaked mode
vehicle:SetCloak(false)
NetVehicle:IsCloaked(): boolean
Returns true if the vehicle is currently cloaked, false otherwise.
Returns: boolean - true if the vehicle is cloaked, false otherwise
NetVehicle:GetDirt(): float
Returns the current dirt level of the vehicle as a float value.
Returns: float - The dirt level of the vehicle
NetVehicle:GetPrimaryColor(): vec3
Returns the primary color of the vehicle as a vec3 RGB value.
Returns: vec3 - The primary RGB color of the vehicle
NetVehicle:GetSecondaryColor(): vec3
Returns the secondary color of the vehicle as a vec3 RGB value.
Returns: vec3 - The secondary RGB color of the vehicle
NetVehicle:GetTertiaryColor(): vec3
Returns the tertiary color of the vehicle as a vec3 RGB value.
Returns: vec3 - The tertiary RGB color of the vehicle
NetVehicle:GetSpecularGloss(): float
Returns the specular gloss value of the vehicle's material.
Returns: float - The specular gloss value of the vehicle
NetVehicle:GetClearCoat(): float
Returns the clear coat value of the vehicle's material.
Returns: float - The clear coat value of the vehicle
NetVehicle:GetMetallic(): float
Returns the metallic value of the vehicle's material.
Returns: float - The metallic value of the vehicle
NetVehicle:GetPartState(part: VehiclePart): VehiclePartState
Returns the current state of the specified vehicle part.
Parameters:
part: VehiclePart
- The part to get the state of
Returns: VehiclePartState - The state of the vehicle part
NetVehicle:SetPartState(part: VehiclePart, state: VehiclePartState): void
Transitions a vehicle part to the specified state with animation. Only VehiclePartState.Open and VehiclePartState.Closed states are supported. Use VehiclePartState.Open to animate the part opening, and VehiclePartState.Closed to animate the part closing. The state change is not instant - the part will transition smoothly over time.
Parameters:
part: VehiclePart
- The vehicle part to controlstate: VehiclePartState
- The state to transition to
Example:
-- Open a vehicle door
vehicle:SetPartState(VehiclePart.DoorFrontLeft, VehiclePartState.Open)
-- Close a vehicle door
vehicle:SetPartState(VehiclePart.DoorFrontLeft, VehiclePartState.Closed)
NetVehicle:UseLight(lightIndex: number, use: boolean): void
Controls whether a specific vehicle light is enabled or disabled. This function MUST be used inside the OnVehicleRender event.
Parameters:
lightIndex: number
- The index of the light to controluse: boolean
- Whether to enable (true) or disable (false) the light
Example:
Event.Add("OnVehicleRender", function(vehicle)
-- Enable the first light
vehicle:UseLight(0, true)
-- Disable the second light
vehicle:UseLight(1, false)
end)
NetVehicle:GetAABB(): AABB
Returns the AABB (bounding box) of the vehicle.
Returns: AABB - The AABB of the vehicle. This is a table containing two fields: min
and max
, both of which are vec3
Example:
local aabb = vehicle:GetAABB()
print("Vehicle AABB: " .. tostring(aabb.min) .. " " .. tostring(aabb.max))
NetVehicle:GetLocalAABB(): AABB
Returns the local AABB (bounding box) of the vehicle.
Returns: AABB - The local AABB of the vehicle. This is a table containing two fields: min
and max
, both of which are vec3
Example:
local localAABB = vehicle:GetLocalAABB()
print("Vehicle local AABB: " .. tostring(localAABB.min) .. " " .. tostring(localAABB.max))
NetVehicle:GetTrailingVehicle(): NetVehicle
Returns the trailing vehicle (trailers etc).
Returns: NetVehicle - The trailing vehicle
NetVehicle:GetType(): VehicleType
Returns the type of the vehicle.
Returns: VehicleType - The type of the vehicle
NetVehicle:IsInAir(): boolean
Returns true if the vehicle is in the air, false otherwise.
Returns: boolean
- true if the vehicle is in the air, false otherwise
NetVehicle:IsHornPlaying(): boolean
Returns true if the vehicle's horn is playing, false otherwise.
Returns: boolean
- true if the horn is playing, false otherwise