Jump to content

Recommended Posts

Hello

Is it possible to somehow check the value of how much NOS you have in the vehicle because I am looking for but not which do not seem to work as if they were not at all.

I need this value to make a bar that will show how much nitro the vehicle has.

Link to comment
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)
Edited by Sr.black
Link to comment
function drawNitroBar()
  local vehicle = getPedOccupiedVehicle(localPlayer)
  if isElement(vehicle) and getVehicleUpgradeOnSlot (vehicle, 8) then
    local nosLevel = getVehicleNitroLevel(vehicle)
    local screenWidth, screenHeight = guiGetScreenSize()
    local barWidth = 200
    local barHeight = 20
    local barX = (screenWidth - barWidth) / 2
    local barY = 20
    local nosPercent = math.floor(nosLevel * 100)
    local textX = barX + (barWidth / 2)
    local textY = barY
    local textSize = 1
    local textColor = tocolor(255, 255, 255, 255)
    local textFont = "default"
    local textAlignment = "center"
    r = nosPercent >= 100 and 0 or nosPercent >= 80 and 0 or nosPercent >= 50 and 255 or nosPercent >= 30 and 255 or nosPercent >= 20 and 200 or 150
    g = nosPercent >= 100 and 255 or nosPercent >= 80 and 200 or nosPercent >= 50 and 165 or nosPercent >= 30 and 0 or nosPercent >= 20 and 0 or 0
    b = nosPercent >= 100 and 0 or nosPercent >= 80 and 0 or nosPercent >= 50 and 0 or nosPercent >= 30 and 0 or nosPercent >= 20 and 0 or 0
    dxDrawRectangle(barX, barY, barWidth, barHeight, tocolor(0, 0, 0, 128))
    dxDrawRectangle(barX, barY, barWidth * nosLevel, barHeight, tocolor(r, g, b, 192))
    dxDrawText(nosPercent.."%", textX, textY, textX, textY, textColor, textSize, textFont, textAlignment)
  end
end
addEventHandler("onClientPreRender", root, drawNitroBar)

pretty sure u wanted it like that 

Edited by FLUSHBICEPS
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...