Jump to content

Error o menu não aparece e da esse error.


Recommended Posts

E um sistema de customizar o veiculo, mas quando entro no marker algumas partes do menu não aparecem e esse erro ocorre.
66YeEpf.png

function formatNumber(amount, spacer)
	if not spacer then
		spacer = ","
	end

	amount = math.floor(amount) ---aqui esta apontando o erro

	local left, num, right = string.match(tostring(amount), "^([^%d]*%d)(%d*)(.-)$")
	return left .. (num:reverse():gsub("(%d%d%d)", "%1" .. spacer):reverse()) .. right
end

 

Link to comment
2 minutes ago, murilo2929 said:

E um sistema de customizar o veiculo, mas quando entro no marker algumas partes do menu não aparecem e esse erro ocorre.
66YeEpf.png


function formatNumber(amount, spacer)
	if not spacer then
		spacer = ","
	end

	amount = math.floor(amount) ---aqui esta apontando o erro

	local left, num, right = string.match(tostring(amount), "^([^%d]*%d)(%d*)(.-)$")
	return left .. (num:reverse():gsub("(%d%d%d)", "%1" .. spacer):reverse()) .. right
end

 

Poste o código por completo.

Link to comment
13 minutes ago, MesaDowN said:

Poste o código por completo.

local screenX, screenY = guiGetScreenSize()

local scaleFactor = screenX / screenX

local tuningMarkers = {}
local tuningMarkersCount = 0
local isBuyyedPainjob = false
local markerImageMaxVisibleDistance = 30
local chargerElement = nil

local totalUpgradeWidth = 0
local acceptedTuningCreate = false
local tuningCompleted = true
--[[
if fileExists("sourceC.Lua") then
	fileDelete("sourceC.Lua")
end
]]
local Roboto = dxCreateFont("files/fonts/Roboto.ttf", 26)
local font = dxCreateFont(":sas_hud/files/fonts/RobotoB.ttf", 26)
local Roboto2 = dxCreateFont("files/fonts/Roboto.ttf", 20)
local RobotoL = dxCreateFont(":sas_hud/files/fonts/Roboto.ttf", 20)

local availableTextures = {
	["logo"] = dxCreateTexture("files/images/logo.png", "argb", true, "clamp"),
	["hoveredrow"] = dxCreateTexture("files/images/hoveredrow.png", "argb", true, "clamp"),
	["menunav"] = dxCreateTexture("files/images/menunav.png", "argb", true, "clamp"),
	["mouse"] = dxCreateTexture("files/images/navbar/mouse.png", "argb", true, "clamp"),
}

local availableIcons = {
	["wrench"] = "",
	["long-arrow-up"] = "",
	["long-arrow-down"] = "",
	["info-circle"] = "",
	["check"] = "",
	["exclamation-triangle"] = "",
}

local panelState = false
local enteredVehicle = false
local availableFonts = nil

local panelWidth, rowHeight = 395 * scaleFactor, 40 * scaleFactor
local panelX, panelY = 32, 78
local logoHeight = 20
local s = {guiGetScreenSize()}
local navX, navY = s[1]/2+380, s[2]-70

local hoveredCategory, selectedCategory, selectedSubCategory = 1, 0, 0
local maxRowsPerPage, currentPage = 7, 1

local compatibleOpticalUpgrades = {}
local equippedTuning = 1

local navbarButtonHeight = 30 * scaleFactor
local navigationBar = {
	{"", {"Enter"}, false},
	{"", {"long-arrow-up", "long-arrow-down"}, true},
	{"", {"Backspace"}, false},
	{getLocalizedText("navbar.camera"), {"mouse"}, "image", 30}
}

local noticeData = {
	["text"] = false,
	["type"] = "info",
	["tick"] = 0,
	["state"] = "",
	["height"] = 0,
	["timer"] = nil
}

local cameraSettings = {}

local promptDialog = {
	["state"] = false,
	["itemName"] = "",
	["itemPrice"] = 0
}

local availableOffroadAbilities = {
	["dirt"] = {0x100000, 2},
    ["sand"] = {0x200000, 3}
}

local availableWheelSizes = {
	["front"] = {
		["verynarrow"] = {0x100, 1},
		["narrow"] = {0x200, 2},
		["wide"] = {0x400, 4},
		["verywide"] = {0x800, 5}
	},
	["rear"] = {
		["verynarrow"] = {0x1000, 1},
		["narrow"] = {0x2000, 2},
		["wide"] = {0x4000, 4},
		["verywide"] = {0x8000, 5}
	}
}

local savedVehicleColors = {["all"] = false, ["headlight"] = false}
local moneyChangeTable = {["tick"] = 0, ["amount"] = 0}

local vehicleNumberplate = ""

addEvent("tuning->ShowMenu", true)
addEvent("tuning->HideMenu", true)



addEventHandler("onClientResourceStart", resourceRoot, function()
	for _, value in ipairs(getElementsByType("marker", root, true)) do
		if getElementData(value, "tuningMarkerSettings") then
			tuningMarkers[value] = true
			tuningMarkersCount = tuningMarkersCount + 1
		end
	end

	actualPaintJob = 0
	defaultPaintJob = actualPaintJob

	for i = 1, 4 do
		table.insert(tuningMenu[getMainCategoryIDByName(getLocalizedText("menu.color"))]["subMenu"], {
			["categoryName"] = getLocalizedText("menu.color") .. " " .. i,
			["tuningPrice"] = 15000,
			["tuningData"] = "color" .. i
		})
	end
end)

addEventHandler("onClientResourceStop", resourceRoot, function()
	if panelState and enteredVehicle then
		resetOpticalUpgrade()
		setVehicleColorsToDefault()
		triggerEvent("tuning->HideMenu", localPlayer)
	end
end)

addEventHandler("onClientElementStreamIn", root, function()
	if getElementType(source) == "marker" then
		if getElementData(source, "tuningMarkerSettings") then
			tuningMarkers[source] = true
			tuningMarkersCount = tuningMarkersCount + 1
		end
	end
end)

addEventHandler("onClientElementStreamOut", root, function()
	if getElementType(source) == "marker" then
		if getElementData(source, "tuningMarkerSettings") then
			tuningMarkers[source] = nil
			tuningMarkersCount = tuningMarkersCount - 1
		end
	end
end)

local moneyLoss = 0
local moneyLosing = false

local ppLoss = 0
local ppLosing = false


addEventHandler("onClientElementDataChange", localPlayer, function(dataName, oldValue)
	if not getElementData(localPlayer, "loggedin") then return end
	if dataName == "money" then
		local newMoney = exports.global:getMoney(localPlayer)
		moneyLoss = newMoney - (oldValue or 0)
		if moneyLoss < 0 then
			moneyLosing = true
			setTimer ( function()
				moneyLosing = false
			end, 3500, 1 )
		end
	elseif dataName == "pp" then
		local newPP = getElementData(localPlayer,"pp")
		ppLoss = newPP - (oldValue or 0)
		if ppLoss < 0 then
			ppLosing = true
			setTimer ( function()
				ppLosing = false
			end, 3500, 1 )
		end
	end
end)

function math.round(number)
    local _, decimals = math.modf(number)
    if decimals < 0.5 then return math.floor(number) end
    return math.ceil(number)
end

local selectR, selectG,selectB = 96,163,91

local lastTickLoading = 0
local tuningText = "Felszerelés..."
local loadingSpeed = 2
local wantedMinutes = 6000
function putTuningOn()
		if acceptedTuningCreate and not tuningCompleted then
			local cTick = getTickCount ()
			local progress = (cTick - lastTickLoading)/wantedMinutes
			totalUpgradeWidth,_,_ = interpolateBetween (
				0,0,0,
				400,0,0,
				progress,"Linear"
			)
			dxDrawRectangle(s[1]/2-200, s[2]-115, 400, 30, tocolor(0,0,0,180))
			dxDrawRectangle(s[1]/2-200, s[2]-115, totalUpgradeWidth, 30, tocolor(96,163,91,255))
			dxDrawText(tuningText, s[1]/2-200, s[2]-115, s[1]/2+200, s[2]-115+30, tocolor(255,255,255,255), 0.52, RobotoL, "center", "center")
			if math.round(totalUpgradeWidth) ~= 400 then
				totalUpgradeWidth = totalUpgradeWidth + loadingSpeed
			end
			if math.round(totalUpgradeWidth) >= 400 then
		--		totalUpgradeWidth = 400
				tuningCompleted = true
			end
		end
