SetVehicleColor: Difference between revisions

From Onset Developer Wiki
Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|SetVehicleColor(vehicle, HexColor)}} {{FuncParameters}} {{FuncParam|vehicle|__EDIT_ME__}} {{FuncPa..."
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|Sets the color of a given vehicle.}}


{{FuncSyntax|SetVehicleColor(vehicle, HexColor)}}
{{FuncSyntax|SetVehicleColor(vehicle, IntColor)}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|vehicle|__EDIT_ME__}}
{{FuncParam|vehicle|The vehicle to change the color of.}}
{{FuncParam|HexColor|__EDIT_ME__}}
{{FuncParam|IntColor|The color as an integer. Use [[RGB]] to convert RGB codes to int.}}


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


== Example ==
== Example ==
__EDIT_ME__
<syntaxhighlight lang="Lua">
function cmd_vcolor(player, r, g, b)
if (r == nil or g == nil or b == nil) then
return AddPlayerChat(player, "Usage: /vcolor <r> <g> <b>")
end
 
local vehicle = GetPlayerVehicle(player)
 
if (vehicle == 0) then
return AddPlayerChat(player, "You must be in a vehicle")
end
 
if (GetPlayerVehicleSeat(player) ~= 1) then
return AddPlayerChat(player, "You must be the driver of the vehicle")
end
 
SetVehicleColor(vehicle, RGB(r, g, b))
AddPlayerChat(player, "New vehicle color set (Integer color: "..GetVehicleColor(vehicle)..")")
end
AddCommand("vcolor", cmd_vcolor)
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
{{VehicleFunctions}}

Latest revision as of 20:39, 30 August 2020

SetVehicleColor

Type: Function
Context: Server
Introduced: v1.0

Description

Sets the color of a given vehicle.

Syntax

SetVehicleColor(vehicle, IntColor)

Parameters

  • vehicle
    The vehicle to change the color of.
  • IntColor
    The color as an integer. Use RGB to convert RGB codes to int.

Return Value

  • Returns true on success, false on error.

Example

function cmd_vcolor(player, r, g, b)
	if (r == nil or g == nil or b == nil) then
		return AddPlayerChat(player, "Usage: /vcolor <r> <g> <b>")
	end

	local vehicle = GetPlayerVehicle(player)

	if (vehicle == 0) then
		return AddPlayerChat(player, "You must be in a vehicle")
	end

	if (GetPlayerVehicleSeat(player) ~= 1) then
		return AddPlayerChat(player, "You must be the driver of the vehicle")
	end

	SetVehicleColor(vehicle, RGB(r, g, b))
	AddPlayerChat(player, "New vehicle color set (Integer color: "..GetVehicleColor(vehicle)..")")
end
AddCommand("vcolor", cmd_vcolor)

See also