Jump to content

debugscript message


MAB

Recommended Posts

i am making a speedometer and i found something very strange.. a debugscript message.. comes when there is not nitro in the vehicle that the player is in

Error:26: attempt to perform arithmetic on local 'nitro' (a boolean value)

although i did "if getVehicleUpgradeOnSlot(veh,8) then" it still coming

note: when i put nitro on the vehicle ... the "currenthealth" progress bar color works but when there is no nitro that color turns white and that is because of that debug message..

also i need help in the speed progress bar.. what should i do in the width? i am tried with it

local sx,sy = guiGetScreenSize () 
local x,y = (sx/1280),(sy/768) 
  
function draw () 
    if isPedInVehicle(localPlayer) then 
       local veh = getPedOccupiedVehicle(localPlayer) 
       local sx, sy, sz = getElementVelocity ( veh ) 
       local kphSpeed = math.ceil( ( ( sx^2 + sy^2 + sz^2 ) ^ ( 0.5 ) ) * 161 ) 
       local health = getElementHealth ( veh ) 
       local currenthealth = math.floor( health/10 ) 
       local engine = getVehicleEngineState ( veh ) 
       dxDrawImage(x*991, y*614, x*25, y*29, ":speed/images/settings.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) 
       dxDrawRectangle(x*991, y*536, x*185, y*29, tocolor(0, 0, 0, 100), false) 
       dxDrawRectangle(x*991, y*536, x*(currenthealth*1.85), y*29, color, false) 
       dxDrawRectangle(x*991, y*575, x*185, y*29, tocolor(0, 0, 0, 100), false) 
       dxDrawImage(x*992, y*576, x*24, y*28, ":speed/images/fuel.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) 
       dxDrawRectangle(x*992, y*497, x*185, y*29, tocolor(0, 0, 0, 100), false) 
       dxDrawImage(x*991, y*536, x*24, y*29, ":speed/images/wrench.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) 
       dxDrawRectangle(x*992, y*614, x*185, y*29, tocolor(0, 0, 0, 100), false) 
       dxDrawRectangle(x*991, y*653, x*185, y*29, tocolor(0, 0, 0, 100), false) 
       dxDrawImage(x*991, y*653, x*25, y*29, ":speed/images/lock.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) 
       dxDrawImage(x*992, y*497, x*28, y*29, ":speed/images/speed.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) 
        if getVehicleUpgradeOnSlot(veh,8) then 
           local nitro = getVehicleNitroLevel(veh) 
           dxDrawRectangle(x*991, y*458, x*185, y*29, tocolor(0, 0, 0, 100), false) 
           dxDrawRectangle(x*991, y*458, x*(185*nitro), y*29, tocolor(255, 255, 0, 255), false) 
           dxDrawImage(x*991, y*458, x*24, y*29, ":speed/images/nitro.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) 
        end 
        if (currenthealth >= 80) then 
            color = tocolor(0,255,0,255) 
        elseif (currenthealth < 80 and currenthealth >= 60) then 
            color = tocolor(150,255,0,255) 
        elseif (currenthealth < 60 and currenthealth >= 50) then 
            color = tocolor(255,215,0,255) 
        elseif (currenthealth < 50 and currenthealth >= 40) then 
            color = tocolor(255,69,0,255) 
        elseif (currenthealth <40 and currenthealth >= 30) then 
            color = tocolor(178,34,34,255) 
        elseif (currenthealth < 30) then 
            color = tocolor(50,0,0,255)       
        end 
    end 
end 
addEventHandler("onClientRender",root,draw) 

Link to comment
I think the function returns false even if the upgrade exists. As long as the nitro level is zero, it returns false.
local nitro = getVehicleNitroLevel(veh) or 0 

This should omit the error.

Bravo.. you were right and there is no message now

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