Jump to content

Speedometer


TorNix~|nR

Recommended Posts

Hello guys, I have my speedometer script, it's working fine

but when the lights are off it change to SPEEDOM0.png, and when the lights on it change to SPEEDOM1.png

but there is a problem, it only change the logo when press 'L', it's not automatically check

I want to make it with this

getVehicleOverrideLights

 

Code

lightState = 0

localPlayer = getLocalPlayer ()

addEventHandler("onClientVehicleEnter", getRootElement(),
    function(thePlayer, seat)
        if thePlayer == getLocalPlayer() then
			if seat == 0 then
				bindKey ( "l", "down", showLightState_panel )
				addEventHandler("onClientRender",root, showPanel_main ) 
				lightState = getVehicleOverrideLights ( source ) or 0
			end
		end
    end
)

addEventHandler("onClientVehicleExit", getRootElement(),
    function(thePlayer, seat)
        if thePlayer == getLocalPlayer() then
			if seat == 0 then
				removeEventHandler("onClientRender",root, showPanel_main )
				unbindKey ( "l", "down" )
				lightState = 0
			end
        end
    end
)

local screenX, screenY = guiGetScreenSize() 
function toposition(x,y) 
  local finalX,finalY = x,y 
  if x > 1 then finalX = x 
  elseif x < -1 then finalX = screenX - x 
  elseif x > 0 then finalX = screenX * x 
  else finalX = screenX - (screenX * x) 
  end 
  -- 
  if y > 1 then finalY = y 
  elseif y < -1 then finalY = screenY - y 
  elseif y > 0 then finalY = screenY * y 
  else finalY = screenY - (screenY * y) 
  end 
  return finalX,finalY 
end

------------------------------- Панель

function showPanel_main ()
	if not getPedOccupiedVehicle ( localPlayer ) then
		removeEventHandler("onClientRender",root, showPanel_main )
		unbindKey ( "l", "down" )
		lightState = 0
		return true
	end
	local vehicleSpeed = getVehicleSpeed()
	local fuel = getElementData(getPedOccupiedVehicle ( localPlayer ), "vehicleFuel" ) or 0
	fuel_t = (fuel-100)-(fuel-100)/3
	if fuel_t > 60 then
		fuel_t = 60
	end
	if fuel_t < -60 then
		fuel_t = -60
	end
	if lightState == 0 or lightState == 1 then
		dxDrawImage(screenX-400, screenY-300,400,343,"SPEEDOM0.png",0.0,0.0,0.0,tocolor(255,255,255,255),false)
		dxDrawImage(screenX-218, screenY-190, 140, 115,"ARROWB0.png",vehicleSpeed-135,0.0,0.0,tocolor(255,255,255,255),false)
		dxDrawImage(screenX-367, screenY-140, 120, 115,"ARROWN0.png",fuel_t,0.0,0.0,tocolor(255,255,255,255),false)
	else
		dxDrawImage(screenX-400, screenY-300,400,343,"SPEEDOM1.png",0.0,0.0,0.0,tocolor(255,255,255,255),false)
		dxDrawImage(screenX-218, screenY-190, 140, 115,"ARROWB1.png",vehicleSpeed-135,0.0,0.0,tocolor(255,255,255,255),false)
		dxDrawImage(screenX-367, screenY-140, 120, 115,"ARROWN1.png",fuel_t,0.0,0.0,tocolor(255,255,255,255),false)
	end
   
	if getElementData(getPedOccupiedVehicle ( localPlayer ), "vehicleFuel" ) < 40 then
		dxDrawImage(screenX-267, screenY-64, 30, 30,"ICON2.png",0.0,0.0,0.0,tocolor(255,255,255,255),false)
	end
end

-------------------------------  Освещение

function showLightState_panel ()
	if lightState == 0 or lightState == 1 then
		lightState = 2
		setVehicleOverrideLights( getPedOccupiedVehicle ( localPlayer ), 2 )
	else
		setVehicleOverrideLights( getPedOccupiedVehicle ( localPlayer ), 1 )
		lightState = 0
	end
end

-----------------------

function getVehicleSpeed()
    if isPedInVehicle(localPlayer) then
        local vx, vy, vz = getElementVelocity(getPedOccupiedVehicle(localPlayer))
        return math.sqrt(vx^2 + vy^2 + vz^2) * 155
    end
    return 0
end

--addEventHandler("onClientRender",root, showPanel_main ) 

Guys help me please!

Link to comment

Let me get it straight. You want to check if your vehicle has its override lights on, but you only check it when you press "L", right?

In that case just use:

-- Everything here should be onClientRender
local lights
function ()
local vehicle = getPedOccupiedVehicle (localPlayer)
	if vehicle then --Is localPlayer in vehicle?
    lights = getVehicleOverrideLights (vehicle) --Here you get the state of the overridelights
    else
    lights = false --if there is no vehicle, false
    end
end

 

  • Confused 1
Link to comment
4 minutes ago, TorNix~|nR said:

I mean, I want to make it get the lights automatically and change the logo, the logo get changed only by pressing 'L'

I want to make it automatically, help please?

Then use the code I've shown you above and:

local logo = false
bindKey ("l","down",function()
  logo = not logo
  end)



-- this will go onClientRender:
if logo then
  image = "image1.png" -- logo 1 filepath
  else
  image = "image2.png" -- logo 2 filepath
  end
dxDrawImage (x,y,w,h,image,...)

 

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