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|__EDIT_ME__}}
{{FuncDescription|Checks whether a given vehicle identifier is a valid vehicle.}}


{{FuncSyntax|IsValidVehicle(vehicle)}}
{{FuncSyntax|IsValidVehicle(vehicle)}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|vehicle|__EDIT_ME__}}
{{FuncParam|vehicle|The vehicle identifier to check.}}


{{FuncReturnValue|__EDIT_ME__}}
{{FuncReturnValue|Returns '''true''' on success, '''false''' on error.}}


== Example ==
== Example ==
__EDIT_ME__
<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}}
__EDIT_ME__
{{VehicleFunctions}}

Latest revision as of 12:51, 22 March 2019

IsValidVehicle

Type: Function
Context: Server & Client
Introduced: v1.0

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