local screenWidth, screenHeight = guiGetScreenSize()
local counter = 0
local starttick
local currenttick
local thePlayer = getLocalPlayer()
local poz1, poz2 = 74, 41
local playerElement
 
function createText()
	if not starttick then
		starttick = getTickCount()
	end
		counter = counter + 1
		currenttick = getTickCount()
	if currenttick - starttick >= 1000 then
		setElementData(thePlayer,"Fps",counter)
		counter = 0
		starttick = false
	end
	-------------------------------------------------------------
	local time = getRealTime()
	local hours = time.hour
	if hours < 10 then hours = "0"..hours end
	local minutes = time.minute
	if minutes < 10 then minutes = "0"..minutes end
	local seconds = time.second
	if seconds < 10 then seconds = "0"..seconds end
	-------------------------------------------------------------
	local pingContent = getPlayerPing(thePlayer)
	local fpsContent = getElementData(thePlayer,"Fps") or "0"
	
	if getElementData(localPlayer, "state") == "dead" then 
		playerElement = getCameraTargetPlayer() 
		if isElement(playerElement) then
			pingContent = getPlayerPing(playerElement)
			fpsContent = getElementData(playerElement,"Fps") or "0"
		end
	else 
		playerElement = localPlayer 
	end
	
	-------------------------------------------------------------
	local fps = tonumber(fpsContent) - 25
				b1 = 0
				if fps >= 25 then
					r1, g1 = 0, 255
				elseif fps <= 0 then
					r1, g1 = 255, 0
				elseif fps <= 12 then
					r1 = 255
					g1 = 255 - 255 * (12 - fps) / 12
				else
					r1 = 255 * (12 - fps) / 12
					g1 = 255
				end
	
	local ping = tonumber(pingContent)
				b2 = 0
				if ping <= 50 then
					r2, g2 = 0, 255
				elseif ping > 350 then
					r2, g2 = 255, 0
				elseif ping <= 200 then
					r2 = 255 * (ping-50) / 150
					g2 = 255
				else
					r2 = 255
					g2 = 255 - 255 * (ping-200) / 150
				end
	if pingContent > 100 then
		poz1 = 77
		poz2 = 46
	elseif pingContent > 999 then
		pingContent = "999+"
		poz1 = 79
		poz2 = 48
	end
	
	
	local time = getRealTime()
local hour = time.hour
local minute = time.minute
local second = time.second
local fp = getElementData(getLocalPlayer(),"FPS")
local pi = getPlayerPing(getLocalPlayer())
local online = #getElementsByType("player")
local maxo = 32
end
function getCameraTargetPlayer()
	local element = getCameraTarget()
	
	if element and getElementType(element) == "vehicle" then
		element = getVehicleController(element)
	end
	return element
