local x, y = guiGetScreenSize()
show_speed = false
local smothedRotation = 0
local indikator_1 = "images/1.png"
local indikator_2 = "images/2.png"
local indikator_3 = "images/3.png"
local indikator_4 = "images/4.png"
local indikator_5 = "images/5.png"
local indikator_6 = "images/6.png"
local indikator_7 = "images/7.png"
local indikator_8 = "images/8.png"
alpha = 255
function fons ()
if show_speed == false then
local veh = getPedOccupiedVehicle(getLocalPlayer())
if not veh or getVehicleOccupant ( veh ) ~= localPlayer then return true end
if not driveDistance then lastTick = getTickCount() driveDistance = getElementData ( veh, "driveDistance" ) or 0 end
local vehs = getElementSpeed(getPedOccupiedVehicle(getLocalPlayer()), "kmh")
local fuel = getElementData(getPedOccupiedVehicle ( localPlayer ), "vehicle:fuel" ) or 0
local rot = math.floor(((270/9800)* getVehicleRPM(getPedOccupiedVehicle(getLocalPlayer()))) + 0.5)
local actualspeed = getElementSpeed (veh, 1)
local kmh = math.floor(actualspeed)
local num = getElementData(veh,"vehicle:mileage") or 0
local mileage = ""..math.floor(num)
repeat mileage = "0"..mileage until #mileage >= 7
if smothedRotation > 252 then
smothedRotation = 252
else
if (smothedRotation < rot) then
smothedRotation = smothedRotation + 1.8
end
if (smothedRotation > rot) then
smothedRotation = smothedRotation - 1.8
end
end
------------------------------------------------------------------------------------------------------------------------------------------------------
dxDrawImage(x - 420, y - 230, 405, 198, "images/fon.png", 0, 0, 0, tocolor(255,255,255,225))
--dxDrawButtonText_pas(x - 245, y - 240, 220, 220, "КМ/Ч", 0.30, 0.30)
--dxDrawImage(x - 365, y - 184, 150, 150, "images/odometr.png", smothedRotation - 128, 0, 0, tocolor(255,255,255,225))
--hou_straight( x - 288, y - 108, 144, 145, tocolor(255,0,0, 200), 140, smothedRotation+2,5)
dxDrawButtonText_pas(x - 241, y - 205, 220, 220, mileage, 0.3, 0.3)
dxDrawButtonText_pas(x - 245, y - 265, 220, 250, kmh, 0.7, 0.7)
if kmh < 405 then
dxDrawImage(x - 245, y - 220, 220, 220, "images/spidometr.png", (-37) + kmh / 1.6 , 0, 0, tocolor(255,255,255,225))
hou_circle( x - 128, y - 128, 160, 160, tocolor(0, 191, 255, 100), 277, kmh / 1.4,20)
else
--dxDrawImage(x - 245, y - 220, 220, 220, "images/spidometr.png", (-37) + 405 / 1.6 , 0, 0, tocolor(255,255,255,225))
--hou_circle( x - 135, y - 112, 234, 235, tocolor(208,64,64, 150), 232, 405 / 1.6,8)
end
-- outputChatBox(getElementSpeed(veh))
------------------------------------------------------------------------------------------------------------------------------------------------------
--dxDrawImage(x - 75, y - 50, 40, 40, indikator_7, 0, 0, 0, tocolor(255,255,255,alpha))
if getVehicleOverrideLights( veh ) == 2 then
dxDrawImage(x - 75, y - 50, 40, 40, indikator_8, 0, 0, 0, tocolor(255,255,255,225))
--alpha = 0
elseif getVehicleOverrideLights( veh ) == 1 then
dxDrawImage(x - 75, y - 50, 40, 40, indikator_7, 0, 0, 0, tocolor(255,255,255,225))
-- alpha = 0
end
if getVehicleEngineState ( veh ) == false then
dxDrawImage(x - 210, y - 50, 40, 40, indikator_1, 0, 0, 0, tocolor(255,255,255,225))
elseif getVehicleEngineState ( veh ) == true then
dxDrawImage(x - 210, y - 50, 40, 40, indikator_2, 0, 0, 0, tocolor(255,255,255,225))
end
if isVehicleLocked ( veh ) then
dxDrawImage(x - 165, y - 50, 40, 40, indikator_3, 0, 0, 0, tocolor(255,255,255,225))
else
dxDrawImage(x - 165, y - 50, 40, 40, indikator_4, 0, 0, 0, tocolor(255,255,255,225))
end
if getElementData(veh, "cruize") == false then
dxDrawImage(x - 120, y - 50, 40, 40, indikator_5, 0, 0, 0, tocolor(255,255,255,225))
elseif getElementData(veh, "cruize") == true then
dxDrawImage(x - 120, y - 50, 40, 40, indikator_6, 0, 0, 0, tocolor(255,255,255,225))
end
hou_circle( x - 215, y - 85, 100, 100, tocolor(0, 191, 255, 100), 360, fuel / 3 * 10.9,7) --85
end
end
addEventHandler ( "onClientRender", getRootElement(), fons)
bindKey("4","down",function()
triggerServerEvent( "triggerVehicleSystem", localPlayer, "engine" )
end)
--bindKey("3","down",function()
-- triggerServerEvent( "triggerVehicleSystem", localPlayer, "lights" )
--end)
function getVehicleRPM(vehicle)
local vehicleRPM = 0
if (vehicle) then
if (getVehicleEngineState(vehicle) == true) then
if getVehicleCurrentGear(vehicle) > 0 then
vehicleRPM = math.floor(((getElementSpeed(vehicle, "kmh")/getVehicleCurrentGear(vehicle))*180) + 0.5)
if (vehicleRPM < 650) then
vehicleRPM = math.random(650, 750)
elseif (vehicleRPM >= 9800) then
vehicleRPM = math.random(9800, 9900)
end
else
vehicleRPM = math.floor((getElementSpeed(vehicle, "kmh")*180) + 0.5)
if (vehicleRPM < 650) then
vehicleRPM = math.random(650, 750)
elseif (vehicleRPM >= 9800) then
vehicleRPM = math.random(9800, 9900)
end
end
else
vehicleRPM = 0
end
return tonumber(vehicleRPM)
else
return 0
end
end
function getFormatSpeed(unit)
if unit < 10 then
unit = "00" .. unit
elseif unit < 100 then
unit = "0" .. unit
elseif unit >= 1000 then
unit = "999"
end
return unit
end
--[[unction getElementSpeed(element,unit)
if (unit == nil) then unit = 0 end
if (isElement(element)) then
local x,y,z = getElementVelocity(element)
if (unit=="mph" or unit==1 or unit =='1') then
return math.floor((x^2 + y^2 + z^2) ^ 0.5 * 100)
else
return math.floor((x^2 + y^2 + z^2) ^ 0.5 * 100 * 1.609344)
end
else
return false
end
end]]
function getElementSpeed(theElement, unit)
-- Check arguments for errors
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 == "kmh" or unit == "mph"), "Bad argument 2 @ getElementSpeed (invalid speed unit)")
-- Default to m/s if no unit specified and 'ignore' argument type if the string contains a number
unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit))
-- Setup our multiplier to convert the velocity to the specified unit
local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456)
-- Return the speed by calculating the length of the velocity vector, after converting the velocity to the specified unit
return (Vector3(getElementVelocity(theElement)) * mult).length
end
function shows_speed ()
if show_speed == false then
show_speed = true
showChat(false)
else
show_speed = false
showChat(true)
end
end