Jump to content

Speedometer with GUIEditor

Recommended Posts

Hi, I'm trying to make a speedometer created in GUIEditor, but I can't make the needle move. I saw that many speedometers are made with dxDrawRelativeImage and how to do it with GUIEditor?

GUIEditor.staticimage[8] = guiCreateStaticImage(1159 * scaleX, 741 * scaleY, 257 * scaleX, 244 * scaleY, "Speedo/ASDDIAL.png", false)
        GUIEditor.staticimage[9] = guiCreateStaticImage(21 * scaleX, 10 * scaleY, 216 * scaleX, 246 * scaleY, "Speedo/DALTLONG.png", false, GUIEditor.staticimage[8])

local function drawSpeedo()
	local veh = getPedOccupiedVehicle(localPlayer)
	if not veh then return end

	local velx, vely, velz = getElementVelocity(veh)
	local speed = (velx ^ 2 + vely ^ 2 + velz ^ 2) ^ (0.5)
	needleRotation = -146 + (speed * 180)


local isSpeedoShown = false
function toggleRender(bool)
	if bool then
		isSpeedoShown = true
		addEventHandler("onClientRender", root, drawSpeedo)
		addEventHandler("onClientRender", root, rotateNeedle)
		isSpeedoShown = false
		removeEventHandler("onClientRender", root, drawSpeedo)
		removeEventHandler("onClientRender", root, rotateNeedle)

function rotateNeedle()
	local needleImage = GUIEditor.staticimage[9]
	guiSetProperty(needleImage, "Rotated", tostring(needleRotation))


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