end
local screenW, screenH = guiGetScreenSize()
local playerElement
local vehicleNos = 0
function Vel()
	if getElementData(localPlayer, "state") == "dead" then 
		playerElement = getCameraTargetPlayer() 
	else 
		playerElement = localPlayer 
	end
	local resourceNos = getResourceFromName("Nos")
	
	if not isElement(playerElement) then
	    vehicleNos = 0
		vehicleSpeed = 0
		vehSpeedForLenght = 0		
		vehicleHealth = 0
		healthR, healthG = getRGColorFromPercentage(vehicleHealth)
	else
		local pVeh = getPedOccupiedVehicle(playerElement)
		if isElement(pVeh) then
			local nos = 0
			local nosStyle = ""
			if (resourceNos) then
				if (getResourceState(resourceNos) == "running") then
					nos = exports["Nos"]:getVehicleNitro() or 0
				else
					nos = 0
				end
			end
			if nos then
				vehicleNos = math.floor(nos)
			end
			vehicleSpeed = getVehicleSpeed(pVeh)
			vehSpeedForLenght = math.floor(vehicleSpeed)
			if vehSpeedForLenght > 240 then
				vehSpeedForLenght = 240
			end
			vehicleHealth = getVehicleHealth(pVeh)
			healthR, healthG = getRGColorFromPercentage(vehicleHealth)
		end
	end
	
	if (resourceNos) then
		if (getResourceState(resourceNos) == "running") then
			nosStyle = string.upper(exports["Nos"]:getVehicleNitroStyle()) or ""
		else
			nosStyle = ""
		end
	end
	local r1,g1,b1 = 0, 0, 0
	if nosStyle == "NFS" then
		r1,g1,b1 = 196, 113, 54
	elseif nosStyle == "NORMAL" then
		r1,g1,b1 = 54, 116, 196
	elseif nosStyle == "HYBRID" then
		r1,g1,b1 = 196, 54, 54
	end
		dxDrawLinedRectangle(screenW-185, 10, 170, 22, tocolor(0, 0, 0, 255), true)
		dxDrawRectangle(screenW-185, 10, 170, 22, tocolor(0, 0, 0, 100), true)
		dxDrawRectangle(screenW-184, 11, 169/100*vehicleHealth, 21, tocolor(healthR, healthG, 0, 230), true)
		dxDrawText("Can: "..vehicleHealth.."%", (screenW*2)-290, 24, 100, 20, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false)
		dxDrawText("Can: "..vehicleHealth.."%", (screenW*2)-290, 23, 100, 20, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false)
		dxDrawLinedRectangle(screenW-185, 45, 170, 22, tocolor(0, 0, 0, 255), true)
		dxDrawRectangle(screenW-185, 45, 170, 22, tocolor(0, 0, 0, 100), true)
		dxDrawRectangle(screenW-184, 46, 169/240*vehSpeedForLenght, 21, tocolor(66, 133, 244, 230), true)
		dxDrawText("Hız: "..vehicleSpeed.." km/h", (screenW*2)-290, 94, 100, 20, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false)
		dxDrawText("Hız: "..vehicleSpeed.." km/h", (screenW*2)-290, 93, 100, 20, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false)
	
		if vehicleNos > 0 and (not justHealth) then
		dxDrawLinedRectangle(screenW-185, 80-(2), 110, 22, tocolor(0, 0, 0, 255), true)
		dxDrawRectangle(screenW-185, 80-(2), 110, 22, tocolor(0, 0, 0, 100), true)
		dxDrawRectangle(screenW-184, 81-(2), 109/100*vehicleNos, 21, tocolor(232, 60, 60, 230), true)
		dxDrawLinedRectangle3(screenW-184, 81-(2), 109/100*vehicleNos, 21, tocolor(0, 0, 0), true)
		dxDrawText("Nitro: "..vehicleNos.." sec", (screenW*2)-355, 161, 100, 20, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false)
		dxDrawText("Nitro: "..vehicleNos.." sec", (screenW*2)-355, 160, 100, 20, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false)
	
		dxDrawLinedRectangle2(screenW-74, 80-(2), 60, 22, tocolor(0, 0, 0, 255), true)
		dxDrawRectangle(screenW-74, 81-(2), 60, 21, tocolor(r1,g1,b1, 255), true)
		dxDrawText(nosStyle, (screenW*2)-185, 161, 100, 20, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false)
		dxDrawText(nosStyle, (screenW*2)-185, 160, 100, 20, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false)
		end
end
addEventHandler("onClientResourceStart", resourceRoot, function()
	removeEventHandler("onClientRender", root, Vel)
	addEventHandler("onClientRender", root, Vel)
	
	removeEventHandler("onClientRender", root, createText)
	addEventHandler("onClientRender", root, createText)
end)
function dxDrawLinedRectangle(x, y, width, height, color, postGUI)
	local _width = 1
	dxDrawLine ( x, y, x+width, y, color, _width, postGUI ) -- Top
	dxDrawLine ( x, y, x, y+height, color, _width, postGUI ) -- Left
	dxDrawLine ( x, y+height, x+width, y+height, color, _width, postGUI ) -- Bottom
	dxDrawLine ( x+width, y, x+width, y+height, color, _width, postGUI ) -- Right
end
function dxDrawLinedRectangle2(x, y, width, height, color, postGUI)
	local _width = 1
	dxDrawLine ( x, y, x+width, y, color, _width, postGUI ) -- Top
	dxDrawLine ( x, y+height, x+width, y+height, color, _width, postGUI ) -- Bottom
	dxDrawLine ( x+width, y, x+width, y+height, color, _width, postGUI ) -- Right
end
function dxDrawLinedRectangle3(x, y, width, height, color, postGUI)
	local _width = 1
	dxDrawLine ( x+width, y, x+width, y+height, color, _width, postGUI ) -- Right
end
function getVehicleSpeed(vehicle)
    local velX, velY, velZ = getElementVelocity(vehicle) 
    return math.floor(math.sqrt( (velX * velX) + (velY * velY) + (velZ * velZ) ) * 160)
end
function getVehicleHealth(vehicle)
	local health = getElementHealth(vehicle) - 250
	local vehicleHealth = math.floor(health / 750 * 100)
	if vehicleHealth < 0 then vehicleHealth = 0 end
	return vehicleHealth
end
function getRGColorFromPercentage(percentage)
	if not percentage or
		percentage and type(percentage) ~= "number" or
		percentage > 100 or percentage < 0 then
		outputDebugString( "Invalid argument @ 'getRGColorFromPercentage'", 2)
		return false
	end
 
	if percentage > 50 then
		local temp = 100 - percentage
		return temp*5.1, 180
	elseif percentage == 50 then
		return 230, 180
	end
 
	return 230, percentage*5.1
end