GetVehicleCurrentGear: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 19: Line 19:
Example of a program that outputs the current gear to the lower, center of the screen
Example of a program that outputs the current gear to the lower, center of the screen
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
g_player = getLocalPlayer()
g_root = getRootElement()
function makeGearGui( )
function makeGearGui( )
local sx,sy = guiGetScreenSize()
local sx, sy = guiGetScreenSize()
local wx = 50
local wx = 50
local wy = 50
local wy = 50
gearLabel = guiCreateLabel(((sx/2)-wx),(sy-wy),wx,wy,"5",false)
gearLabel = guiCreateLabel(((sx / 2) - wx), (sy - wy), wx, wy, "5", false)
end
end
makeGearGui()


function onRender()
function onRender()
g_vehicle = getPedOccupiedVehicle(g_player)
g_vehicle = getPedOccupiedVehicle(localPlayer)
if g_vehicle then
if g_vehicle then
g_curGear = tostring(getVehicleCurrentGear(g_vehicle))
g_curGear = tostring(getVehicleCurrentGear(g_vehicle))
guiSetText(gearLabel,g_curGear)
guiSetText(gearLabel, g_curGear)
else
else
guiSetText(gearLabel,"")
guiSetText(gearLabel, "")
end
end
end
end
 
addEventHandler("onClientRender", root, onRender)
makeGearGui()
addEventHandler("onClientRender",g_root,onRender)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 15:09, 14 February 2021

Gets the specified vehicle's current gear.

Syntax

int getVehicleCurrentGear ( vehicle theVehicle )

Required Arguments

  • theVehicle: the vehicle to get the gear of

Returns

Returns the gear if successful, false otherwise.

Example

Click to collapse [-]
Client

Example of a program that outputs the current gear to the lower, center of the screen

function makeGearGui( )
	local sx, sy = guiGetScreenSize()
	local wx = 50
	local wy = 50
	gearLabel = guiCreateLabel(((sx / 2) - wx), (sy - wy), wx, wy, "5", false)
end
makeGearGui()

function onRender()
	g_vehicle = getPedOccupiedVehicle(localPlayer)
	if g_vehicle then
		g_curGear = tostring(getVehicleCurrentGear(g_vehicle))
		guiSetText(gearLabel, g_curGear)
	else
		guiSetText(gearLabel, "")
	end
end
addEventHandler("onClientRender", root, onRender)

See Also