GetPlayerVehicle: Difference between revisions

From Onset Developer Wiki
No edit summary
28days (talk | contribs)
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{Info|Function|Server & Client|1.0}}
{{Info|Function|Server & Client|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|Returns the vehicle identifier the player is in.}}


{{FuncSyntax|GetPlayerVehicle(player)}}
{{FuncSyntax|GetPlayerVehicle(player)}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|player|__EDIT_ME__}}
{{FuncParam|player|The player identifier.}}


{{FuncReturnValue|__EDIT_ME__}}
{{FuncReturnValue|Returns the vehicle identifier the player is in. Returns '''0''' if not in any vehicle.}}


== Example ==
== Example ==
__EDIT_ME__
<syntaxhighlight lang="Lua>
AddCommand("colorv", function(playerid, red, green, blue)
local vehicleid = GetPlayerVehicle(playerid)
 
if vehicleid == 0 then
AddPlayerChat(playerid, "You must be in a vehicle...")
return
end
 
red = tonumber(red)
green = tonumber(green)
blue = tonumber(blue)
 
if red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255 then
AddPlayerChat(playerid, "Usage: /colorv <red> <green> <blue>")
return
end
 
SetVehicleColor(vehicleid, RGB(red, green, blue, 255))
end)
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
{{Template:VehicleFunctions}}

Latest revision as of 09:58, 12 December 2019

GetPlayerVehicle

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

Description

Returns the vehicle identifier the player is in.

Syntax

GetPlayerVehicle(player)

Parameters

  • player
    The player identifier.

Return Value

  • Returns the vehicle identifier the player is in. Returns 0 if not in any vehicle.

Example

AddCommand("colorv", function(playerid, red, green, blue)
	local vehicleid = GetPlayerVehicle(playerid)

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

	red = tonumber(red)
	green = tonumber(green)
	blue = tonumber(blue)

	if red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255 then
		AddPlayerChat(playerid, "Usage: /colorv <red> <green> <blue>")
		return
	end

	SetVehicleColor(vehicleid, RGB(red, green, blue, 255))
end)

See also