Jump to content

SpeedOmeter


Recommended Posts

Can somebody tells me what this error means?
Error: SAFshop\speedometer.lua:20 bad argument #1 to 'floor' (number expected, got nil)

Script:

Spoiler

local rx, ry = guiGetScreenSize ( )

function vehiclestatus ( )
	local theVehicle = getPedOccupiedVehicle ( localPlayer )
	if theVehicle and getPedOccupiedVehicleSeat (localPlayer) == 0 then
		local car = getPedOccupiedVehicle ( localPlayer )
		local currentFuel = tonumber(getElementData(car,"fuel"))
		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 mphSpeed = math.ceil( ( ( ( sx^2 + sy^2 + sz^2 ) ^ ( 0.5 ) ) * 161 ) / 1.61 )
		local health = getElementHealth ( car )
		local name = getVehicleName ( car )
		local currenthealth = math.floor( health/10 )
		-- dxDraw --
		dxDrawRectangle( ( rx-205 ), ( ry-78 ), 199, 17, tocolor(0, 0, 0, 180), true)
		dxDrawRectangle( ( rx-205 ), ( ry-54 ), 199, 17, tocolor(0, 0, 0, 180), true)
		dxDrawRectangle( ( rx-205 ), ( ry-30 ), 199, 17, tocolor(0, 0, 0, 180), true)
		dxDrawText ( "Speed: "..tostring(kphSpeed).." KM/H", ( rx - 199 ), ( ry - 77 ), 1280, 887, tocolor ( 255, 255, 255, 255 ), 1,"default-bold", "left", "top", false, false, true, true, false )
		dxDrawText ( "Vehicle: "..tostring(currenthealth).."% | Fuel: " .. math.floor(currentFuel) .. "%", ( rx - 199 ), ( ry - 53 ), 1280, 887, tocolor ( 255, 255, 255, 255 ), 1,"default-bold", "left", "top", false, false, true, true, false )
		dxDrawText ( "Location: " .. getZoneName(x, y, z), (rx - 199 ), ( ry - 29), 1280, 887, tocolor ( 255, 255, 255, 255 ), 1, "default-bold", "left", "top", false, false, true, true, false )
	end
end
addEventHandler ( "onClientRender", root, vehiclestatus )

 

 

Link to comment

Yes now i know what the error means :P
But still don't understand why it has no number.

This is a function of a other script (same resource):
 

Spoiler

function setFuel(player,seat,jacked,vehicle)
	if(getElementData(source,"fuel") == false) then
		fuel = math.random(70,100)
		setElementData(source,"fuel",tonumber(fuel))
	end
end
addEventHandler("onClientVehicleEnter",getRootElement(),setFuel)

 

 

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