this is my speedometer with a fuel system.... problems : serverside: attempt to perform arithmetic on local data < a boolean value > .. : client : problem 2 : the speedo was working but now it is not.... problem 3 : i am trying to bind "j" to toggle the car engine but when the data of the fuel is 0 cancelEvent but it isn't working....
client :
function draw ()
if isPedInVehicle ( localPlayer ) then
local car = getPedOccupiedVehicle ( localPlayer )
local x, y, z = getElementPosition( localPlayer )
local sx, sy, sz = getElementVelocity ( car )
local kphSpeed = math.ceil( ( ( sx^2 + sy^2 + sz^2 ) ^ ( 0.5 ) ) * 161 )
local health = getElementHealth ( car )
local currenthealth = math.floor( health/10 )
local nitro = getVehicleNitroLevel(car)
local engine = getVehicleEngineState ( car )
local light = getVehicleOverrideLights ( car )
local fuel = getElementData ( car, "fuel" )
dxDrawLine(1006 - 1, 662 - 1, 1006 - 1, 692, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1238, 662 - 1, 1006 - 1, 662 - 1, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1006 - 1, 692, 1238, 692, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1238, 692, 1238, 662 - 1, tocolor(0, 0, 0, 255), 1, false)
dxDrawRectangle(1006, 662, 232, 30, tocolor(0, 0, 0, 100), false)
dxDrawLine(1006 - 1, 698 - 1, 1006 - 1, 728, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1238, 698 - 1, 1006 - 1, 698 - 1, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1006 - 1, 728, 1238, 728, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1238, 728, 1238, 698 - 1, tocolor(0, 0, 0, 255), 1, false)
dxDrawRectangle(1006, 698, 232, 30, tocolor(0, 0, 0, 100), false)
dxDrawLine(1006 - 1, 592 - 1, 1006 - 1, 622, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1238, 592 - 1, 1006 - 1, 592 - 1, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1006 - 1, 622, 1238, 622, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1238, 622, 1238, 592 - 1, tocolor(0, 0, 0, 255), 1, false)
dxDrawRectangle(1006, 592, 232, 30, tocolor(0, 0, 0, 100), false)
dxDrawRectangle(1006, 592, fuel*2.32, 30, tocolor(0, 255, 0, 100), false)
dxDrawLine(1006 - 1, 627 - 1, 1006 - 1, 657, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1238, 627 - 1, 1006 - 1, 627 - 1, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1006 - 1, 657, 1238, 657, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1238, 657, 1238, 627 - 1, tocolor(0, 0, 0, 255), 1, false)
dxDrawRectangle(1006, 627, 232, 30, tocolor(0, 0, 0, 100), false)
dxDrawRectangle(1006, 627, currenthealth*2.32, 30, tocolor(255, 0, 0, 100), false)
dxDrawLine(1006 - 1, 557 - 1, 1006 - 1, 587, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1238, 557 - 1, 1006 - 1, 557 - 1, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1006 - 1, 587, 1238, 587, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1238, 587, 1238, 557 - 1, tocolor(0, 0, 0, 255), 1, false)
dxDrawRectangle(1006, 557, 232, 30, tocolor(0, 0, 0, 100), false)
dxDrawRectangle(1006, 557, 232/161/0.5/2/1.5*kphSpeed, 30, tocolor(255, 255, 0, 100), false)
dxDrawImage(1010, 564, 23, 18, ":speed/images/speed.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
dxDrawImage(1010, 592, 22, 25, ":speed/images/fuel.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
dxDrawImage(1010, 634, 20, 18, ":speed/images/health.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
dxDrawImage(1010, 666, 16, 16, ":speed/images/lock.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
dxDrawImage(1010, 704, 16, 14, ":speed/images/engine.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
dxDrawText(tostring(kphSpeed).." KM/H ", 1090, 565, 1226, 549, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
dxDrawText(tostring(currenthealth).." % ", 1090, 635, 1226, 549, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
dxDrawText(tostring(fuel).." % ", 1090, 600, 1226, 549, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
if engine == true then
dxDrawText(" On ", 1090, 705, 1226, 549, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
else
dxDrawText(" Off ", 1090, 705, 1226, 549, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
end
if isVehicleLocked ( car ) then
dxDrawText("Locked ", 1090, 670, 1226, 549, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
else
dxDrawText("Unlocked ", 1090, 670, 1226, 549, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
end
end
end
addEventHandler("onClientRender", root, draw)
function nitro ()
local car = getPedOccupiedVehicle ( localPlayer )
local nitro = getVehicleNitroLevel(car)
if isPedInVehicle ( localPlayer ) then
if getVehicleUpgradeOnSlot ( car, 8 ) then
if nitro then
dxDrawLine(1006 - 1, 521 - 1, 1006 - 1, 551, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1238, 521 - 1, 1006 - 1, 521 - 1, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1006 - 1, 551, 1238, 551, tocolor(0, 0, 0, 255), 1, false)
dxDrawLine(1238, 551, 1238, 521 - 1, tocolor(0, 0, 0, 255), 1, false)
dxDrawRectangle(1006, 521, 232, 30, tocolor(0, 0, 0, 100), false)
dxDrawRectangle(1006, 521, 232/1*nitro, 30, tocolor(0, 255, 255, 100), false)
dxDrawImage(1010, 528, 16, 19, ":speed/images/nitro.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
dxDrawText(math.floor(nitro/1*100).."%", 1090, 527, 1226, 549, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
end
end
end
end
addEventHandler("onClientRender", root, nitro)
function nitro2 (key, keyState)
localplayer = getLocalPlayer()
if isPedInVehicle(localplayer) then
pVehicle = getPedOccupiedVehicle(localplayer)
if getVehicleUpgradeOnSlot(pVehicle, -- s8) --> then
if isVehicleNitroActivated(pVehicle) then
setVehicleNitroActivated (pVehicle, false)
end
end
end
end
bindKey ("mouse1", "up",nitro2)
function nitro3 (key, keyState)
localplayer = getLocalPlayer()
if isPedInVehicle(localplayer) then
pVehicle = getPedOccupiedVehicle(localplayer)
if getVehicleUpgradeOnSlot(pVehicle, -- s8) --> then
setVehicleNitroActivated (pVehicle, true)
end
end
end
bindKey ("mouse1", "down",nitro3)
function toggleEngine ( key, keyState )
local data = getElementData ( source, "fuel" )
setVehicleEngineState ( source, false )
else
setVehicleEngineState ( source, true )
if data == 0 then
cancelEvent()
end
end
bindKey ( "j", "down", toggleEngine )]
server :
function set ()
if getElementData ( source, "fuel" ) == false then
setElementData ( source, "fuel", tonumber(100) )
end
end
addEventHandler ( "onVehicleEnter",root,set )
function update ()
for i,v in pairs(getElementsByType("vehicle")) do
local data = getElementData ( v, "fuel" )
if getVehicleEngineState ( v ) == true and data ~= 0 then
setElementData ( v, "fuel", data - tonumber(1) )
end
if getVehicleEngineState ( v ) == false then
cancelEvent()
end
if data == tonumber(0) then
setVehicleEngineState ( v, false )
end
if data ~= tonumber(0) then
setVehicleEngineState ( v, true )
end
end
end
function starttimer ()
setTimer ( update, 1000, 0 )
end
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), starttimer )