IsValidVehicle

From Onset Developer Wiki
Revision as of 12:51, 22 March 2019 by BlueMountains (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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