Jump to content

velocimeter


lima

Recommended Posts


I'm trying to put this dxDrawImageSection to work according to the speedometer but it's giving an error when loading the image.

Could someone help me put the image to interact with the speedometer?


local screen = {guiGetScreenSize ()}
local resolution = {1366, 768}
local scale = math.min (0.75, math.max ((screen[2] / resolution[2]), 2))


addEventHandler("onClientResourceStart", resourceRoot,
function()
    loadSVG()
end)

local bollX, bollY = (screen[1] - (scale * 152)), (screen[2] - (scale * 254))

local bollTX, bollTY = (screen[1] - (scale *  183)), (screen[2] - (scale * 183))

local fuelX, fuelY = (screen[1] - (scale * 67)), (screen[2] - (scale * 67))

local textX, textY = (screen[1] - (scale * 35)), (screen[2] - (scale * 105))
local bollTTX, bollTTY = (screen[1] - (scale * 70)), (screen[2] - (scale * 60))


local font = dxCreateFont("assets/fonts/Medium.ttf", 17)

addEventHandler ("onClientRender", root, function ()
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if not vehicle then return end
    local kmh = getElementSpeed(vehicle, 2)
    local maxVelocity = (getVehicleHandling(vehicle)["maxVelocity"])
    local fuel = (getElementData(vehicle, "fuel") or 100)
    local motor = (getElementHealth(vehicle))

    dxDrawImage(bollX - 108, bollY - 30, 280 * scale, 255 * scale, "assets/img/base.png")
    dxDrawImage(bollX - 10, bollY + 132 , 17 * scale, 17 * scale, "assets/img/dano.png")
    dxDrawImage(bollX - 39, bollY + 130 , 20 * scale, 19 * scale, "assets/img/fuel1.png")
    dxDrawImage(bollX + 12, bollY + 124 , 35 * scale, 35 * scale, "assets/img/lock.png")

    --setSVGOffset(1, -281)

    --createCircleStroke(1, 393 * scale, 393 * scale, 21)
    --drawItem(1, bollTX - 160, bollTY - 195, 200, tocolor(0, 224, 255, 255), false)
    --setSVGOffset(1, -281 +( maxVelocity*kmh))

    
    dxDrawImageSection(bollTX + 72, bollTY + 120, 60 * ((getElementSpeed(vehicle,2,maxVelocity*kmh) or 100) / 100), 11, 0, 0, 60 * ((getElementSpeed(vehicle,2,maxVelocity*kmh) or      100) / 100), 11, 'assets/img/base2.png', 0, 0, 0, tocolor(255, 255, 255, alpha))
       

    createCircleStroke(4, 50 * scale, 50 * scale, 2)
    drawItem(4, bollTTX - 115, bollTTY - 34, 200, tocolor(0, 224, 255, 255), false)
    setSVGOffset(4, (80/100*fuel))


    createCircleStroke(6, 50 * scale, 50 * scale, 2)
    drawItem(6, bollTTX - 80, bollTTY - 34, 250, tocolor(0, 224, 255, 255), false)
    setSVGOffset(6, motor <= 100 and 0 or (7/150*motor))


    kmh = math.floor(kmh)
        if (kmh == 0) then 
            kmh = '00'..kmh
        elseif (kmh < 10) then 
            kmh = '00'..kmh
        elseif (kmh < 100) then 
            kmh = '0'..kmh
        end 

    dxDrawText(kmh, textX - 143, textY - (90), ((textX - 143)+108), ((textY - (90))+72), tocolor(255, 255, 255, 75), 1.00, font, "center", "center", false, false, false, false, false)
end)


function getElementSpeed(theElement, unit)
    assert(isElement(theElement), "Bad argument 1 @ getElementSpeed (element expected, got " .. type(theElement) .. ")")
    local elementType = getElementType(theElement)
    assert(elementType == "player" or elementType == "ped" or elementType == "object" or elementType == "vehicle" or elementType == "projectile", "Invalid element type @ getElementSpeed (player/ped/object/vehicle/projectile expected, got " .. elementType .. ")")
    assert((unit == nil or type(unit) == "string" or type(unit) == "number") and (unit == nil or (tonumber(unit) and (tonumber(unit) == 0 or tonumber(unit) == 1 or tonumber(unit) == 2)) or unit == "m/s" or unit == "km/h" or unit == "mph"), "Bad argument 2 @ getElementSpeed (invalid speed unit)")
    unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit))
    local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456)
    return (Vector3(getElementVelocity(theElement)) * mult).length
end
 

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...