IsValidVehicle: Difference between revisions
From Onset Developer Wiki
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{Info|Function|Server & Client|1.0}} | {{Info|Function|Server & Client|1.0}} | ||
{{FuncDescription| | {{FuncDescription|Checks whether a given vehicle identifier is a valid vehicle.}} | ||
{{FuncSyntax|IsValidVehicle(vehicle)}} | {{FuncSyntax|IsValidVehicle(vehicle)}} | ||
{{FuncParameters}} | {{FuncParameters}} | ||
{{FuncParam|vehicle| | {{FuncParam|vehicle|The vehicle identifier to check.}} | ||
{{FuncReturnValue| | {{FuncReturnValue|Returns '''true''' on success, '''false''' on error.}} | ||
== Example == | == Example == | ||
<syntaxhighlight lang="Lua"> | |||
function cmd_debugvehicle(player, vehicle) | |||
if (vehicle == nil) then | |||
return AddPlayerChat(player, "Usage: /debugvehicle <vehicle>") | |||
end | |||
if (not IsValidVehicle(vehicle)) then | |||
return AddPlayerChat(player, "Vehicle (ID: "..vehicle..") does not exist") | |||
end | |||
local model = GetVehicleModelName(vehicle).." (ModelID: "..GetVehicleModel(vehicle)..")" | |||
local x, y, z = GetVehicleLocation(vehicle) | |||
local rx, ry, rz = GetVehicleRotation(vehicle) | |||
local h = GetVehicleRotation(vehicle) | |||
local vx, vy, vz = GetVehicleVelocity(vehicle) | |||
local health = GetVehicleHealth(vehicle) | |||
local r, g, b = HexToRGBA(GetVehicleColor(vehicle)) | |||
local streamed = IsVehicleStreamedIn(player, vehicle) == true and 'True' or 'False' | |||
local occupants = {} | |||
for i=1, GetVehicleNumberOfSeats(vehicle) do | |||
local passenger = GetVehiclePassenger(vehicle, i) | |||
if (passenger == 0) then | |||
occupants[i] = "Empty" | |||
else | |||
occupants[i] = GetPlayerName(passenger).."("..passenger..")" | |||
end | |||
end | |||
AddPlayerChat(player, '<span color="00ee00ff">Vehicle (ID: '..vehicle..')</>') | |||
AddPlayerChat(player, ' Loc: ' .. x .. ', ' .. y .. ', ' .. z) | |||
AddPlayerChat(player, ' Rot: ' .. rx .. ', ' .. ry .. ', ' .. rz) | |||
AddPlayerChat(player, ' Velocity: ' .. vx .. ', ' .. vy .. ', ' .. vz) | |||
AddPlayerChat(player, ' Health: '..health) | |||
AddPlayerChat(player, ' Model: '..model) | |||
AddPlayerChat(player, ' Color: '..r..', '..g..', '..b) | |||
AddPlayerChat(player, ' StreamedIn: '..streamed) | |||
for k, v in ipairs(occupants) do | |||
AddPlayerChat(player, ' Seat '..k..': '..v) | |||
end | |||
end | |||
AddCommand("debugvehicle", cmd_debugvehicle) | |||
</syntaxhighlight> | |||
{{RelatedFunctions}} | {{RelatedFunctions}} | ||
{{VehicleFunctions}} |
Latest revision as of 12:51, 22 March 2019
Description
Checks whether a given vehicle identifier is a valid vehicle.
Syntax
IsValidVehicle(vehicle)
Parameters
- vehicle
The vehicle identifier to check.
Return Value
- Returns true on success, false on error.
Example
function cmd_debugvehicle(player, vehicle)
if (vehicle == nil) then
return AddPlayerChat(player, "Usage: /debugvehicle <vehicle>")
end
if (not IsValidVehicle(vehicle)) then
return AddPlayerChat(player, "Vehicle (ID: "..vehicle..") does not exist")
end
local model = GetVehicleModelName(vehicle).." (ModelID: "..GetVehicleModel(vehicle)..")"
local x, y, z = GetVehicleLocation(vehicle)
local rx, ry, rz = GetVehicleRotation(vehicle)
local h = GetVehicleRotation(vehicle)
local vx, vy, vz = GetVehicleVelocity(vehicle)
local health = GetVehicleHealth(vehicle)
local r, g, b = HexToRGBA(GetVehicleColor(vehicle))
local streamed = IsVehicleStreamedIn(player, vehicle) == true and 'True' or 'False'
local occupants = {}
for i=1, GetVehicleNumberOfSeats(vehicle) do
local passenger = GetVehiclePassenger(vehicle, i)
if (passenger == 0) then
occupants[i] = "Empty"
else
occupants[i] = GetPlayerName(passenger).."("..passenger..")"
end
end
AddPlayerChat(player, '<span color="00ee00ff">Vehicle (ID: '..vehicle..')</>')
AddPlayerChat(player, ' Loc: ' .. x .. ', ' .. y .. ', ' .. z)
AddPlayerChat(player, ' Rot: ' .. rx .. ', ' .. ry .. ', ' .. rz)
AddPlayerChat(player, ' Velocity: ' .. vx .. ', ' .. vy .. ', ' .. vz)
AddPlayerChat(player, ' Health: '..health)
AddPlayerChat(player, ' Model: '..model)
AddPlayerChat(player, ' Color: '..r..', '..g..', '..b)
AddPlayerChat(player, ' StreamedIn: '..streamed)
for k, v in ipairs(occupants) do
AddPlayerChat(player, ' Seat '..k..': '..v)
end
end
AddCommand("debugvehicle", cmd_debugvehicle)
See also
- CreateVehicle
- DestroyVehicle
- IsValidVehicle
- GetVehicleCount
- GetAllVehicles
- GetVehicleModel
- GetVehicleModelName
- SetVehicleRespawnParams
- IsVehicleStreamedIn
- GetStreamedVehiclesForPlayer
- GetStreamedVehicles
- SetVehicleLocation
- GetVehicleLocation
- SetVehicleRotation
- GetVehicleRotation
- SetVehicleHeading
- GetVehicleHeading
- SetVehicleHealth
- GetVehicleHealth
- SetVehicleLicensePlate
- GetVehicleVelocity
- GetVehicleDriver
- GetVehiclePassenger
- GetVehicleNumberOfSeats
- SetVehicleColor
- GetVehicleColor
- SetVehicleLinearVelocity
- SetVehicleAngularVelocity
- GetVehicleGear
- SetVehicleHoodRatio
- GetVehicleHoodRatio
- SetVehicleTrunkRatio
- GetVehicleTrunkRatio
- StartVehicleEngine
- StopVehicleEngine
- GetVehicleEngineState
- SetVehicleLightEnabled
- GetVehicleLightState
- SetVehicleDamage
- GetVehicleDamage
- AttachVehicleNitro