GetVehicleNitroCount: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (fixes)
Line 5: Line 5:
}}
}}


'''Note:''' This function return ''false'' if nitro is not exists. So you need add nitro via function [[addVehicleUpgrade]].
{{Warning|Function is not working correctly.}}  
{{Warning|Function not working correctly}}  
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">int getVehicleNitroCount ( vehicle theVehicle )</syntaxhighlight>  
<syntaxhighlight lang="lua">int getVehicleNitroCount ( vehicle theVehicle )</syntaxhighlight>  
Line 14: Line 13:


===Returns===
===Returns===
This function returns a nitro count from vehicle.
Returns ''an integer'' determining the amount of nitro counts of the vehicle, ''false'' if there is no nitro in the vehicle.


==Example==
==Example==
This example draws a nitro count on vehicles.
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">addEventHandler( 'onClientRender', root,
This example draws the nitro count on vehicle on the player's screen.
function()
<syntaxhighlight lang="lua">
local fCamX, fCamY, fCamZ = getCameraMatrix()
function drawNitroCounts()
for _, v in ipairs( getElementsByType 'vehicle' ) do
local fCamX, fCamY, fCamZ = getCameraMatrix()
if getVehicleUpgradeOnSlot( v, 8 ) then -- Nitro installed?
for _, v in ipairs(getElementsByType("vehicle")) do
local fX, fY, fZ = getElementPosition( v )
if getVehicleUpgradeOnSlot(v, 8) then -- Check if the vehicle has nitro installed
local fCamX, fCamY, fCamZ = getCameraMatrix()
local fX, fY, fZ = getElementPosition(v)
local fX2, fY2 = getScreenFromWorldPosition( fX, fY, fZ + 0.85, 0.08 )
local fCamX, fCamY, fCamZ = getCameraMatrix()
if fX2 then
local fX2, fY2 = getScreenFromWorldPosition(fX, fY, fZ + 0.85, 0.08)
local fDistance = getDistanceBetweenPoints3D( fX, fY, fZ, fCamX, fCamY, fCamZ )
if fX2 then
if fDistance < 60 then
local fDistance = getDistanceBetweenPoints3D(fX, fY, fZ, fCamX, fCamY, fCamZ)
if isLineOfSightClear( fCamX, fCamY, fCamZ, fX, fY, fZ, true, false, false, true, false ) then
if fDistance < 60 then
local pVehicle = getPedOccupiedVehicle( localPlayer )
if isLineOfSightClear(fCamX, fCamY, fCamZ, fX, fY, fZ, true, false, false, true, false) then
if not pVehicle or pVehicle ~= v then
local pVehicle = getPedOccupiedVehicle(localPlayer)
local fScale = ( 60 / fDistance ) * 0.7
if not pVehicle or pVehicle ~= v then
local iNitroCount = getVehicleNitroCount( v )
local fScale = (60 / fDistance) * 0.7
dxDrawText( 'Nitro count: ' .. iNitroCount, fX2 + 1, fY2 + 1, fX2 + 1, fY2 + 1, tocolor( 0, 0, 255 ), fScale, 'default', 'center', 'bottom' )
local iNitroCount = getVehicleNitroCount(v)
dxDrawText( 'Nitro count: ' .. iNitroCount, fX2, fY2, fX2, fY2, tocolor( 255, 255, 255 ), fScale, 'default', 'center', 'bottom' )
dxDrawText("Nitro count: " .. iNitroCount, fX2 + 1, fY2 + 1, fX2 + 1, fY2 + 1, tocolor(0, 0, 255), fScale, "default", "center", "bottom")
end
dxDrawText("Nitro count: " .. iNitroCount, fX2, fY2, fX2, fY2, tocolor(255, 255, 255), fScale, "default", "center", "bottom")
end
end
end
end
Line 43: Line 42:
end
end
end
end
)</syntaxhighlight>
end
addEventHandler("onClientRender", root, drawNitroCounts)
</syntaxhighlight>
</section>


==Requirements==
==Requirements==

Revision as of 11:36, 14 March 2013

ADDED/UPDATED IN VERSION 1.3.1 r4993:

This function get the nitro count from the vehicle.


[[|link=|]] Warning: Function is not working correctly.

Syntax

int getVehicleNitroCount ( vehicle theVehicle )

Required Arguments

  • theVehicle The vehicle which you want to get a nitro count.

Returns

Returns an integer determining the amount of nitro counts of the vehicle, false if there is no nitro in the vehicle.

Example

Click to collapse [-]
Client

This example draws the nitro count on vehicle on the player's screen.

function drawNitroCounts()
	local fCamX, fCamY, fCamZ = getCameraMatrix()
	for _, v in ipairs(getElementsByType("vehicle")) do
		if getVehicleUpgradeOnSlot(v, 8) then -- Check if the vehicle has nitro installed
			local fX, fY, fZ = getElementPosition(v)
			local fCamX, fCamY, fCamZ = getCameraMatrix()
			local fX2, fY2 = getScreenFromWorldPosition(fX, fY, fZ + 0.85, 0.08)
			if fX2 then
				local fDistance = getDistanceBetweenPoints3D(fX, fY, fZ, fCamX, fCamY, fCamZ)
				if fDistance < 60 then
					if isLineOfSightClear(fCamX, fCamY, fCamZ, fX, fY, fZ, true, false, false, true, false) then
						local pVehicle = getPedOccupiedVehicle(localPlayer)
						if not pVehicle or pVehicle ~= v then
							local fScale = (60 / fDistance) * 0.7
							local iNitroCount = getVehicleNitroCount(v)
							dxDrawText("Nitro count: " .. iNitroCount, fX2 + 1, fY2 + 1, fX2 + 1, fY2 + 1, tocolor(0, 0, 255), fScale, "default", "center", "bottom")
							dxDrawText("Nitro count: " .. iNitroCount, fX2, fY2, fX2, fY2, tocolor(255, 255, 255), fScale, "default", "center", "bottom")
						end
					end
				end
			end
		end
	end
end
addEventHandler("onClientRender", root, drawNitroCounts)

Requirements

Minimum server version n/a
Minimum client version 1.3.1-9.04993

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.3.1-9.04993" />

See Also