end
addEventHandler("onClientRender", getRootElement(), putTuningOn)
local szorzas = 1
local lastTick2 = 0
local csuszas = false
addEventHandler("onClientRender", root, function()
	--** Tuning marker image

		local cameraX, cameraY, cameraZ = getCameraMatrix()

	-- ** Tuning menu
	if panelState and enteredVehicle then

		dxDrawRectangle(0,0,screenX,105,tocolor(0,0,0,180))
		dxDrawRectangle(0,screenY-70,screenX,70,tocolor(0,0,0,180))
		dxDrawImage(0,0,100,100,"files/images/logo.png")
		dxDrawText("#7cc576MTATESTE V3 #ffffff- Tuning", screenX/screenX+120, screenY/screenY+25, 0, 0, tocolor(255,255,255,255), 1.3, Roboto, nil,nil,false, false, true, true)

		--> Current Money
		local moneyWidth = dxGetTextWidth(formatNumber(exports.global:getMoney(localPlayer)):gsub(","," "), 0.5, Roboto2)
		if moneyLosing then
			dxDrawText("#d9534f(#d9534f" .. moneyLoss .. " #d9534f$)",panelX+screenX-200-200+moneyWidth+15, panelY+132-178, panelX + screenX + (panelX * 2), panelY-178 + screenY - (panelY * 2), tocolor(189, 227, 188, 255), 0.5, Roboto2, "left", "top", false, false, false, true)
		end

		local ppWidth = dxGetTextWidth(formatNumber(getElementData(localPlayer,"pp")):gsub(","," "), 0.5, Roboto2)
		if ppLosing then
			dxDrawText("#d9534f(#d9534f" .. ppLoss .. " #d9534fPP)",panelX+screenX-200-200+ppWidth+40, panelY+132-178+40, panelX + screenX + (panelX * 2), panelY-178 + screenY - (panelY * 2), tocolor(189, 227, 188, 255), 0.5, Roboto2, "left", "top", false, false, false, true)
		end

		dxDrawText("#7cc576Készpénz:",panelX+screenX-200-200, panelY-20+132-178, panelX-200 + screenX, panelY + screenY - (panelY * 2)-20-178, tocolor(189, 227, 188, 255), 0.5, Roboto2, "left", "top", false, false, false, true)
		dxDrawText("#ffffff" .. formatNumber(exports.global:getMoney(localPlayer)):gsub(","," ") .. " #7cc576$",panelX+screenX-200-200, panelY+132-178, panelX + screenX + (panelX * 2), panelY-178 + screenY - (panelY * 2), tocolor(189, 227, 188, 255), 0.5, Roboto2, "left", "top", false, false, false, true)
		dxDrawText("#3f8bb0Prémium Pont:", panelX+screenX-200-200, panelY+132-20+20+20-178, panelX-200 + screenX - (panelX * 2), panelY-178 + screenY - (panelY * 2)-20, tocolor(189, 227, 188, 255), 0.5, Roboto2, "left", "top", false, false, false, true)
		dxDrawText("#ffffff" .. formatNumber(getElementData(localPlayer,"pp")or 0) .. " #3f8bb0PP", panelX+screenX-200-200, panelY+40+132-178, panelX + screenX + (panelX * 2), panelY-178 + screenY - (panelY * 2), tocolor(189, 227, 188, 255),0.5, Roboto2, "left", "top", false, false, false, true)

		--> Notification
		if noticeData["text"] then
			if noticeData["state"] == "showNotice" then
				local animationProgress = (getTickCount() - noticeData["tick"]) / 300
				local animationState = interpolateBetween(0, 0, 0, logoHeight * scaleFactor, 0, 0, animationProgress, "Linear")

				noticeData["height"] = animationState

				if animationProgress > 1 then
					noticeData["state"] = "fixNoticeJumping"

					noticeData["timer"] = setTimer(function()
						noticeData["tick"] = getTickCount()
						noticeData["state"] = "hideNotice"
					end, string.len(noticeData["text"]) * 50, 1)
				end
			elseif noticeData["state"] == "hideNotice" then
				local animationProgress = (getTickCount() - noticeData["tick"]) / 300
				local animationState = interpolateBetween(logoHeight * scaleFactor, 0, 0, 0, 0, 0, animationProgress, "Linear")

				noticeData["height"] = animationState

				if animationProgress > 1 then
					noticeData["text"] = false
				end
			elseif noticeData["state"] == "fixNoticeJumping" then
				noticeData["height"] = (logoHeight * scaleFactor)
			end
			fix = 0
			if noticeData["text"] then
				fix = 20+ dxGetTextWidth(noticeData["text"], 0.5, availableFonts["chalet"])/2
				roundedRectangle(s[1]/2 -fix, 30,40+ dxGetTextWidth(noticeData["text"], 0.5, availableFonts["chalet"]), noticeData["height"], tocolor(0, 0, 0, 120))
			end
			if noticeData["height"] == (logoHeight * scaleFactor) then
				local noticeIcon, iconColor = "", {255, 255, 255}

				if noticeData["type"] == "info" then
					noticeIcon, iconColor = availableIcons["info-circle"], {85, 178, 243}
				elseif noticeData["type"] == "warning" then
					noticeIcon, iconColor = availableIcons["exclamation-triangle"], {220, 190, 120}
				elseif noticeData["type"] == "error" then
					noticeIcon, iconColor = availableIcons["exclamation-triangle"], {200, 80, 80}
				elseif noticeData["type"] == "success" then
					noticeIcon, iconColor = availableIcons["check"], {130, 220, 115}
				end

				dxDrawText(noticeIcon, s[1]/2+5 -fix, 30+5,0,0, tocolor(iconColor[1], iconColor[2], iconColor[3], 255), 1.0, availableFonts["icons"], "left", "top")
				dxDrawText(noticeData["text"], s[1]/2+35 -fix, 30+2, 0,0 , tocolor(255, 255, 255, 255), 0.5, availableFonts["chalet"], "left", "top", false, true)
			end
		end

		loopTable, categoryCount, categoryName = {}, 0, "N/A"

		if selectedCategory == 0 then
			loopTable = tuningMenu
			categoryName = ""

			navigationBar[1][1] = getLocalizedText("navbar.select")
			navigationBar[3][1] = getLocalizedText("navbar.exit")
		elseif selectedCategory ~= 0 and selectedSubCategory == 0 then
			loopTable = tuningMenu[selectedCategory]["subMenu"]
			categoryName = tuningMenu[selectedCategory]["categoryName"]

			if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.color")) then -- Color
				navigationBar[1][1] = getLocalizedText("navbar.buy")
			else
				navigationBar[1][1] = getLocalizedText("navbar.select")
			end

			navigationBar[3][1] = getLocalizedText("navbar.back")
		elseif selectedCategory ~= 0 and selectedSubCategory ~= 0 then
			if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.optical")) then -- Optical
				if isGTAUpgradeSlot(tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["upgradeSlot"]) then
					loopTable = tuningMenu[selectedCategory]["availableUpgrades"]
					categoryName = tuningMenu[selectedCategory]["categoryName"]
				else
					loopTable = tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["subMenu"]
					categoryName = tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["categoryName"]
				end
			else
				loopTable = tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["subMenu"]
				categoryName = tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["categoryName"]
			end

			navigationBar[1][1] = getLocalizedText("navbar.buy")
			navigationBar[3][1] = getLocalizedText("navbar.back")
		end

		--> Current category
		local panelY = panelY + (logoHeight * scaleFactor)

		--dxDrawRectangle(panelX, panelY, panelWidth, rowHeight, tocolor(0, 0, 0, 255))
		--dxDrawText(utf8.upper(categoryName), panelX + 10, panelY, panelX + 10 + panelWidth - 20, panelY + rowHeight, tocolor(255, 255, 255, 255), 0.5, availableFonts["chalet"], "left", "center", false, false, false, true)
		--dxDrawText(hoveredCategory .. " / " .. #loopTable, panelX + 10, panelY, panelX + 10 + panelWidth - 20, panelY + rowHeight, tocolor(255, 255, 255, 255), 0.5, availableFonts["chalet"], "right", "center", false, false, false, true)

		--> Menu rows
		local panelY = panelY + rowHeight

		for id, row in ipairs(loopTable) do
			if id >= currentPage and id <= currentPage + maxRowsPerPage then
				local rowX, rowY, rowWidth, rowHeight = panelX, panelY + (categoryCount * rowHeight), panelWidth, rowHeight

				if selectedCategory == 0 or selectedSubCategory == 0 then
					equippedUpgrade = -1
				elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.optical")) then
					if isGTAUpgradeSlot(tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["upgradeSlot"]) then
						if row["upgradeID"] == equippedTuning then
							equippedUpgrade = id
						end
					else
						if id == equippedTuning then
							equippedUpgrade = id
						end
					end
				else
					if id == equippedTuning then
						equippedUpgrade = id
					end
				end
				local keretVariable = rowHeight*id
				if  id > 8 then
					keretVariable = rowHeight*8
				end
				exports.sas_system:radarKeret(panelX, panelY, panelWidth, keretVariable, 2, 255)

				if row["categoryName"] == "Teljesítmény" then
					kep = "teljesitmeny.png"
				elseif row["categoryName"] == "Optika" then
					kep = "optika.png"
				elseif row["categoryName"] == "Fényezés" then
					kep = "fenyezes.png"
				elseif row["categoryName"] == "Extrák" then
					kep = "extra.png"
				elseif row["categoryName"] == "Motor" then
					kep = "performance/motor.png"
				elseif row["categoryName"] == "Turbó" then
					kep = "performance/turbo.png"
				elseif row["categoryName"] == "ECU" then
					kep = "performance/ecu.png"
				elseif row["categoryName"] == "Váltó" then
					kep = "performance/valto.png"
				elseif row["categoryName"] == "Felfüggesztés" then
					kep = "performance/felfugg.png"
				elseif row["categoryName"] == "Fékek" then
					kep = "performance/fek.png"
				elseif row["categoryName"] == "Gumik" then
					kep = "performance/gumi.png"
				elseif row["categoryName"] == "Nitro" then
					kep = "performance/nitro.png"
				elseif row["categoryName"] == "25%" then
					kep = "performance/nitro.png"
				elseif row["categoryName"] == "50%" then
					kep = "performance/nitro.png"
				elseif row["categoryName"] == "75%" then
					kep = "performance/nitro.png"
				elseif row["categoryName"] == "100%" then
					kep = "performance/nitro.png"
				elseif row["categoryName"] == "Súlycsökkentés" then
					kep = "performance/sulycsokkentes.png"
				elseif row["categoryName"] == "Turbó" then
					kep = "performance/turbo.png"
				elseif row["categoryName"] == "Turbó" then
					kep = "performance/turbo.png"
				-- Fényezés
				elseif row["categoryName"] == "Fényezés 1" then
					kep = "fenyezes.png"
				elseif row["categoryName"] == "Fényezés 2" then
					kep = "fenyezes.png"
				elseif row["categoryName"] == "Fényezés 3" then
					kep = "fenyezes.png"
				elseif row["categoryName"] == "Fényezés 4" then
					kep = "fenyezes.png"

				--basic
				elseif equippedUpgrade == id then
					kep = "felszerelt.png"
				elseif row["categoryName"] == "Gyári" then
					kep = "free.png"
				elseif row["categoryName"] == "Alap csomag" or row["categoryName"] == "Profi csomag" or row["categoryName"] == "Verseny csomag" then
					kep = "dollar.png"
				elseif row["categoryName"] == "Venom csomag" then
					kep = "pp.png"

				--optical
				elseif row["categoryName"] == "Első lökhárító" then
					kep = "optical/elso.png"
				elseif row["categoryName"] == "Hátsó lökhárító" then
					kep = "optical/hatso.png"
				elseif row["categoryName"] == "Küszöb" then
					kep = "optical/kuszob.png"
				elseif row["categoryName"] == "Motorháztető" then
					kep = "optical/motorhaz.png"
				elseif row["categoryName"] == "Légterelő" then
					kep = "optical/legterelo.png"
				elseif row["categoryName"] == "Tetőlégterelő" then
					kep = "optical/tetolegterelo.png"
				elseif row["categoryName"] == "Kerekek" then
					kep = "optical/felni.png"
				elseif row["categoryName"] == "Kipufogó" then
					kep = "optical/kipufogo.png"
				elseif row["categoryName"] == "Hidraulika" then
					kep = "optical/hidra.png"
				elseif row["categoryName"] == "Air-Ride" then
					kep = "optical/airride.png"
				elseif row["categoryName"] == "Neon" then
					kep = "optical/neon.png"
				elseif row["categoryName"] == "Izzó szín" then
					kep = "optical/izzo.png"
			--	elseif row["categoryName"] == "Fehér" or row["categoryName"] == "Kék" or row["categoryName"] == "Zöld" or row["categoryName"] == "Piros" or row["categoryName"] == "Citromsárga" or row["categoryName"] == "Rózsaszín" or row["categoryName"] == "Narancssárga" or row["categoryName"] == "Világoskék" or row["categoryName"] == "Raszta" or row["categoryName"] == "Fehér + Világoskék" then
				elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.optical")) then
					if selectedSubCategory == 11 then
						kep = "optical/neon.png"
					elseif selectedSubCategory == 1 then
						kep = "optical/elso.png"
					elseif selectedSubCategory == 2 then
						kep = "optical/hatso.png"
					elseif selectedSubCategory == 3 then
						kep = "optical/kuszob.png"
					elseif selectedSubCategory == 4 then
						kep = "optical/motorhaz.png"
					elseif selectedSubCategory == 5 then
						kep = "optical/legterelo.png"
					elseif selectedSubCategory == 6 then
						kep = "optical/tetolegterelo.png"
					elseif selectedSubCategory == 7 then
						kep = "optical/felni.png"
					elseif selectedSubCategory == 8 then
						kep = "optical/kipufogo.png"
					elseif selectedSubCategory == 9 then
						kep = "optical/hidra.png"
					elseif selectedSubCategory == 12 then
						kep = "optical/airride.png"
					end
				elseif row["categoryName"] == "Első kerék szélessége" then
					kep = "optical/gumiszelesseg.png"
				elseif row["categoryName"] == "Hátsó kerék szélessége" then
					kep = "optical/gumiszelesseg.png"
				elseif row["categoryName"] == "Offroad optimalizáció" then
					kep = "optical/offroad.png"
				elseif row["categoryName"] == "Meghajtás" then
					kep = "optical/meghajtas.png"
				elseif row["categoryName"] == "Variáns" then
					kep = "variant.png"
				elseif row["categoryName"] == "Paintjob" then
					kep = "fenyezes.png"
				elseif row["categoryName"] == "LSD Ajtó" then
					kep = "optical/lsd.png"
				elseif row["categoryName"] == "Gyári rendszám" then
						kep = "free.png"
				elseif row["categoryName"] == "Egyedi rendszám" then
						kep = "pp.png"
				elseif row["categoryName"] == "Rendszám" then
					kep = "optical/plate.png"
				elseif row["categoryName"] == "Fordulási szög" then
					kep = "slock.png"
				elseif row["categoryName"] == "Traffipax radar" then
					kep = "speedo.png"
				elseif row["categoryName"] == "SeeGO navigációs rendszer" then
					kep = "gps.png"
				elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.extras")) then
					if selectedSubCategory == 1 then
						kep = "optical/gumiszelesseg.png"
					elseif selectedSubCategory == 2 then
							kep = "optical/gumiszelesseg.png"
					elseif selectedSubCategory == 3 then
							kep = "optical/offroad.png"
					elseif selectedSubCategory == 4 then
							kep = "optical/meghajtas.png"
					elseif selectedSubCategory == 5 then
							kep = "variant.png"
					elseif selectedSubCategory == 6 then
							kep = "pp.png"
					elseif selectedSubCategory == 7 then
							kep = "optical/lsd.png"
					elseif selectedSubCategory == 8 then
							kep = "slock.png"
					elseif selectedSubCategory == 10 then
							kep = "speedo.png"
					elseif selectedSubCategory == 11 then
							kep = "gps.png"
					end
				else
						kep = "misc.png"
				end

			--	if hoveredCategory ~= id then
					if categoryCount %2 == 0 then
						dxDrawRectangle(rowX, rowY, rowWidth, rowHeight, tocolor(0, 0, 0, 150))
						dxDrawImage(rowX+2, rowY+2, 32,32, "files/icons/"..kep,0,0,0,tocolor(255,255,255,255),true)
					else
						dxDrawRectangle(rowX, rowY, rowWidth, rowHeight, tocolor(0, 0, 0, 255))
						dxDrawImage(rowX+2, rowY+2, 32,32, "files/icons/"..kep,0,0,0,tocolor(255,255,255,255),true)
					end
			--	end
				local cTick = getTickCount ()
				local progress = (cTick - lastTick2)/300
				szorzas = hoveredCategory
				if hoveredCategory >= 8 then
					szorzas = 8
				end
				if not arrowFel and szorzas <= 8 then
			  	_,plusY,_ = interpolateBetween (
						0,panelY-80+(40*szorzas),0,
						0,panelY-80+(40*szorzas)+40,0,
						progress,"Linear"
						)
				end
				if arrowFel and szorzas < 8 then
					_,plusY,_ = interpolateBetween (
						0,panelY-80+(40*(szorzas+1))+40,0,
						0,panelY-80+(40*szorzas)+40,0,
						progress,"Linear"
						)
				end
				if arrowFel and szorzas >= 8 then
					_,plusY,_ = interpolateBetween (
						0,panelY-80+(40*(szorzas))+40,0,
						0,panelY-80+(40*szorzas)+40,0,
						progress,"Linear"
						)
				end
				--outputChatBox(hoveredCategory)
				--outputChatBox(#loopTable)
				dxDrawImage(panelX, plusY, panelWidth, 40, availableTextures["hoveredrow"],0,0,0,tocolor(selectR, selectG,selectB,255))
				if hoveredCategory ~= id then


					--dxDrawText(row["categoryName"], rowX, rowY, rowX+rowWidth-15, rowY + rowHeight, tocolor(255, 255, 255, 255), 0.5, availableFonts["chalet"], "right", "center", false, false, false, true)

					if equippedUpgrade ~= id then
						--if row["tuningPrice"] then
						--	if row["tuningPrice"] == 0 then
								--dxDrawText(getLocalizedText("tuningPrice.free"), rowX + 15, rowY, rowX , rowY + rowHeight, tocolor(198, 83, 82, 255), 0.5, availableFonts["chalet"], "left", "center", false, false, false, true)

							dxDrawText(row["categoryName"], rowX, rowY, rowX+rowWidth-15, rowY + rowHeight, tocolor(255, 255, 255, 255), 0.5, availableFonts["chalet"], "right", "center", false, false, true, true)
								--dxDrawText("$ " .. formatNumber(row["tuningPrice"], ","), rowX+15 , rowY, rowX, rowY + rowHeight, tocolor(255, 255, 255, 200), 0.5, availableFonts["chalet"], "left", "center", false, false, false, true)
							--end
						--end
					else
							dxDrawText(row["categoryName"].." #3f8bb0(Felszerelve)", rowX, rowY, rowX+rowWidth-15, rowY + rowHeight, tocolor(255, 255, 255, 255), 0.5, availableFonts["chalet"], "right", "center", false, false, true, true)
						--dxDrawText(getLocalizedText("tuning.active"), rowX + 15, rowY, rowX + 15 + rowWidth - 30 - dxGetTextWidth(availableIcons["wrench"], 1.0, availableFonts["icons"]) - 10, rowY + rowHeight, tocolor(150, 255, 150, 255), 0.5, availableFonts["chalet"], "left", "center", false, false, false, true)
						--dxDrawText(availableIcons["wrench"], rowX + 15, rowY, rowX + 15 + rowWidth - 30, rowY + rowHeight, tocolor(150, 255, 150, 255), 1.0, availableFonts["icons"], "left", "center", false, false, false, true)
					end
				else
					if kep == "pp.png" then
						selectR, selectG,selectB = 50,148,195
					else
						--selectR, selectG,selectB = 50,148,195
						selectR, selectG,selectB = 96,163,91
					end

					if row["categoryName"] == "Gyári" then
						selectR, selectG,selectB = 217, 83, 79
					end

				--	dxDrawImage(rowX, rowY, rowWidth, rowHeight, availableTextures["hoveredrow"],0,0,0,tocolor(selectR, selectG,selectB,255)) -- animchancge

					if equippedUpgrade ~= id then
						--if row["tuningPrice"] then
						--	if row["tuningPrice"] == 0 then
								--dxDrawText(getLocalizedText("tuningPrice.free"), rowX + 15, rowY, rowX , rowY + rowHeight, tocolor(198, 83, 82, 255), 0.5, availableFonts["chalet"], "left", "center", false, false, false, true)
							dxDrawText(row["categoryName"], rowX, rowY, rowX+rowWidth-15, rowY + rowHeight, tocolor(255, 255, 255, 255), 0.5, availableFonts["chalet"], "right", "center", false, false, true, true)
								--dxDrawText("$ " .. formatNumber(row["tuningPrice"], ","), rowX+15 , rowY, rowX, rowY + rowHeight, tocolor(255, 255, 255, 200), 0.5, availableFonts["chalet"], "left", "center", false, false, false, true)
							--end
							dxDrawImage(rowX+2, rowY+2, 32,32, "files/icons/"..kep,0,0,0,tocolor(255,255,255,255),true)
						--end
					else
							dxDrawText(row["categoryName"].." #3f8bb0(Felszerelve)", rowX, rowY, rowX+rowWidth-15, rowY + rowHeight, tocolor(255, 255, 255, 255), 0.5, availableFonts["chalet"], "right", "center", false, false, true, true)
						--dxDrawText(getLocalizedText("tuning.active"), rowX + 15, rowY, rowX + 15 + rowWidth - 30 - dxGetTextWidth(availableIcons["wrench"], 1.0, availableFonts["icons"]) - 10, rowY + rowHeight, tocolor(150, 255, 150, 255), 0.5, availableFonts["chalet"], "left", "center", false, false, false, true)
						dxDrawImage(rowX+2, rowY+2, 32,32, "files/icons/"..kep,0,0,0,tocolor(255,255,255,255),true)
						--dxDrawText(availableIcons["wrench"], rowX + 15, rowY, rowX + 15 + rowWidth - 30, rowY + rowHeight, tocolor(150, 255, 150, 255), 1.0, availableFonts["icons"], "left", "center", false, false, false, true)
					end

				--	if equippedUpgrade ~= id then
						if row["tuningPrice"] then
							if row["tuningPrice"] == 0 then
								dxDrawText("Ár: #d9534fIngyenes", 15, navY+5, 0,0, tocolor(255, 255, 255, 255), 0.45, Roboto, "left", "top", false, false, false, true)
							else
								if selectR == 50 and selectG == 148 and selectB == 195 and equippedUpgrade ~= id then
									dxDrawText("Ár: #3f8bb0" .. formatNumber(row["tuningPrice"], ",").." #3f8bb0PP", 15, navY+5, 0,0, tocolor(255, 255, 255, 255), 0.45, Roboto, "left", "top", false, false, false, true)
								else
									if equippedUpgrade ~= id then
										dxDrawText("Ár: #60a35b" .. formatNumber(row["tuningPrice"], ",").." #60a35b$", 15, navY+5, 0,0, tocolor(255, 255, 255, 255), 0.45, Roboto, "left", "top", false, false, false, true)
									end
								end
							end
						--end
					else
						--dxDrawText(getLocalizedText("tuning.active"), rowX + 15, rowY, rowX + 15 + rowWidth - 30 - dxGetTextWidth(availableIcons["wrench"], 1.0, availableFonts["icons"]) - 10, rowY + rowHeight, tocolor(0, 0, 0, 255), 0.5, availableFonts["chalet"], "right", "center", false, false, false, true)
						--dxDrawText(availableIcons["wrench"], rowX + 15, rowY, rowX + 15 + rowWidth - 30, rowY + rowHeight, tocolor(0, 0, 0, 255), 1.0, availableFonts["icons"], "right", "center", false, false, false, true)
					end
				end

				categoryCount = categoryCount + 1
			end
		end

		--dxDrawImage(panelX, panelY + (categoryCount * rowHeight), panelWidth, rowHeight, availableTextures["menunav"])
		for id, row in ipairs(loopTable) do
			if row["categoryName"] == "Kerekek 1" then
				row["categoryName"] = "Oxygen Eins"
			end
			if row["categoryName"] == "Kerekek 2" then
				row["categoryName"] = "WedsSport TC105N"
			end
			if row["categoryName"] == "Kerekek 3" then
				row["categoryName"] = "Dare V2 Alloy"
			end
			if row["categoryName"] == "Kerekek 4" then
				row["categoryName"] = "Ronal Turbo"
			end
			if row["categoryName"] == "Kerekek 5" then
				row["categoryName"] = "Dayton 100 Spoke"
			end
			if row["categoryName"] == "Kerekek 6" then
				row["categoryName"] = "Hamann Edition Race"
			end
			if row["categoryName"] == "Kerekek 7" then
				row["categoryName"] = "Dunlop Drag"
			end
			if row["categoryName"] == "Kerekek 8" then
				row["categoryName"] = "Luxury Diamond"
			end
			if row["categoryName"] == "Kerekek 9" then
				row["categoryName"] = "Advan Racing RGII"
			end
			if row["categoryName"] == "Kerekek 10" then
				row["categoryName"] = "Classic"
			end
			if row["categoryName"] == "Kerekek 11" then
				row["categoryName"] = "Volk Racing TE37"
			end
			if row["categoryName"] == "Kerekek 12" then
				row["categoryName"] = "Luxury Racing"
			end
			if row["categoryName"] == "Kerekek 13" then
				row["categoryName"] = "Avenger G/T"
			end
			if row["categoryName"] == "Kerekek 14" then
				row["categoryName"] = "BBS RS Gold"
			end
		end
		--> Scrollbar
		if categoryCount >= (maxRowsPerPage + 1) and categoryCount ~= #loopTable then
			local rowVisible = math.max(0.05, math.min(1.0, (maxRowsPerPage + 1) / #loopTable))
			local scrollbarHeight = ((maxRowsPerPage + 1) * rowHeight) * rowVisible
			local scrollbarPosition = math.min((currentPage - 1) / #loopTable, 1.0 - rowVisible) * ((maxRowsPerPage + 1) * rowHeight)

			dxDrawRectangle(panelX + panelWidth - 2+5, panelY + scrollbarPosition, 3, scrollbarHeight, tocolor(255, 255, 255, 255))
		end
		--dxDrawImage(0, 0, 1920, 1080, "t")
		--> Navigation Bar
		dxDrawImage(navX, navY, 128, 32, "files/nav/enter.png")
		dxDrawText("Vásárlás", navX+65, navY+5, 0, 0, tocolor(255,255,255,255), 0.5, availableFonts["chalet"])

		dxDrawImage(navX+130, navY, 128, 32, "files/nav/backspace.png")
		dxDrawText("Kilépés", navX+65+128+24, navY+5, 0, 0, tocolor(255,255,255,255), 0.5, availableFonts["chalet"])

		dxDrawImage(navX+130+130+8, navY, 32, 32, "files/nav/up.png")
		dxDrawImage(navX+130+130+40, navY, 32, 32, "files/nav/down.png")
		dxDrawText("Navigáció", navX+130+130+75, navY+5, 0, 0, tocolor(255,255,255,255), 0.5, availableFonts["chalet"])

		dxDrawImage(navX+130+130+40+108, navY, 32, 32, "files/nav/mouse.png")
		dxDrawText("Kamera mozgatás", navX+130+130+40+108+34, navY+5, 0, 0, tocolor(255,255,255,255), 0.5, availableFonts["chalet"])
		--> Prompt dialog
		if promptDialog["state"] then
			local promptWidth = dxGetTextWidth(getLocalizedText("prompt.text"), 0.5, availableFonts["chalet"]) + 20
			local promptWidth, promptHeight = promptWidth, 120 * scaleFactor
			local promptX, promptY = (screenX / 2) - (promptWidth / 2), (screenY / 2) - (promptHeight / 2)

			dxDrawRectangle(screenX/2-300, screenY/2-100, 600, 200, tocolor(0, 0, 0, 150))
			dxDrawText(getLocalizedText("prompt.text"), screenX/2-300, screenY/2-80+10, screenX/2+300, screenY/2+100, tocolor(255, 255, 255, 255), 0.5, Roboto, "center", "top")

			--dxDrawText("#cccccc" .. getLocalizedText("prompt.info.1") ..": #ffffff" .. promptDialog["itemName"], promptX + 15, promptY + 30, promptX + 15 + promptWidth - 30, promptY + 30 + promptHeight - 60, tocolor(255, 255, 255, 255), 0.45, font, "left", "top", false, false, false, true)
			if (selectR == 50 and selectG == 148 and selectB == 195) or promptDialog["itemPrice"] < 5000 then
				dxDrawText("#3f8bb0" .. getLocalizedText("prompt.info.2") .. ": " .. formatNumber(promptDialog["itemPrice"], " ").. " PP",screenX/2-300, screenY/2-80+35, screenX/2+300, screenY/2+100, tocolor(255, 255, 255, 255), 0.5, Roboto, "center", "top", false, false, false, true)

			else
					dxDrawText("#7cc576" .. getLocalizedText("prompt.info.2") .. ": " .. formatNumber(promptDialog["itemPrice"], " ").. " $",screenX/2-300, screenY/2-80+35, screenX/2+300, screenY/2+100, tocolor(255, 255, 255, 255), 0.5, Roboto, "center", "top", false, false, false, true)
			end
			dxDrawText("#7cc576MTATESTE - #ff7f00Tuning", screenX/2-300, screenY/2-100-20,0,0,tocolor(255, 255, 255, 255), 0.5, Roboto,"left","top",false,false,false,true)

			dxDrawRectangle(screenX/2-270, screenY/2+100-70,240,40, tocolor(217, 83, 79,200)) -- mégsem
			dxDrawRectangle(screenX/2+30, screenY/2+100-70,240,40, tocolor(96,163,91,200)) -- vásárlás
			dxDrawText(getLocalizedText("prompt.button.1"), screenX/2+30, screenY/2+100-70,screenX/2+30+240, screenY/2+100-70+40, tocolor(0, 0, 0, 255), 0.45, font, "center", "center")
			dxDrawText(getLocalizedText("prompt.button.2"), screenX/2-270, screenY/2+100-70, screenX/2-270+240, screenY/2+100-70+40, tocolor(0, 0, 0, 255), 0.45, font, "center", "center")
		end

		--> License Plate inputbox
		if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.extras")) then
			if selectedSubCategory == 9 and hoveredCategory == 2 then
				local boxX, boxY, boxWidth, boxHeight = panelX + 2, panelY + (categoryCount * rowHeight) + rowHeight, panelWidth - 4, rowHeight

				drawBorderedRectangle(boxX, boxY, boxWidth, boxHeight, 2, tocolor(0, 0, 0, 255), tocolor(30, 30, 30, 255))
				dxDrawText(vehicleNumberplate, boxX, boxY, boxX + boxWidth, boxY + boxHeight, tocolor(255, 255, 255, 255), 0.5, availableFonts["chalet"], "center", "center")
			end
		end
	else

	end
end)

addEventHandler("onClientPreRender", root, function()
	if panelState and enteredVehicle then
		local _, _, _, _, _, _, roll, fov = getCameraMatrix()
		local cameraZoomProgress = (getTickCount() - cameraSettings["zoomTick"]) / 500
		local cameraZoomAnimation = interpolateBetween(fov, 0, 0, cameraSettings["zoom"], 0, 0, cameraZoomProgress, "Linear")

		if cameraSettings["moveState"] == "moveToElement" then
			local currentCameraX, currentCameraY, currentCameraZ, currentCameraRotX, currentCameraRotY, currentCameraRotZ = getCameraMatrix()
			local cameraProgress = (getTickCount() - cameraSettings["moveTick"]) / 1000
			local cameraX, cameraY, cameraZ, componentX, componentY, componentZ = _getCameraPosition("component")
			local newCameraX, newCameraY, newCameraZ = interpolateBetween(currentCameraX, currentCameraY, currentCameraZ, cameraX, cameraY, cameraZ, cameraProgress, "Linear")
			local newCameraRotX, newCameraRotY, newCameraRotZ = interpolateBetween(currentCameraRotX, currentCameraRotY, currentCameraRotZ, componentX, componentY, componentZ, cameraProgress, "Linear")
			local newCameraZoom = interpolateBetween(fov, 0, 0, 60, 0, 0, cameraProgress, "Linear")

			setCameraMatrix(newCameraX, newCameraY, newCameraZ, newCameraRotX, newCameraRotY, newCameraRotZ, roll, newCameraZoom)

			if cameraProgress > 0.5 then
				cameraSettings["moveState"] = "freeMode"
				cameraSettings["zoom"] = 60
			end
		elseif cameraSettings["moveState"] == "backToVehicle" then
			local currentCameraX, currentCameraY, currentCameraZ, currentCameraRotX, currentCameraRotY, currentCameraRotZ = getCameraMatrix()
			local cameraProgress = (getTickCount() - cameraSettings["moveTick"]) / 1000
			local cameraX, cameraY, cameraZ, vehicleX, vehicleY, vehicleZ = _getCameraPosition("vehicle")
			local newCameraX, newCameraY, newCameraZ = interpolateBetween(currentCameraX, currentCameraY, currentCameraZ, cameraX, cameraY, cameraZ, cameraProgress, "Linear")
			local newCameraRotX, newCameraRotY, newCameraRotZ = interpolateBetween(currentCameraRotX, currentCameraRotY, currentCameraRotZ, vehicleX, vehicleY, vehicleZ, cameraProgress, "Linear")
			local newCameraZoom = interpolateBetween(fov, 0, 0, 60, 0, 0, cameraProgress, "Linear")

			setCameraMatrix(newCameraX, newCameraY, newCameraZ, newCameraRotX, newCameraRotY, newCameraRotZ, roll, newCameraZoom)

			if cameraProgress > 0.5 then
				cameraSettings["moveState"] = "freeMode"
				cameraSettings["zoom"] = 60
			end
		elseif cameraSettings["moveState"] == "freeMode" then
			local cameraX, cameraY, cameraZ, elementX, elementY, elementZ = _getCameraPosition("both")

			setCameraMatrix(cameraX, cameraY, cameraZ, elementX, elementY, elementZ, roll, cameraZoomAnimation)

			if getKeyState("mouse1") and not isCursorShowing() and not isMTAWindowActive() and not promptDialog["state"] then
				cameraSettings["freeModeActive"] = true
			else
				cameraSettings["freeModeActive"] = false
			end
		end
	end
end)

addEventHandler("onClientCursorMove", root, function(cursorX, cursorY)
	if panelState and enteredVehicle then
		if cameraSettings["freeModeActive"] then
			local differentX, differentY = cursorX - 0.5, cursorY - 0.5
			local cameraX = cameraSettings["currentX"] - differentX * cameraSettings["movingSpeed"]
			local cameraY = cameraSettings["currentY"] - differentX * cameraSettings["movingSpeed"]
			local cameraZ = cameraSettings["currentZ"] + (differentY * cameraSettings["movingSpeed"]) / math.pi

			cameraZ = math.max(cameraSettings["minimumZ"], math.min(cameraSettings["maximumZ"], cameraZ))

			cameraSettings["currentX"] = cameraX
			cameraSettings["currentY"] = cameraY
			cameraSettings["currentZ"] = cameraZ
		end
	end
end)

addEventHandler("onClientCharacter", root, function(character)

	if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.extras")) then
		if selectedSubCategory == 9 and hoveredCategory == 2 then
			if #vehicleNumberplate < 8 then
				local supportedCharacters = {
					["q"] = true, ["w"] = true, ["x"] = true, ["4"] = true,
					["e"] = true, ["r"] = true, ["c"] = true, ["5"] = true,
					["t"] = true, ["z"] = true, ["v"] = true, ["6"] = true,
					["u"] = true, ["i"] = true, ["b"] = true, ["7"] = true,
					["o"] = true, ["p"] = true, ["n"] = true, ["8"] = true,
					["a"] = true, ["s"] = true, ["m"] = true, ["9"] = true,
					["d"] = true, ["f"] = true, ["0"] = true, ["-"] = true,
					["g"] = true, ["h"] = true, ["1"] = true, [" "] = true,
					["j"] = true, ["k"] = true, ["2"] = true,
					["l"] = true, ["y"] = true, ["3"] = true,
				}

				if supportedCharacters[character] then
					vehicleNumberplate = vehicleNumberplate .. utf8.upper(character)
					setVehiclePlateText(enteredVehicle, vehicleNumberplate)
				end
      end
		end
	end
end)

function resetUpgrades(veh)
    if defaultPaintJob == 0 then
		actualPaintJob = 0
		exports.sas_paintjob:destroyShaderCache(veh)
	else
		actualPaintJob = defaultPaintJob
		exports.sas_paintjob:addVehiclePaintJob(veh, getElementModel(veh), defaultPaintJob)
	end
end

addEventHandler("onClientKey", root, function(key, pressed)
	if panelState and enteredVehicle then
		if pressed then
			if key == "arrow_d" and not promptDialog["state"] and tuningCompleted then
				arrowFel = false
				--[[if szorzas <= maxRowsPerPage then
					szorzas = szorzas + 1
				else
					szorzas = maxRowsPerPage
				end]]
				if #loopTable <= 4 then
					if szorzas ~= 4 then
						lastTick2 =getTickCount()
					end
				end
				if #loopTable > 4 then
					if szorzas ~= 8 then
						lastTick2 =getTickCount()
					end
				end
				if hoveredCategory > #loopTable or hoveredCategory == #loopTable then
					hoveredCategory = #loopTable
				else
					if hoveredCategory > maxRowsPerPage then
						currentPage = currentPage + 1
					end

					hoveredCategory = hoveredCategory + 1

					if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.optical")) then
						if selectedSubCategory ~= 0 then
							if isGTAUpgradeSlot(tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["upgradeSlot"]) then
								showNextOpticalUpgrade()
							else
								if selectedSubCategory == 11 then -- Neon
									addNeon(enteredVehicle, loopTable[hoveredCategory]["tuningData"])
								end
							end
						end
					elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.extras")) then
						if selectedSubCategory == 1 then
							triggerServerEvent("tuning->WheelWidth", localPlayer, enteredVehicle, "front", loopTable[hoveredCategory]["tuningData"])
						elseif selectedSubCategory == 2 then
							triggerServerEvent("tuning->WheelWidth", localPlayer, enteredVehicle, "rear", loopTable[hoveredCategory]["tuningData"])
						elseif selectedSubCategory == 5 then
							--triggerServerEvent("tuning->WheelWidth", localPlayer, enteredVehicle, "rear", loopTable[hoveredCategory]["tuningData"])
							triggerServerEvent("event->buyVariant", localPlayer, enteredVehicle, loopTable[hoveredCategory]["tuningData"])
						elseif selectedSubCategory == 6 then
							--local model = getElementModel(enteredVehicle)
							--triggerEvent("addVehiclePaintJob", localPlayer, enteredVehicle, model, loopTable[hoveredCategory]["tuningData"])
							--triggerServerEvent("event->buyPaintjob", localPlayer, enteredVehicle, getElementModel(enteredVehicle), loopTable[hoveredCategory]["tuningData"])
							exports.sas_paintjob:addVehiclePaintJob(enteredVehicle, getElementModel(enteredVehicle), loopTable[hoveredCategory]["tuningData"])
						end
					elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.color")) then
						setVehicleColorsToDefault()
						setPaletteType(loopTable[hoveredCategory]["tuningData"])
						updatePaletteColor(enteredVehicle, loopTable[hoveredCategory]["tuningData"])
					elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.performance")) then
						if selectedSubCategory == 2 then
							if hoveredCategory == 5 then

								if isCharger[getElementModel(enteredVehicle)] then
									if not isElement(chargerElement) then
										local x,y,z = getElementPosition(enteredVehicle)
										chargerElement = createObject(17697,x,y,z)
										local posX,posY,posZ,rotX,rotY,rotZ = isCharger[getElementModel(enteredVehicle)][1],isCharger[getElementModel(enteredVehicle)][2],isCharger[getElementModel(enteredVehicle)][3],isCharger[getElementModel(enteredVehicle)][4],isCharger[getElementModel(enteredVehicle)][5],isCharger[getElementModel(enteredVehicle)][6]
										attachElements(chargerElement,enteredVehicle,posX,posY,posZ,rotX,rotY,rotZ)
										setElementCollisionsEnabled(chargerElement, false)
									end
								end

							end
						end
					end

					playSoundEffect("menunavigate.mp3")
				end
			elseif key == "arrow_u" and not promptDialog["state"] and tuningCompleted then
				arrowFel = true
			--[[	if szorzas <= maxRowsPerPage then
					szorzas = szorzas - 1
				else
					szorzas = maxRowsPerPage
				end]]
			--	if #loopTable <= 4 then
					if szorzas ~= 1 then
						lastTick2 = getTickCount()
					end
				--end

				if hoveredCategory < 1 or hoveredCategory == 1 then
					hoveredCategory = 1

					if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.optical")) then
						if selectedSubCategory ~= 0 then
							if isGTAUpgradeSlot(tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["upgradeSlot"]) then
								showDefaultOpticalUpgrade()
							end
						end
					end
				else
					if currentPage - 1 >= 1 then
						currentPage = currentPage - 1
					end

					hoveredCategory = hoveredCategory - 1

					if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.optical")) then
						if selectedSubCategory ~= 0 then
							if isGTAUpgradeSlot(tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["upgradeSlot"]) then
								if hoveredCategory == 1 then -- Default upgrade
									removeVehicleUpgrade(enteredVehicle, compatibleOpticalUpgrades[hoveredCategory])
								else
									showNextOpticalUpgrade()
								end
							else
								if selectedSubCategory == 11 then -- Neon
									if hoveredCategory == 1 then
										removeNeon(enteredVehicle, true)
									else
										addNeon(enteredVehicle, loopTable[hoveredCategory]["tuningData"])
									end
								end
							end
						end
					elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.extras")) then
						if selectedSubCategory == 1 then
							triggerServerEvent("tuning->WheelWidth", localPlayer, enteredVehicle, "front", loopTable[hoveredCategory]["tuningData"])
						elseif selectedSubCategory == 2 then
							triggerServerEvent("tuning->WheelWidth", localPlayer, enteredVehicle, "rear", loopTable[hoveredCategory]["tuningData"])
						elseif selectedSubCategory == 5 then
							--triggerServerEvent("tuning->WheelWidth", localPlayer, enteredVehicle, "rear", loopTable[hoveredCategory]["tuningData"])
							triggerServerEvent("event->buyVariant", localPlayer, enteredVehicle, loopTable[hoveredCategory]["tuningData"])
						elseif selectedSubCategory == 6 then
							--local model = getElementModel(enteredVehicle)
							--triggerEvent("addVehiclePaintJob", localPlayer, enteredVehicle, model, loopTable[hoveredCategory]["tuningData"])
							--triggerServerEvent("event->buyPaintjob", localPlayer, enteredVehicle, getElementModel(enteredVehicle), loopTable[hoveredCategory]["tuningData"])
							exports.sas_paintjob:addVehiclePaintJob(enteredVehicle, getElementModel(enteredVehicle), loopTable[hoveredCategory]["tuningData"])
						elseif selectedSubCategory == 9 then
							if equippedTuning ~= vehicleNumberplate then
								setVehiclePlateText(enteredVehicle, equippedTuning)
								vehicleNumberplate = equippedTuning
							end
						end
					elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.color")) then
						setVehicleColorsToDefault()
						setPaletteType(loopTable[hoveredCategory]["tuningData"])
						updatePaletteColor(enteredVehicle, loopTable[hoveredCategory]["tuningData"])
					elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.performance")) then
						if selectedSubCategory == 2 then
							if hoveredCategory == 4 then
								if isCharger[getElementModel(enteredVehicle)] then
									if isElement(chargerElement) then
										destroyElement(chargerElement)
									end
								end
							end
						end
					end

					playSoundEffect("menunavigate.mp3")
				end
			elseif key == "backspace" and tuningCompleted then
				if promptDialog["state"] then
					promptDialog["state"] = false
				else
					if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.extras")) and selectedSubCategory == 9 then
						if hoveredCategory == 2 then
							if #vehicleNumberplate - 1 > 0 then
								vehicleNumberplate = string.sub(vehicleNumberplate, 1, #vehicleNumberplate - 1)
								setVehiclePlateText(enteredVehicle, vehicleNumberplate)
							else
								setVehiclePlateText(enteredVehicle, "-")
								vehicleNumberplate = ""
							end

							return
						else
							if equippedTuning ~= vehicleNumberplate then
								setVehiclePlateText(enteredVehicle, equippedTuning)
								vehicleNumberplate = equippedTuning
							end
						end
					end

					if selectedCategory == 0 and selectedSubCategory == 0 then
						triggerEvent("tuning->HideMenu", localPlayer)
						isBuyyedPainjob = false
					elseif selectedCategory ~= 0 and selectedSubCategory == 0 then
						if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.color")) then -- Color
							destroyColorPicker()
							setVehicleColorsToDefault()
							showCursor(false)
						end

						selectedCategory, hoveredCategory, currentPage = 0, 1, 1
					elseif selectedCategory ~= 0 and selectedSubCategory ~= 0 then
						moveCameraToDefaultPosition()

						if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.optical")) then -- Optical
							if selectedSubCategory ~= 0 then
								if isGTAUpgradeSlot(tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["upgradeSlot"]) then
									resetOpticalUpgrade() -- reset to equipped upgrade
									tuningMenu[selectedCategory]["availableUpgrades"] = {}
									equippedTuning = 1
								else
									if selectedSubCategory == 10 then -- Lamp color
										destroyColorPicker()
										setVehicleColorsToDefault()
										showCursor(false)
										setVehicleOverrideLights(enteredVehicle, 1)
									elseif selectedSubCategory == 11 then -- Neon
										restoreOldNeon(enteredVehicle)
									end
								end
							end
						elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.extras")) then -- Extras
							if selectedSubCategory == 1 then
								local defaultWheelSize = (equippedTuning == 1 and "verynarrow") or (equippedTuning == 2 and "narrow") or (equippedTuning == 3 and "default") or (equippedTuning == 4 and "wide") or (equippedTuning == 5 and "verywide")

								triggerServerEvent("tuning->WheelWidth", localPlayer, enteredVehicle, "front", defaultWheelSize)
							elseif selectedSubCategory == 2 then
								local defaultWheelSize = (equippedTuning == 1 and "verynarrow") or (equippedTuning == 2 and "narrow") or (equippedTuning == 3 and "default") or (equippedTuning == 4 and "wide") or (equippedTuning == 5 and "verywide")

								triggerServerEvent("tuning->WheelWidth", localPlayer, enteredVehicle, "rear", defaultWheelSize)
							elseif selectedSubCategory == 5 then
								--setVehicleVariant(enteredVehicle, 255, 255)
								local defaultVariant = getElementData(enteredVehicle, "tuning.variant") or 255
								triggerServerEvent("event->buyVariant", localPlayer, enteredVehicle, defaultVariant)
							elseif selectedSubCategory == 6 then
								local defaultPaintjob = tonumber(getElementData(enteredVehicle, "PaintJob")) or 0
								if isBuyyedPainjob == true then
									--outputChatBox("te vettél")
									--triggerServerEvent("event->buyPaintjob", localPlayer, enteredVehicle, getElementModel(enteredVehicle), defaultPaintJob)
									exports.sas_paintjob:addVehiclePaintJob(enteredVehicle, getElementModel(enteredVehicle), defaultPaintJob)
								else
									if getElementData(enteredVehicle, "PaintJob") and getElementData(enteredVehicle, "PaintJob") > 0 then
										exports.sas_paintjob:addVehiclePaintJob(enteredVehicle, getElementModel(enteredVehicle), getElementData(enteredVehicle, "PaintJob"))
									else
										exports.sas_paintjob:destroyShaderCache(enteredVehicle)
									end
								end
								tuningMenu[4]["subMenu"][6]["subMenu"] ={
									[1] = {["categoryName"] = getLocalizedText("tuningPack.0"), ["tuningPrice"] = 0, ["tuningData"] = 0},
								}

							elseif selectedSubCategory == 7 then
								setVehicleDoorOpenRatio(enteredVehicle, 2, 0, 500)
								setVehicleDoorOpenRatio(enteredVehicle, 3, 0, 500)

								setVehicleDoorToLSD(enteredVehicle, ((equippedTuning == 1 and false) or (equippedTuning == 2 and true)))
							end
						elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.performance")) then
							if selectedSubCategory == 2 then
								if hoveredCategory == 5 then
									if isCharger[getElementModel(enteredVehicle)] then
										if isElement(chargerElement) then
											destroyElement(chargerElement)
										end
									end
								end
							end
						end

						selectedSubCategory, hoveredCategory, currentPage = 0, 1, 1
					end

					playSoundEffect("menuback.mp3")

					if enteredVehicle then
						for component in pairs(getVehicleComponents(enteredVehicle)) do
							if component ~= "wheel_type" and component ~= "lamps" and component ~= "calipers" and component ~= "display" and component ~= "skyline" and component ~= "motor" and component ~= "LFA11_engine" then
								setVehicleComponentVisible(enteredVehicle, component, true)
							end
						end
					end
				end
			elseif key == "enter" and tuningCompleted then
				if not promptDialog["state"] then
					if selectedCategory == 0 then
						selectedCategory, currentPage, hoveredCategory = hoveredCategory, 1, 1

						if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.color")) then
							savedVehicleColors["all"] = {getVehicleColor(enteredVehicle, true)}
							savedVehicleColors["headlight"] = {getVehicleHeadLightColor(enteredVehicle)}

							createColorPicker(enteredVehicle, panelX, (panelY + (logoHeight * scaleFactor) + rowHeight + (categoryCount * rowHeight) + rowHeight)-35, panelWidth - 4+4, (panelWidth / 2) * scaleFactor, "color1")
							showCursor(true)
						end

						playSoundEffect("menuenter.mp3")
					elseif selectedCategory ~= 0 and selectedSubCategory == 0 then
						if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.performance")) then
							local componentCompatible = false

							if isComponentCompatible(enteredVehicle, {"Automobile", "Monster Truck", "Quad", "Bike"}) then
								local tuningDataName = loopTable[hoveredCategory]["upgradeData"]
								local equippedTuningID = getElementData(enteredVehicle, "vehicle.tuning." .. tuningDataName) or 1

								if tuningDataName ~= "nitro" then
									equippedTuning = equippedTuningID
									componentCompatible = true
								else
									if isComponentCompatible(enteredVehicle, {"Automobile", "Monster Truck"}) then
										equippedTuning = -1
										componentCompatible = true
									end
								end
							end

							if componentCompatible then
								setCameraAndComponentVisible()
								selectedSubCategory, hoveredCategory, currentPage = hoveredCategory, 1, 1
							end
						elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.optical")) then
							if isGTAUpgradeSlot(loopTable[hoveredCategory]["upgradeSlot"]) then
								local upgradeSlot = loopTable[hoveredCategory]["upgradeSlot"]
								local compatibleUpgrades = getVehicleCompatibleUpgrades(enteredVehicle, upgradeSlot)

								if compatibleUpgrades[1] == nil then
									exports.hud:addNotification(getLocalizedText("notification.error.notCompatible"), "error")
									--outputDebugString("asd")
								else
									setCameraAndComponentVisible()

									compatibleOpticalUpgrades = compatibleUpgrades
									equippedTuning = getVehicleUpgradeOnSlot(enteredVehicle, upgradeSlot)

									table.insert(tuningMenu[selectedCategory]["availableUpgrades"], {
										["categoryName"] = getLocalizedText("tuningPack.0"),
										["tuningPrice"] = 0,
										["upgradeID"] = 0
									})

									for id, upgrade in pairs(compatibleOpticalUpgrades) do
										table.insert(tuningMenu[selectedCategory]["availableUpgrades"], {
											["categoryName"] = tuningMenu[selectedCategory]["subMenu"][hoveredCategory]["categoryName"] .. " " .. id,
											["tuningPrice"] = tuningMenu[selectedCategory]["subMenu"][hoveredCategory]["tuningPrice"],
											["upgradeID"] = upgrade
										})
									end

									selectedSubCategory, hoveredCategory, currentPage = hoveredCategory, 1, 1
									showDefaultOpticalUpgrade()
								end
							else -- Customs optical elements (Neon, Air-Ride etc..)
								local componentCompatible = false

								if hoveredCategory == 12 then -- Air-Ride
									if isComponentCompatible(enteredVehicle, "Automobile") then
										equippedTuning = (getElementData(enteredVehicle, "tuning.airRide") and 2) or 1
										componentCompatible = true
									end
								elseif hoveredCategory == 10 then -- Lamp color
									if isComponentCompatible(enteredVehicle, {"Automobile", "Monster Truck", "Quad", "Bike"}) then
										equippedTuning = -1

										setVehicleOverrideLights(enteredVehicle, 2)

										savedVehicleColors["all"] = {getVehicleColor(enteredVehicle, true)}
										savedVehicleColors["headlight"] = {getVehicleHeadLightColor(enteredVehicle)}

										createColorPicker(enteredVehicle, panelX + 2, (panelY + (logoHeight * scaleFactor) + (rowHeight * 2) + rowHeight)-35, panelWidth - 4, (panelWidth / 2) * scaleFactor, "headlight")
										showCursor(true)

										componentCompatible = true
									end
								elseif hoveredCategory == 11 then -- Neon
									if isComponentCompatible(enteredVehicle, "Automobile") then
										local currentNeon = getElementData(enteredVehicle, "tuning.neon") or false

										if currentNeon == "white" then currentNeon = 2
										elseif currentNeon == "blue" then currentNeon = 3
										elseif currentNeon == "green" then currentNeon = 4
										elseif currentNeon == "red" then currentNeon = 5
										elseif currentNeon == "yellow" then currentNeon = 6
										elseif currentNeon == "pink" then currentNeon = 7
										elseif currentNeon == "orange" then currentNeon = 8
										elseif currentNeon == "lightblue" then currentNeon = 9
										elseif currentNeon == "rasta" then currentNeon = 10
										elseif currentNeon == "ice" then currentNeon = 11
										else currentNeon = 1
										end

										equippedTuning = currentNeon
										removeNeon(enteredVehicle, true)

										componentCompatible = true
									end
								end

								if componentCompatible then
									setCameraAndComponentVisible()
									selectedSubCategory, hoveredCategory, currentPage = hoveredCategory, 1, 1
								end
							end
						elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.extras")) then
							local componentCompatible = false

							if hoveredCategory == 1 then
								if isComponentCompatible(enteredVehicle, "Automobile") then
									equippedTuning = getVehicleWheelSize(enteredVehicle, "front")
									triggerServerEvent("tuning->WheelWidth", localPlayer, enteredVehicle, "front", loopTable[hoveredCategory]["subMenu"][1]["tuningData"])

									componentCompatible = true
								end
							elseif hoveredCategory == 2 then
								if isComponentCompatible(enteredVehicle, "Automobile") then
									equippedTuning = getVehicleWheelSize(enteredVehicle, "rear")
									triggerServerEvent("tuning->WheelWidth", localPlayer, enteredVehicle, "rear", loopTable[hoveredCategory]["subMenu"][1]["tuningData"])

									componentCompatible = true
								end
							elseif hoveredCategory == 3 then
								if isComponentCompatible(enteredVehicle, {"Automobile", "Monster Truck", "Quad", "Bike"}) then
									equippedTuning = getVehicleOffroadAbility(enteredVehicle)
									componentCompatible = true
								end
							elseif hoveredCategory == 4 then
								if isComponentCompatible(enteredVehicle, {"Automobile", "Monster Truck", "Quad"}) then
									local driveType = getVehicleHandling(enteredVehicle)["driveType"]

									equippedTuning = (driveType == "fwd" and 1) or (driveType == "awd" and 2) or (driveType == "rwd" and 3)
									componentCompatible = true
								end
							elseif hoveredCategory == 5 then
								if isComponentCompatible(enteredVehicle, {"Automobile", "Monster Truck", "Quad", "Bike"}) then
									equippedTuning = (getElementData(enteredVehicle, "tuning.variant"))
									triggerServerEvent("event->buyVariant", localPlayer, enteredVehicle, loopTable[hoveredCategory]["subMenu"][1]["tuningData"])
									componentCompatible = true
								end
							elseif hoveredCategory == 6 then
								if isComponentCompatible(enteredVehicle, {"Automobile", "Monster Truck"}) then
									equippedTuning = (getElementData(enteredVehicle, "PaintJob"))
									allowedPaintjobs = exports.sas_paintjob:getVehiclePaintJobs(getElementModel(enteredVehicle))
									outputDebugString(tuningMenu[4]["subMenu"][6]["categoryName"])
									for i=1, allowedPaintjobs do
										table.insert(tuningMenu[4]["subMenu"][6]["subMenu"], {["categoryName"] = "Paintjob "..i, ["tuningPrice"] = 1800, ["tuningData"] = i})
									end
									--local model = getElementModel(enteredVehicle)
									--triggerServerEvent("addVehiclePaintJob", localPlayer, enteredVehicle, model, equippedTuning)
									--triggerServerEvent("event->buyPaintjob", localPlayer, enteredVehicle, model, loopTable[hoveredCategory]["tuningData"])
									exports.sas_paintjob:addVehiclePaintJob(enteredVehicle, getElementModel(enteredVehicle), equippedTuning)
									componentCompatible = true
								end
							elseif hoveredCategory == 7 then
								if isComponentCompatible(enteredVehicle, {"Automobile", "Monster Truck"}) then
									equippedTuning = (getElementData(enteredVehicle, "tuning.lsdDoor") and 2) or 1

									setVehicleDoorOpenRatio(enteredVehicle, 2, 1, 500)
									setVehicleDoorOpenRatio(enteredVehicle, 3, 1, 500)

									setVehicleDoorToLSD(enteredVehicle, true)

									componentCompatible = true
								end
							elseif hoveredCategory == 8 then
								if isComponentCompatible(enteredVehicle, {"Automobile", "Monster Truck", "Quad", "Bike", "BMX"}) then
									local steeringLock = getVehicleHandling(enteredVehicle)["steeringLock"]

									equippedTuning = (steeringLock == 30 and 2) or (steeringLock == 40 and 3) or (steeringLock == 50 and 4) or (steeringLock == 60 and 5) or 1
									componentCompatible = true
								end
							elseif hoveredCategory == 9 then
								if isComponentCompatible(enteredVehicle, {"Automobile", "Monster Truck", "Quad", "Bike"}) then
									equippedTuning = getVehiclePlateText(enteredVehicle)
									vehicleNumberplate = equippedTuning
									componentCompatible = true

								end
							elseif hoveredCategory == 10 then -- TRAFIRADAR
								componentCompatible = true
								equippedTuning = getElementData(enteredVehicle, "vehicle.tuning.traffiradar") or 2
							elseif hoveredCategory == 11 then -- SEEGOOO
								componentCompatible = true
								equippedTuning = getElementData(enteredVehicle, "vehicle.tuning.seeGO") or 2
							end

							if componentCompatible then
								setCameraAndComponentVisible()
								selectedSubCategory, hoveredCategory, currentPage = hoveredCategory, 1, 1
							end
						elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.color")) then
							promptDialog = {
								["state"] = true,
								["itemName"] = categoryName .. " (" .. loopTable[hoveredCategory]["categoryName"] .. ")",
								["itemPrice"] = loopTable[hoveredCategory]["tuningPrice"]
							}
						end

						playSoundEffect("menuenter.mp3")
					elseif selectedCategory ~= 0 and selectedSubCategory ~= 0 then
						promptDialog = {
							["state"] = true,
							["itemName"] = categoryName .. " (" .. loopTable[hoveredCategory]["categoryName"] .. ")",
							["itemPrice"] = loopTable[hoveredCategory]["tuningPrice"]
						}
					end
				else -- Buying item after accepted prompt
					if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.performance")) then
						if hoveredCategory == equippedTuning then
							exports.hud:addNotification(getLocalizedText("A kiválasztott csomag ("..loopTable[hoveredCategory]["categoryName"])..") már megtalálható a járművedben.", "error")
							promptDialog["state"] = false
							return
						else
							if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
								local tuningName = tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["upgradeData"]

								setElementData(enteredVehicle, "vehicle.tuning." .. tuningName, hoveredCategory, true)

								if selectedSubCategory == 2 then
									if hoveredCategory == 5 then
										if isElement(chargerElement) then
											destroyElement(chargerElement)
										end
									else
										triggerServerEvent("destroyChargerToClient",localPlayer,enteredVehicle)
									end
								end

								if tuningName ~= "nitro" then
									triggerServerEvent("tuning->performanceUpgrade", localPlayer, enteredVehicle, loopTable[hoveredCategory]["tuningData"])
									equippedTuning = hoveredCategory
								else
									if loopTable[hoveredCategory]["tuningData"] == 0 then
										triggerServerEvent("tuning->OpticalUpgrade", localPlayer, enteredVehicle, "remove", 1010)
									else
										triggerServerEvent("tuning->OpticalUpgrade", localPlayer, enteredVehicle, "add", 1010)
									end

									setElementData(enteredVehicle, "tuning.nitroLevel", loopTable[hoveredCategory]["tuningData"])
									refreshVehicleNitroLevel(enteredVehicle, loopTable[hoveredCategory]["tuningData"])
								end

								moneyChange(loopTable[hoveredCategory]["tuningPrice"])
								promptDialog["state"] = false
							else
								exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
								promptDialog["state"] = false
							end
						end
					elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.optical")) then
						if isGTAUpgradeSlot(tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["upgradeSlot"]) then
							if equippedTuning == loopTable[hoveredCategory]["upgradeID"] then
								exports.hud:addNotification("A kiválasztott elem ("..loopTable[hoveredCategory]["categoryName"].."már megtalálható a járművedben.", "error")
								promptDialog["state"] = false
							else
								if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
									if getElementData(enteredVehicle, "tuning.airRide") and selectedSubCategory == 8 then
										exports.hud:addNotification(getLocalizedText("notification.warning.airRideInstalled"))
									else
										if loopTable[hoveredCategory]["upgradeID"] == 0 then
											triggerServerEvent("tuning->OpticalUpgrade", localPlayer, enteredVehicle, "remove", equippedTuning)
											equippedTuning = 0
										else
											triggerServerEvent("tuning->OpticalUpgrade", localPlayer, enteredVehicle, "add", loopTable[hoveredCategory]["upgradeID"])
											equippedTuning = loopTable[hoveredCategory]["upgradeID"]
										end

										moneyChange(loopTable[hoveredCategory]["tuningPrice"])
									end

									promptDialog["state"] = false
								else
									exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"))
									promptDialog["state"] = false
								end
							end
						else
							if selectedSubCategory == 12 then -- Air-Ride
								if hoveredCategory == equippedTuning then
									exports.hud:addNotification("A kiválasztott elem ("..loopTable[hoveredCategory]["categoryName"]..") már megtalálható a járművedben.", "error")
									promptDialog["state"] = false
								else
									if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
										setElementData(enteredVehicle, "tuning.airRide", loopTable[hoveredCategory]["tuningData"], true)
										triggerServerEvent("tuning->buyAirride", localPlayer, enteredVehicle, loopTable[hoveredCategory]["tuningData"])
										if hoveredCategory == 1 then
											removeAirRide(enteredVehicle)
										end

										equippedTuning = hoveredCategory
										moneyChange(loopTable[hoveredCategory]["tuningPrice"])
										promptDialog["state"] = false
									else
										exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
										promptDialog["state"] = false
									end
								end
							elseif selectedSubCategory == 10 then -- Lamp color
								if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
									savedVehicleColors["all"] = {getVehicleColor(enteredVehicle, true)}
									savedVehicleColors["headlight"] = {getVehicleHeadLightColor(enteredVehicle)}

									triggerServerEvent("tuning->Color", localPlayer, enteredVehicle, savedVehicleColors["all"], savedVehicleColors["headlight"])

									equippedTuning = -1
									moneyChange(loopTable[hoveredCategory]["tuningPrice"])
									promptDialog["state"] = false
								else
									exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
									promptDialog["state"] = false
								end
							elseif selectedSubCategory == 11 then -- Neon
								if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
									saveNeon(enteredVehicle, loopTable[hoveredCategory]["tuningData"], true)

									--setElementData(enteredVehicle, "tuning.neon", loopTable[hoveredCategory]["tuningData"], true)
									triggerServerEvent("tuning->buyNeon", localPlayer, enteredVehicle, loopTable[hoveredCategory]["tuningData"])

									equippedTuning = hoveredCategory
									moneyChange(loopTable[hoveredCategory]["tuningPrice"])
									promptDialog["state"] = false
								else
									exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
									promptDialog["state"] = false
								end
							end
						end
					elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.extras")) then
						if selectedSubCategory == 1 or selectedSubCategory == 2 then
							local vehicleSide = (selectedSubCategory == 1 and "front") or (selectedSubCategory == 2 and "rear")

							if hoveredCategory == equippedTuning then
								exports.hud:addNotification("A kiválasztott elem ("..loopTable[hoveredCategory]["categoryName"]..") már megtalálható a járművedben.", "error")
								promptDialog["state"] = false
							else
								if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
									triggerServerEvent("tuning->WheelWidth", localPlayer, enteredVehicle, vehicleSide, loopTable[hoveredCategory]["tuningData"])

									equippedTuning = hoveredCategory
									moneyChange(loopTable[hoveredCategory]["tuningPrice"])
									promptDialog["state"] = false
								else
									exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
									promptDialog["state"] = false
								end
							end
						elseif selectedSubCategory == 3 then
							if hoveredCategory == equippedTuning then
								exports.hud:addNotification("A kiválasztott elem ("..loopTable[hoveredCategory]["categoryName"].. ") már megtalálható a járművedben", "error")
								promptDialog["state"] = false
							else
								if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
									triggerServerEvent("tuning->OffroadAbility", localPlayer, enteredVehicle, loopTable[hoveredCategory]["tuningData"])

									equippedTuning = hoveredCategory
									moneyChange(loopTable[hoveredCategory]["tuningPrice"])
									promptDialog["state"] = false
								else
									exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
									promptDialog["state"] = false
								end
							end
						elseif selectedSubCategory == 4 then
							if hoveredCategory == equippedTuning then
								exports.hud:addNotification("A kiválasztott elem ("..loopTable[hoveredCategory]["categoryName"].. ") már megtalálható a járművedben.", "error")
								promptDialog["state"] = false
							else
								if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
									triggerServerEvent("tuning->HandlingUpdate", localPlayer, enteredVehicle, tuningMenu[selectedCategory]["subMenu"][selectedSubCategory]["propertyName"], loopTable[hoveredCategory]["tuningData"])

									equippedTuning = hoveredCategory
									moneyChange(loopTable[hoveredCategory]["tuningPrice"])
									promptDialog["state"] = false
								else
									exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
									promptDialog["state"] = false
								end
							end
						elseif selectedSubCategory == 5 then
							if hoveredCategory == equippedTuning then
								exports.hud:addNotification("A kiválasztott elem ("..loopTable[hoveredCategory]["categoryName"]..") már megtalálható a járművedben.", "error")
								promptDialog["state"] = false
							else
								if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
									setElementData(enteredVehicle, "tuning.variant", loopTable[hoveredCategory]["tuningData"], true)
									triggerServerEvent("event->buyVariant", localPlayer, enteredVehicle, loopTable[hoveredCategory]["tuningData"])
									equippedTuning = hoveredCategory
									moneyChange(loopTable[hoveredCategory]["tuningPrice"])
									promptDialog["state"] = false
								else
									exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
									promptDialog["state"] = false
								end
							end
						elseif selectedSubCategory == 6 then
							if hoveredCategory == equippedTuning then
								exports.hud:addNotification("A kiválasztott elem ("..loopTable[hoveredCategory]["categoryName"]..") már megtalálható a járművedben.", "error")
								promptDialog["state"] = false
							else
								if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
									setElementData(enteredVehicle, "PaintJob", 0)
									setElementData(enteredVehicle, "PaintJob", loopTable[hoveredCategory]["tuningData"])
									triggerServerEvent("event->buyPaintjob", localPlayer, enteredVehicle, loopTable[hoveredCategory]["tuningData"])
									isBuyyedPainjob = true
									exports.sas_paintjob:addVehiclePaintJob(enteredVehicle, getElementModel(enteredVehicle), loopTable[hoveredCategory]["tuningData"])
									equippedTuning = hoveredCategory
									moneyChange(loopTable[hoveredCategory]["tuningPrice"])
									promptDialog["state"] = false
								else
									exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
									promptDialog["state"] = false
								end
							end
						elseif selectedSubCategory == 7 then
							if hoveredCategory == equippedTuning then
								exports.hud:addNotification("A kiválasztott elem ("..loopTable[hoveredCategory]["categoryName"]..") már megtalálható a járművedben.", "error")
								promptDialog["state"] = false
							else
								if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
									setVehicleDoorToLSD(enteredVehicle, loopTable[hoveredCategory]["tuningData"])

									triggerServerEvent("tuning->buyLSDDoor", localPlayer, enteredVehicle, loopTable[hoveredCategory]["tuningData"])

									equippedTuning = hoveredCategory
									moneyChange(loopTable[hoveredCategory]["tuningPrice"])
									promptDialog["state"] = false
								else
									exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
									promptDialog["state"] = false
								end
							end
						--[[elseif selectedSubCategory == 8 then
							if hoveredCategory == equippedTuning then
								giveNotification("error", getLocalizedText("notification.error.itemIsPurchased", loopTable[hoveredCategory]["categoryName"]))
								promptDialog["state"] = false
							else
								if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
									setVehicleDoorToLSD(enteredVehicle, loopTable[hoveredCategory]["tuningData"])
									--steeringLock
									triggerServerEvent("tuning->performanceUpgrade", localPlayer, enteredVehicle, loopTable[hoveredCategory]["tuningData"])

									equippedTuning = hoveredCategory
									moneyChange(loopTable[hoveredCategory]["tuningPrice"])
									promptDialog["state"] = false
								else
									giveNotification("error", getLocalizedText("notification.error.notEnoughMoney"))
									promptDialog["state"] = false
								end
							end]]
						elseif selectedSubCategory == 9 then
							if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
								if loopTable[hoveredCategory]["tuningData"] == "random" then
									local letter1 = string.char(math.random(65,90))
									local letter2 = string.char(math.random(65,90))
									local str = "abcdefghijklmnopqrstuvwxyz"
					  				local plate = ""
					  				for index = 1, 3 do
					       			   plate = plate .. string.char(str:byte(math.random(1, #str)))
					   				end
								   	plate = string.upper(plate)
					   			    plate = plate .. "-"
					    			for index = 1, 3 do
					       				plate = plate .. math.random(1, 9)
					   			    end

									vehicleNumberplate = plate
								elseif loopTable[hoveredCategory]["tuningData"] == "custom" then
									vehicleNumberplate = vehicleNumberplate
								end

								triggerServerEvent("tuning->LicensePlate", localPlayer, enteredVehicle, vehicleNumberplate)

								equippedTuning = vehicleNumberplate
								moneyChange(loopTable[hoveredCategory]["tuningPrice"])
								promptDialog["state"] = false
							else
								exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
								promptDialog["state"] = false
							end
						elseif selectedSubCategory == 10 then
							if hoveredCategory == equippedTuning then
								exports.hud:addNotification("A kiválasztott elem ("..loopTable[hoveredCategory]["categoryName"]..") már megtalálható a járművedben.", "error")
								promptDialog["state"] = false
							else
								if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then

									triggerServerEvent("tuning->buytrafiRadar", localPlayer, enteredVehicle, loopTable[hoveredCategory]["tuningData"])

									equippedTuning = hoveredCategory
									moneyChange(loopTable[hoveredCategory]["tuningPrice"])
									promptDialog["state"] = false
								else
									exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
									promptDialog["state"] = false
								end
							end
						elseif selectedSubCategory == 11 then
							if hoveredCategory == equippedTuning then
								exports.hud:addNotification("A kiválasztott elem ("..loopTable[hoveredCategory]["categoryName"]..") már megtalálható a járművedben.", "error")
								promptDialog["state"] = false
							else
								if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then

									triggerServerEvent("tuning->buySeeGO", localPlayer, enteredVehicle, loopTable[hoveredCategory]["tuningData"])

									equippedTuning = hoveredCategory
									moneyChange(loopTable[hoveredCategory]["tuningPrice"])
									promptDialog["state"] = false
								else
									exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
									promptDialog["state"] = false
								end
							end
						end

					elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.color")) then
						if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
							savedVehicleColors["all"] = {getVehicleColor(enteredVehicle, true)}
							savedVehicleColors["headlight"] = {getVehicleHeadLightColor(enteredVehicle)}

							triggerServerEvent("tuning->Color", localPlayer, enteredVehicle, savedVehicleColors["all"], savedVehicleColors["headlight"])

							equippedTuning = hoveredCategory
							moneyChange(loopTable[hoveredCategory]["tuningPrice"])
							promptDialog["state"] = false
						else
							exports.hud:addNotification(getLocalizedText("notification.error.notEnoughMoney"), "error")
							promptDialog["state"] = false
						end
					end
					if hasPlayerMoney(loopTable[hoveredCategory]["tuningPrice"]) then
						--if hoveredCategory == equippedTuning then
						--	if hoveredCategory ~= equippedTuning then
								tuningCompleted = false
								acceptedTuningCreate = true
								totalUpgradeWidth = 0
								--wantedMinutes = 6000
								lastTickLoading = getTickCount()
						--	end
							if selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.color")) then
								tuningText = "Festés..."
								playSound("files/sounds/paint.mp3")
								wantedMinutes = 8500
							--	lastTickLoading = getTickCount()

							elseif selectedCategory == getMainCategoryIDByName(getLocalizedText("menu.extras")) then
								if selectedSubCategory == 6 then
									tuningText = "Festés..."
									playSound("files/sounds/paint.mp3")
									wantedMinutes = 8500
								--	lastTickLoading = getTickCount()
							elseif selectedSubCategory == 9 and hoveredCategory == 2 then
									tuningText = "Felszerelés..."
									playSound("files/sounds/newpart.mp3")
									wantedMinutes = 6000
								end
								tuningText = "Felszerelés..."
								playSound("files/sounds/newpart.mp3")
								wantedMinutes = 6000
							else
							--	if hoveredCategory ~= equippedTuning then
									tuningText = "Felszerelés..."
									playSound("files/sounds/newpart.mp3")
									wantedMinutes = 6000
								--	lastTickLoading = getTickCount()
							--	end
							end
						--end
					end
				end
			end

			if key == "mouse_wheel_up" and not promptDialog["state"] then
				if not isCursorShowing() and not isMTAWindowActive() then
					cameraSettings["zoom"] = math.max(cameraSettings["zoom"] - 5, 30)
					cameraSettings["zoomTick"] = getTickCount()
				end
			elseif key == "mouse_wheel_down" and not promptDialog["state"] then
				if not isCursorShowing() and not isMTAWindowActive() then
					cameraSettings["zoom"] = math.min(cameraSettings["zoom"] + 5, 60)
					cameraSettings["zoomTick"] = getTickCount()
				end
			end
		end
	end
end)

addEventHandler("tuning->ShowMenu", root, function(vehicle)
	if source and vehicle then
		if not panelState then
			enteredVehicle = vehicle

			createFonts()

			hoveredCategory, selectedCategory, selectedSubCategory = 1, 0, 0
			maxRowsPerPage, currentPage = 7, 1

			navigationBar[1][1] = getLocalizedText("navbar.select")
			navigationBar[2][1] = getLocalizedText("navbar.navigate")
			navigationBar[3][1] = getLocalizedText("navbar.back")

			if noticeData["timer"] then
				if isTimer(noticeData["timer"]) then
					killTimer(noticeData["timer"])
				end
			end

			noticeData = {
				["text"] = false,
				["type"] = "info",
				["tick"] = 0,
				["state"] = "",
				["height"] = 0,
				["timer"] = nil
			}

			local _, _, vehicleRotation = getElementRotation(enteredVehicle)
			local cameraRotation = vehicleRotation + 60

			cameraSettings = {
				["distance"] = 9,
				["movingSpeed"] = 2,
				["currentX"] = math.rad(cameraRotation),
				["defaultX"] = math.rad(cameraRotation),
				["currentY"] = math.rad(cameraRotation),
				["currentZ"] = math.rad(15),
				["maximumZ"] = math.rad(35),
				["minimumZ"] = math.rad(0),
				["freeModeActive"] = false,
				["zoomTick"] = 0,
				["zoom"] = 60
			}

			cameraSettings["moveState"] = "freeMode"

			promptDialog = {
				["state"] = false,
				["itemName"] = "",
				["itemPrice"] = 0
			}

			panelState = true
			setElementData(localPlayer,"toggleBinds",true)
			toggleAllControls(false)
			--setPlayerHudComponentVisible("all", false)
			showChat(false)
			showCursor(false)
            executeCommandHandler("togbar")
            --setElementData(localPlayer, "hudVisible", false)
            setElementData(localPlayer,"enableall", false)
            executeCommandHandler("togradar")

		end
	end
end)

addEventHandler("tuning->HideMenu", root, function()
	if enteredVehicle and panelState then
		panelState = false
		setElementData(localPlayer,"toggleBinds",false)
		toggleAllControls(true)
		triggerServerEvent("tuning->saveTuning", localPlayer, enteredVehicle)
	--	setPlayerHudComponentVisible("all", false)
		showChat(true)
		enteredVehicle = nil
		destroyFonts()
		setCameraTarget(localPlayer)
		showCursor(false)
		triggerServerEvent("tuning->ResetMarker", root, localPlayer)
        executeCommandHandler("togbar")
        executeCommandHandler("togradar")
        setElementData(localPlayer,"enableall", true)
        --setElementData(localPlayer, "hudVisible", true)
	end
end)

function moneyChange(amount)
	--takePlayerMoney(loopTable[hoveredCategory]["tuningPrice"])
	--setElementData(localPlayer, "money", getElementData(localPlayer, "money") - loopTable[hoveredCategory]["tuningPrice"])
	if amount < 5000 and amount ~= 0 then
		triggerServerEvent("ppChange", localPlayer, localPlayer, loopTable[hoveredCategory]["tuningPrice"])
	else
		triggerServerEvent("moneyChange", localPlayer, localPlayer, loopTable[hoveredCategory]["tuningPrice"])
	end
	--giveNotification("success", getLocalizedText("notification.success.purchased"))
	playSoundEffect("moneychange.wav")

	if amount > 0 then
		moneyChangeTable = {
			["tick"] = getTickCount() + 5000,
			["amount"] = amount
		}
	end
end

function createFonts()
	availableFonts = {
		chalet = dxCreateFont(":sas_hud/files/fonts/Roboto.ttf", 22 * scaleFactor, false, "antialiased"),
		icons = dxCreateFont("files/fonts/icons.ttf", 11 * scaleFactor, false, "antialiased")
	}
end

function destroyFonts()
	if availableFonts then
		for fontName, fontElement in pairs(availableFonts) do
			destroyElement(fontElement)
			availableFonts[fontName] = nil
		end

		availableFonts = nil
	end
end

function drawTextWithBorder(text, offset, x, y, w, h, borderColor, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenterX, fRotationCenterY)
	for offsetX = -offset, offset do
		for offsetY = -offset, offset do
			dxDrawText(text:gsub("#%x%x%x%x%x%x", ""), x + offsetX, y + offsetY, w + offsetX, h + offsetY, borderColor, scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenterX, fRotationCenterY)
		end
	end

	dxDrawText(text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenterX, fRotationCenterY)
end

function giveNotification(type, text)
	type = type or "info"

	if noticeData["timer"] then
		if isTimer(noticeData["timer"]) then
			killTimer(noticeData["timer"])
		end
	end

	noticeData = {
		["text"] = text,
		["type"] = type,
		["tick"] = getTickCount(),
		["state"] = "showNotice",
		["height"] = 0,
		["timer"] = nil
	}

	playSoundEffect("notification.mp3")
end

function getNavbarWidth()
	local barOffsetX = 0

	for _, row in ipairs(navigationBar) do
		local textLength = dxGetTextWidth(row[1], 0.5, availableFonts["chalet"]) + 20
		local navWidth = 0

		for id, icon in ipairs(row[2]) do
			local buttonWidth = 0

			if type(row[3]) == "string" and row[3] == "image" then
				buttonWidth = row[4]
			elseif type(row[3]) == "boolean" and row[3] then
				buttonWidth = dxGetTextWidth(availableIcons[icon], 1.0, availableFonts["icons"]) + 20
			elseif type(row[3]) == "boolean" and not row[3] then
				buttonWidth = dxGetTextWidth(icon, 0.5, availableFonts["chalet"]) + 10
			end

			navWidth = navWidth + buttonWidth + 10
		end

		barOffsetX = barOffsetX + (navWidth + textLength)
	end

	return barOffsetX
end

function hasPlayerMoney(money)
	--if getPlayerMoney(localPlayer) >= money then
	if selectR == 50 and selectG == 148 and selectB == 195 then
		if tonumber(getElementData(localPlayer, "pp")) >= money then
			return true
		end
		return false
	else
		if tonumber(getElementData(localPlayer, "money")) >= money then
			return true
		end
		return false
	end
end

function drawRoundedRectangle(x, y, w, h, rounding, borderColor, bgColor, postGUI)
	borderColor = borderColor or tocolor(0, 0, 0, 200)
	bgColor = bgColor or borderColor
	rounding = rounding or 2

	roundedRectangle(x, y, w, h, bgColor, postGUI)
	roundedRectangle(x + rounding, y - 1, w - (rounding * 2), 1, borderColor, postGUI)
	roundedRectangle(x + rounding, y + h, w - (rounding * 2), 1, borderColor, postGUI)
	roundedRectangle(x - 1, y + rounding, 1, h - (rounding * 2), borderColor, postGUI)
	roundedRectangle(x + w, y + rounding, 1, h - (rounding * 2), borderColor, postGUI)
end

function showDefaultOpticalUpgrade()
	if panelState then
		if enteredVehicle then
			if equippedTuning ~= 0 then
				removeVehicleUpgrade(enteredVehicle, equippedTuning)
			elseif equippedTuning == 0 then
				removeVehicleUpgrade(enteredVehicle, compatibleOpticalUpgrades[hoveredCategory])
			end
		end
	end
end

function showNextOpticalUpgrade()
	if panelState then
		if enteredVehicle then
			addVehicleUpgrade(enteredVehicle, compatibleOpticalUpgrades[hoveredCategory - 1])
		end
	end
end

function resetOpticalUpgrade()
	if panelState then
		if enteredVehicle then
			if equippedTuning ~= 0 then
				addVehicleUpgrade(enteredVehicle, equippedTuning)
			else
				if hoveredCategory - 1 == 0 then
					removeVehicleUpgrade(enteredVehicle, compatibleOpticalUpgrades[hoveredCategory])
				else
					removeVehicleUpgrade(enteredVehicle, compatibleOpticalUpgrades[hoveredCategory - 1])
				end
			end
		end
	end
end

function formatNumber(amount, spacer)
	if not spacer then
		spacer = ","
	end

	amount = math.floor(amount)

	local left, num, right = string.match(tostring(amount), "^([^%d]*%d)(%d*)(.-)$")
	return left .. (num:reverse():gsub("(%d%d%d)", "%1" .. spacer):reverse()) .. right
end

function playSoundEffect(soundFile)
	if soundFile then
		local soundEffect = playSound("files/sounds/" .. soundFile, false)

		setSoundVolume(soundEffect, 0.5)
	end
end

function getPositionFromElementOffset(element, offsetX, offsetY, offsetZ)
	local elementMatrix = getElementMatrix(element)
    local elementX = offsetX * elementMatrix[1][1] + offsetY * elementMatrix[2][1] + offsetZ * elementMatrix[3][1] + elementMatrix[4][1]
    local elementY = offsetX * elementMatrix[1][2] + offsetY * elementMatrix[2][2] + offsetZ * elementMatrix[3][2] + elementMatrix[4][2]
    local elementZ = offsetX * elementMatrix[1][3] + offsetY * elementMatrix[2][3] + offsetZ * elementMatrix[3][3] + elementMatrix[4][3]

    return elementX, elementY, elementZ
end

function getVehicleOffroadAbility(vehicle)
	if vehicle then
		local flags = getVehicleHandling(vehicle)["handlingFlags"]

		for name, flag in pairs(availableOffroadAbilities) do
			if isFlagSet(flags, flag[1]) then
				return flag[2]
			end
		end

		return 1
	end
end

function getVehicleWheelSize(vehicle, side)
	if vehicle and side then
		local flags = getVehicleHandling(vehicle)["handlingFlags"]

		for name, flag in pairs(availableWheelSizes[side]) do
			if isFlagSet(flags, flag[1]) then
				return flag[2]
			end
		end

		return 3
	end
end

function isGTAUpgradeSlot(slot)
	if slot then
		for i = 0, 16 do
			if slot == i then
				return true
			end
		end
	end

	return false
end

function isFlagSet(val, flag)
	return (bitAnd(val, flag) == flag)
end

function moveCameraToComponent(component, offsetX, offsetZ, zoom)
	if component then
		local _, _, vehicleRotation = getElementRotation(enteredVehicle)

		offsetX = offsetX or cameraSettings["defaultX"]
		offsetZ = offsetZ or 15
		zoom = zoom or 9

		local cameraRotation = vehicleRotation + offsetX

		cameraSettings["moveState"] = "moveToElement"
		cameraSettings["moveTick"] = getTickCount()
		cameraSettings["viewingElement"] = component
		cameraSettings["currentX"] = math.rad(cameraRotation)
		cameraSettings["currentY"] = math.rad(cameraRotation)
		cameraSettings["currentZ"] = math.rad(offsetZ)
		cameraSettings["distance"] = zoom
	end
end

function moveCameraToDefaultPosition()
	cameraSettings["moveState"] = "backToVehicle"
	cameraSettings["moveTick"] = getTickCount()
	cameraSettings["viewingElement"] = enteredVehicle

	cameraSettings["currentX"] = cameraSettings["defaultX"]
	cameraSettings["currentY"] = cameraSettings["defaultX"]
	cameraSettings["currentZ"] = math.rad(15)
	cameraSettings["distance"] = 9
end

function _getCameraPosition(element)
	if element == "component" then
		local componentX, componentY, componentZ = getVehicleComponentPosition(enteredVehicle, cameraSettings["viewingElement"])
		local elementX, elementY, elementZ = getPositionFromElementOffset(enteredVehicle, componentX, componentY, componentZ)
		local elementZ = elementZ + 0.2

		local cameraX = elementX + math.cos(cameraSettings["currentX"]) * cameraSettings["distance"]
		local cameraY = elementY + math.sin(cameraSettings["currentY"]) * cameraSettings["distance"]
		local cameraZ = elementZ + math.sin(cameraSettings["currentZ"]) * cameraSettings["distance"]

		return cameraX, cameraY, cameraZ, elementX, elementY, elementZ
	elseif element == "vehicle" then
		local elementX, elementY, elementZ = getElementPosition(enteredVehicle)
		local elementZ = elementZ + 0.2

		local cameraX = elementX + math.cos(cameraSettings["currentX"]) * cameraSettings["distance"]
		local cameraY = elementY + math.sin(cameraSettings["currentY"]) * cameraSettings["distance"]
		local cameraZ = elementZ + math.sin(cameraSettings["currentZ"]) * cameraSettings["distance"]

		return cameraX, cameraY, cameraZ, elementX, elementY, elementZ
	elseif element == "both" then
		if type(cameraSettings["viewingElement"]) == "string" then
			local componentX, componentY, componentZ = getVehicleComponentPosition(enteredVehicle, cameraSettings["viewingElement"])

			elementX, elementY, elementZ = getPositionFromElementOffset(enteredVehicle, componentX, componentY, componentZ)
		else
			elementX, elementY, elementZ = getElementPosition(enteredVehicle)
		end

		local elementZ = elementZ + 0.2

		local cameraX = elementX + math.cos(cameraSettings["currentX"]) * cameraSettings["distance"]
		local cameraY = elementY + math.sin(cameraSettings["currentY"]) * cameraSettings["distance"]
		local cameraZ = elementZ + math.sin(cameraSettings["currentZ"]) * cameraSettings["distance"]

		return cameraX, cameraY, cameraZ, elementX, elementY, elementZ
	end
end

function isValidComponent(vehicle, componentName)
	if vehicle and componentName then
		for component in pairs(getVehicleComponents(vehicle)) do
			if componentName == component then
				return true
			end
		end
	end

	return false
end

function setVehicleColorsToDefault()
	local vehicleColor = savedVehicleColors["all"]
	local vehicleLightColor = savedVehicleColors["headlight"]

	setVehicleColor(enteredVehicle, vehicleColor[1], vehicleColor[2], vehicleColor[3], vehicleColor[4], vehicleColor[5], vehicleColor[6], vehicleColor[7], vehicleColor[8], vehicleColor[9])
	setVehicleHeadLightColor(enteredVehicle, vehicleLightColor[1], vehicleLightColor[2], vehicleLightColor[3])
end

function setCameraAndComponentVisible()
	if getVehicleType(enteredVehicle) == "Automobile" then
		if loopTable[hoveredCategory]["cameraSettings"] then
			local cameraSetting = loopTable[hoveredCategory]["cameraSettings"]

			if isValidComponent(enteredVehicle, cameraSetting[1]) then
				moveCameraToComponent(cameraSetting[1], cameraSetting[2], cameraSetting[3], cameraSetting[4])
				playSound("files/sounds/cammove.mp3")
			end

			if cameraSetting[5] then
				setVehicleComponentVisible(enteredVehicle, cameraSetting[1], false)
			end
		end
	end
end

function generateString(len)
	if tonumber(len) then
		local allowed = {{1, 9}, {1, 9}}

		math.randomseed(getTickCount())

		local str = ""

		for i = 1, len do
			local charlist = allowed[math.random(1, 2)]

			if i == 3 then
				str = str .. " "
			else
				str = str .. string.char(math.random(charlist[1], charlist[2]))
			end
		end

		return utf8.upper(str)
	end

	return false
end

function isComponentCompatible(vehicle, vehicleType)
	if vehicle and vehicleType then
		if type(vehicleType) == "string" then
			if getVehicleType(vehicle) == vehicleType then
				return true
			else
				exports.hud:addNotification("A kiválasztott elem ("..loopTable[hoveredCategory]["categoryName"].. ") nem kompatibilis ezzel a járművel.", "error")
			end
		elseif type(vehicleType) == "table" then
			local typeFounded = false

			for _, modelType in pairs(vehicleType) do
				if modelType == getVehicleType(vehicle) then
					typeFounded = true
				end
			end

			if typeFounded then
				return true
			else
				exports.hud:addNotification("A kiválasztott elem ("..loopTable[hoveredCategory]["categoryName"].. ") nem kompatibilis ezzel a járművel.", "error")
			end
		end
	end

	return false
end

function drawBorder(x, y, w, h, size, color, postGUI)
	size = size or 2

	dxDrawRectangle(x - size, y, size, h, color or tocolor(0, 0, 0, 200), postGUI)
	dxDrawRectangle(x + w, y, size, h, color or tocolor(0, 0, 0, 200), postGUI)
	dxDrawRectangle(x - size, y - size, w + (size * 2), size, color or tocolor(0, 0, 0, 200), postGUI)
	dxDrawRectangle(x - size, y + h, w + (size * 2), size, color or tocolor(0, 0, 0, 200), postGUI)
end

function drawBorderedRectangle(x, y, w, h, borderSize, borderColor, bgColor, postGUI)
	borderSize = borderSize or 2
	borderColor = borderColor or tocolor(0, 0, 0, 200)
	bgColor = bgColor or borderColor

	dxDrawRectangle(x, y, w, h, bgColor, postGUI)
	drawBorder(x, y, w, h, borderSize, borderColor, postGUI)
end

addCommandHandler("markerpos", function()
	if getPedOccupiedVehicle(localPlayer) then
		local x, y, z = getElementPosition(getPedOccupiedVehicle(localPlayer))
		local _, _, rotation = getElementRotation(getPedOccupiedVehicle(localPlayer))

		setClipboard(x .. ", " .. y .. ", " .. z .. ", " .. rotation)
	else
		local x, y, z = getElementPosition(localPlayer)
		local rotation = getPedRotation(localPlayer)

		setClipboard(x .. ", " .. y .. ", " .. z .. ", " .. rotation)
	end

	outputDebugString("[TUNING]: Marker position set to Clipboard. Use [CTRL + V] to paste it.", 0, 2, 168, 255)
end)


function turbo()
	timer = setTimer(function()
		if (isPedInVehicle(getLocalPlayer())) then
			if (getElementData(getPedOccupiedVehicle(getLocalPlayer()), "vehicle.tuning.turbo") == false) then

			elseif (getElementData(getPedOccupiedVehicle(getLocalPlayer()), "vehicle.tuning.turbo") >= 3) then
				local cur = getVehicleCurrentGear(getPedOccupiedVehicle(getLocalPlayer()))
				if ((getElementData(getLocalPlayer(), "tuning.gear") or 0)<cur) and (cur==2 or cur>=3) then
					setElementData(getLocalPlayer(), "tuning.gear", cur)
					sounds = playSound("turbo.mp3")
				else
					setElementData(getLocalPlayer(), "tuning.gear", cur)
				end
			end
		else
			if isTimer(timer) then
				killTimer(timer)
			end
		end
	end,50,0)
end
addEvent("playTurboSound", true)
addEventHandler("playTurboSound", getRootElement(), turbo)

function roundedRectangle(x, y, w, h, borderColor, bgColor, postGUI)
	if (x and y and w and h) then
		if (not borderColor) then
			borderColor = tocolor(0, 0, 0, 180);
		end
		if (not bgColor) then
			bgColor = borderColor;
		end
		dxDrawRectangle(x, y, w, h, bgColor, postGUI);
		dxDrawRectangle(x + 2, y - 1, w - 4, 1, borderColor, postGUI);
		dxDrawRectangle(x + 2, y + h, w - 4, 1, borderColor, postGUI);
		dxDrawRectangle(x - 1, y + 2, 1, h - 4, borderColor, postGUI);
		dxDrawRectangle(x + w, y + 2, 1, h - 4, borderColor, postGUI);
	end
end

 

Link to comment

Pelo o que entendi do erro, o math.floor não está recebendo o valor amount como número.

Tente isso:

function formatNumber(amount, spacer)
	if not spacer then
		spacer = ","
	end

	amount = math.floor(tonumber(amount)) ---aqui esta apontando o erro

	local left, num, right = string.match(tostring(amount), "^([^%d]*%d)(%d*)(.-)$")
	return left .. (num:reverse():gsub("(%d%d%d)", "%1" .. spacer):reverse()) .. right
end

EDIT: Não testei.

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