dener189 Posted August 4, 2019 Share Posted August 4, 2019 This script is a gas system. Not from my altoria. Error message: "main.Lua:16: attempt to compare string with number" and "main.Lua:16: attempt to compare string with number [DUP 5x]" -Main.Lua factor = 0.03 function createVehicles(player) for i,v in ipairs(getElementsByType("vehicle")) do fuel = math.random(10,25) setElementData(v, "fuel", fuel) end end function processFuel(player) for i,v in ipairs(getElementsByType("vehicle")) do local fuel = getElementData(v, "fuel") or math.random(10,25) if (getVehicleEngineState(v) and fuel > 0 ) then fuel = fuel - factor end if (fuel <= 0.99) then fuel = 0 setVehicleEngineState(v, false) end setElementData(v, "fuel", fuel) end end createVehicles() setTimer(processFuel, 1000, 0) Link to comment
Moderators IIYAMA Posted August 4, 2019 Moderators Share Posted August 4, 2019 @dener189 It looks like the fuel system has changed the value to a string. At least not within the code you are currently showing. local fuel = tonumber(getElementData(v, "fuel")) or math.random(10,25) Oh and btw, using this code will ruin your network. So use with caution. You do not want this to happen: So, my recommendation: if getElementData(v, "fuel") ~= fuel then setElementData(v, "fuel", fuel) end Link to comment
dener189 Posted August 6, 2019 Author Share Posted August 6, 2019 On 04/08/2019 at 17:47, IIYAMA said: @ dener189 Parece que o sistema de combustível mudou o valor para uma string. Pelo menos não dentro do código que você está mostrando no momento. Ah, e btw, usando esse código vai arruinar sua rede. Portanto, use com cautela. Você não quer que isso aconteça: Então, minha recomendação: I'll be sending all the tracks from all the scripts "postos.Lua" local markersPostos = { {city = "LS-2", x = -99.317001342773, y = -1172.4971923828, z = 1.4453792572021, style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -95.26969909668, y = -1174.9270019531, z = 1.2943935394287, style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -88.415390014648, y = -1177.2751464844, z = 1.1038908958435, style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -83.929489135742, y = -1166.6140136719, z = 1.279646396637, style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -83.929489135742, y = -1166.6140136719, z = 1.279646396637, style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -91.114555358887, y = -1163.8930664063, z = 1.316956281662, style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -86.747230529785, y = -1163.6921386719, z = 1.216748714447, style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 1943.6787109375, y = -1778.5, z = 12.390598297119,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 1943.9921875, y = -1771.1083984375, z = 12.390598297119,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 1939.2060546875, y = -1771.4345703125, z = 12.3828125,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 1939.3017578125, y = -1778.236328125, z = 12.390598297119,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 2120.9228515625, y = 927.486328125, z = 9.8203125,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 2114.7607421875, y = 927.7734375, z = 9.8203125,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 2114.951171875, y = 917.513671875, z = 9.8203125,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 70.021484375, y = 1218.794921875, z = 17.810596466064,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -2029.5693359375,y = 157.0537109375, z = 27.8359375,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -2023.94140625, y = 156.91796875, z = 27.8359375,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -2407.7900390625, y = 981.638671875, z = 44.296875,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -2407.966796875, y = 971.537109375, z = 44.296875,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 2205.5888671875, y = 2469.7236328125, z = 9.8203125,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 2205.7412109375, y = 2480.01953125, z = 9.8203125,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 2194.095703125, y = 2475.271484375, z = 9.8203125,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 2194.220703125, y = 2470.84765625, z = 9.8203125,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -1602.03125, y = -2710.5712890625, z = 47.5390625,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -1605.4091796875, y = -2714.3037109375, z = 47.533473968506,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -1608.5830078125, y = -2718.638671875, z = 47.5390625,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 622.9189453125, y = 1680.3486328125, z = 5.9921875,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 615.6982421875, y = 1690.5673828125, z = 5.9921875,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 608.8447265625, y = 1700.0146484375, z = 5.9921875,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 1008.3486328125, y = -939.84375, z = 41.1796875,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 999.6259765625, y = -940.79296875, z = 41.1796875,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -92.314453125, y = -1176.08984375, z = 1.2067136764526,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -94.1083984375, y = -1161.775390625, z = 1.2461423873901,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 1873.2841796875, y = -2380.119140625, z = 12.5546875,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = -1280.7412109375, y = -0.7314453125, z = 13.1484375,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 1574.8916015625, y = 1449.80078125, z = 9.8299560546875,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170}, {city = "LS-2", x = 354.5390625, y = 2538.3251953125, z = 15.717609405518,style = "cylinder", font = 1.0, r = 255, g = 165, b = 0, opaccity = 170} } local blipsGasStations = { {city = "LSBLIP", x = 1943.6787109375, y = -1778.5,12.390598297119, z = 12.390598297119, icon = 44, size = 4, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = 2120.9228515625, y = 927.486328125, z = 9.8203125, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = 70.021484375, y = 1218.794921875, z = 17.810596466064, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = -2029.5693359375, y = 157.0537109375, z = 27.8359375, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = -2407.7900390625, y = 981.638671875, z = 44.296875, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = 2205.5888671875, y = 2469.7236328125, z = 9.8203125, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = -1602.03125, y = -2710.5712890625, z = 47.5390625, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = 622.9189453125, y = 1680.3486328125, z = 5.9921875, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = 1008.3486328125, y = -939.84375, z = 41.1796875, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = -92.314453125, y = -1176.08984375, z = 1.2067136764526, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = 1873.2841796875, y = -2380.119140625, z = 12.5546875, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = -1280.7412109375, y = -0.7314453125, z = 13.1484375, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = 1574.8916015625, y = 1449.80078125, z = 9.8299560546875, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = 354.5390625, y = 2538.3251953125, z = 15.717609405518, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, {city = "LSBLIP", x = -1676.64453125, y = 411.70034790039, z = 7.1796875, icon = 44, size = 2, r = 0, g = 0, b = 0, a = 0, ordering = 0, visibleDistance = 200}, } function createGasStations() for i,v in ipairs(markersPostos) do local m = createMarker(v.x, v.y, v.z, v.style, v.font, v.r, v.g, v.b, v.opaccity) addEventHandler("onClientMarkerHit", m, refuelCar) end end function createBlipsFromGasStations() for i,v in ipairs(blipsGasStations) do local b = createBlip(v.x, v.y, v.z, v.icon, v.size, v.r, v.g, v.b, v.a, v.ordering, v.visibleDistance) end end function refuelCar(player) if (player ~= localPlayer) then return false end local seat = getPedOccupiedVehicleSeat(localPlayer) if(seat ~= 0) then return else addEventHandler("onClientRender", root, drawImages) end end createGasStations() createBlipsFromGasStations() function bindFromRefulling() local vehicle = getPedOccupiedVehicle(localPlayer) triggerServerEvent("onVehicleRefulling", localPlayer, vehicle) end function bindFromRefullingFull() local vehicle = getPedOccupiedVehicle(localPlayer) triggerServerEvent("onVehicleRefullingFull", localPlayer, vehicle) end function getVehicleFuel(v) local fuel = getElementData(v, "fuel") if (fuel) then return fuel end return 0 end function dxDrawBorderedText( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI ) dxDrawText ( text, x - 1, y - 1, w - 1, h - 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x + 1, y - 1, w + 1, h - 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x - 1, y + 1, w - 1, h + 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x + 1, y + 1, w + 1, h + 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x - 1, y, w - 1, h, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x + 1, y, w + 1, h, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x, y - 1, w, h - 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x, y + 1, w, h + 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI ) end x,y = guiGetScreenSize() MaxFuel = 100 price = "5,00" tick = getTickCount() addEventHandler("onClientMarkerLeave", root, function (player) if (player ~= localPlayer) then return false end removeEventHandler("onClientRender", root, drawImages) end ) x, y = guiGetScreenSize() local font = "default-bold" function resX(value) return (value/800) * x end function resY(value) return (value/600) * y end function drawImages(v) local pedInVehicle = getPedOccupiedVehicle(localPlayer) local fuel = getVehicleFuel(pedInVehicle) dxDrawRectangleGradiente(x*0.35,y*0.2,resX(125),resY(170),0,0,0,200,"left") dxDrawRectangleGradiente(x*0.35+resX(125),y*0.2,resX(125),resY(170),0,0,0,200,"right") dxDrawRectangleGradiente(x*0.35,y*0.2,resX(150),resY(30),180,0,0,200,"left") dxDrawRectangleGradiente(x*0.35+resX(100),y*0.2,resX(150),resY(30),180,0,0,200,"right") dxDrawRecLine(x*0.35,y*0.2,resX(250),resY(30),tocolor(0,0,0,255)) dxDrawRecLine(x*0.35,y*0.2,resX(250),resY(170),tocolor(0,0,0,255)) dxDrawText("POSTO DE COMBUSTIVEL",x*0.35,y*0.2,x*0.35+resX(250),y*0.2+resY(30),tocolor(255,255,255,255),resY(1.4),font,"center","center",true) dxText("Combustivel: #FF0000" .. math.floor(fuel)*1000/1000 .. "%",x*0.35+resX(20),y*0.2+resY(30),x*0.35+resX(260),y*0.2+resY(60),255,255,255,255,1,font,"left","center",true,false,false,true) if (MaxFuel - fuel) < 1 then dxText("Abastecer: #FF0000"..(MaxFuel) - math.floor(fuel) .. " %",x*0.35+resX(20),y*0.2+resY(50),x*0.35+resX(260),y*0.2+resY(80),255,255,255,255,1,font,"left","center",true,false,false,true) else dxText("Abastecer: #FF0000"..(MaxFuel) - math.floor(fuel)*1000/1000 .. "%",x*0.35+resX(20),y*0.2+resY(50),x*0.35+resX(260),y*0.2+resY(80),255,255,255,255,1,font,"left","center",true,false,false,true) end dxText("Preço por Litro: #FF0000$5 = 1%",x*0.35+resX(20),y*0.2+resY(70),x*0.35+resX(260),y*0.2+resY(100),255,255,255,255,1,font,"left","center",true,false,false,true) dxText("Para Abastecer por #FF0000% #FFFFFFaperte: #FF0000L",x*0.35+resX(20),y*0.2+resY(90),x*0.35+resX(260),y*0.2+resY(120),255,255,255,255,1,font,"left","center",true,false,false,true) dxText("Para Encher o Tanque aperte: #FF0000K",x*0.35+resX(20),y*0.2+resY(110),x*0.35+resX(260),y*0.2+resY(140),255,255,255,255,1,font,"left","center",true,false,false,true) dxText("Meu Dinheiro: #FF0000$"..convertNumber( getPlayerMoney(getLocalPlayer())).."",x*0.35+resX(20),y*0.2+resY(130),x*0.35+resX(260),y*0.2+resY(160),255,255,255,255,1,font,"left","center",true,false,false,true) if (getKeyState("L") and (getTickCount() - tick) > 600 and fuel <= 100) then bindFromRefulling() tick = getTickCount() playSound("sounds/song.mp3") end if (getKeyState("K") and (getTickCount() - tick) > 600 and fuel <= 100) then bindFromRefullingFull() tick = getTickCount() playSound("sounds/song.mp3") end end --addEventHandler("onClientRender",root,painelfreeroam) function convertNumber ( number ) local formatted = number while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if ( k==0 ) then break end end return formatted end function dxDrawRecLine(x,y,w,h,color) dxDrawRectangle(x,y,w,1,color) -- h dxDrawRectangle(x,y+h-1,w,1,color) -- h dxDrawRectangle(x,y,1,h,color) -- v dxDrawRectangle(x+w-1,y,1,h,color) -- v end function dxText(text,x,y,w,h,red,green,blue,alpha,scale,font,a,b,c,d,e,f) dxDrawText(string.gsub(text,"(#%x%x%x%x%x%x)",""),x+1,y+1,w+1,h+1,tocolor(0,0,0,alpha),scale,font,a,b,c,d,e,f) dxDrawText(text,x,y,w,h,tocolor(red,green,blue,alpha),scale,font,a,b,c,d,e,f) end function dxDrawRectangleGradiente(x,y,w,h,r,g,b,a,direction) if not x or not y or not w or not h or not r or not g or not b or not a or not direction then return outputDebugString("arguments not correspond") end if direction == "left" then local space = (w/a) for i=1,a do local now = space+(i*space) dxDrawRectangle(x+w+space-now,y,space,h,tocolor(r,g,b,i)) end elseif direction == "right" then local space = (w/a) for i=1,a do local now = space+(i*space) dxDrawRectangle(x-(space*2)+now,y,space,h,tocolor(r,g,b,i)) end elseif direction == "down" then local space = (h/a) for i=1,a do local now = space+(i*space) dxDrawRectangle(x,y+now,w,space,tocolor(r,g,b,i)) end elseif direction == "up" then local space = (h/a) for i=1,a do local now = space+(i*space) dxDrawRectangle(x,y+h-now,w,space,tocolor(r,g,b,i)) end else return outputDebugString("direction invalid") end end "carhud.Lua" local screenW,screenH = guiGetScreenSize() local resW,resH = 1366,768 local x,y = (screenW/resW), (screenH/resH) local font = dxCreateFont("fonts/font.ttf", 10) local MaxFuel = 100 function getVehicleFuel(v) local fuel = getElementData(v, "fuel") if (fuel) then return fuel end return 0 end function onPlayerRequestHUD() local asd = getPedOccupiedVehicle(localPlayer) local seat = getPedOccupiedVehicleSeat(localPlayer) if (seat ~= 0) then return end if not (asd) then return else local fuel = getVehicleFuel(asd) dxDrawText("", x*1000, y*800, x*1431, y*714, tocolor(255, 255, 255, 255), y*1, font, "left", "center", false, false, false, true, false) end end addEventHandler("onClientRender", root, onPlayerRequestHUD) function dxDrawRecLine(x,y,w,h,color) dxDrawRectangle(x,y,w,1,color) -- h dxDrawRectangle(x,y+h-1,w,1,color) -- h dxDrawRectangle(x,y,1,h,color) -- v dxDrawRectangle(x+w-1,y,1,h,color) -- v end "carfunctions.Lua" local addingFuel = {} addEvent("onVehicleRefulling", true) function vehicleRefulling(v) if (getPlayerMoney(source) < 5) then outputChatBox("#000000[ #FF0000GASOLINA #000000] #ffffffVocê não tem dinheiro $10", source, 255, 255, 255, true) else setElementData(v, "fuel", getElementData(v, "fuel") + 1) takePlayerMoney(source, 5) end end addEventHandler("onVehicleRefulling", root, vehicleRefulling) addEvent("onVehicleRefullingFull", true) function vehicleRefullingf(v) gabas = 100 - getElementData(v, "fuel") if (getPlayerMoney(source) < tonumber(gabas*5)) then outputChatBox("#000000[ #FF0000GASOLINA #000000] #ffffffVocê não tem dinheiro $"..convertNumber (gabas*5).."", source, 255, 255, 255, true) else setElementData(v, "fuel", getElementData(v, "fuel")+gabas+1) takePlayerMoney(source, tonumber(gabas*5)) end end addEventHandler("onVehicleRefullingFull", root, vehicleRefullingf) function convertNumber ( number ) local formatted = number while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if ( k==0 ) then break end end return formatted end Link to comment
Moderators IIYAMA Posted August 6, 2019 Moderators Share Posted August 6, 2019 1 hour ago, dener189 said: I'll be sending all the tracks from all the scripts Why? The error was only about 1 line of code. Link to comment
dener189 Posted August 6, 2019 Author Share Posted August 6, 2019 9 hours ago, IIYAMA said: Por quê? ?"> O erro foi apenas cerca de 1 linha de código. I sent because I don't know where the error is, and may have other errors in other scripts Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now