joao2235 Posted September 3, 2019 Share Posted September 3, 2019 Server-Side possui 2 arquivos. 1: factor = 0.03 function createVehicles(player) for i,v in ipairs(getElementsByType("vehicle")) do fuel = math.random(70,80) 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(70,80) 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) 2: 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 Client-Side: local sx,sy = guiGetScreenSize() local px,py = 1366,768 local x,y = (sx/px), (sy/py) function gas() local vehicle = getPedOccupiedVehicle( getLocalPlayer() ) local gasosa = math.floor(getElementData(vehicle,"fuel") or 11) if ( vehicle ) then dxDrawRectangle(x*1125 - 2, y*718 - 2, x*100 + 4, y*27 + 4, tocolor(0, 0, 0, 140), false) dxDrawRectangle(x*1125, y*718, x*100, y*27, tocolor(0, 0, 0, 30), false) if gasosa <= 100 then dxDrawRectangle(x*1125, y*718, x*100/100*gasosa, y*27, tocolor(243, 0, 0, 255), false) else dxDrawRectangle(x*1125, y*718, x*100, y*27, tocolor(243, 0, 0, 255), false) end end end addEventHandler("onClientRender", root, gas) Como posso fazer para que veículos que não possuam motor, como por exemplo a bike não apareça o indicador de Gasolina ? PS: O lado do server-side não foi eu quem fiz. Link to comment
Other Languages Moderators Lord Henry Posted September 3, 2019 Other Languages Moderators Share Posted September 3, 2019 Com isso: if (getVehicleType (vehicle) ~= "BMX") then -- Se o veículo não for uma bicicleta, então: Link to comment
joao2235 Posted September 3, 2019 Author Share Posted September 3, 2019 Certo, coloquei isso no lado do servidor e funcionou. Mas a minha dúvida é como faço para não aparecer a barra da gasolina (client-side) quando o player entra na bike por exemplo. Link to comment
Other Languages Moderators Lord Henry Posted September 3, 2019 Other Languages Moderators Share Posted September 3, 2019 Faz no lado client também ué. Link to comment
joao2235 Posted September 3, 2019 Author Share Posted September 3, 2019 2 hours ago, Lord Henry said: Faz no lado client também ué. local sx,sy = guiGetScreenSize() local px,py = 1366,768 local x,y = (sx/px), (sy/py) function gas() local vehicle = getPedOccupiedVehicle( getLocalPlayer() ) local gasosa = math.floor(getElementData(vehicle,"fuel") or 11) if ( vehicle ) then if (getVehicleType (vehicle) ~= "BMX") then -- Se o veículo não for uma bicicleta, então: dxDrawRectangle(x*1125 - 2, y*718 - 2, x*100 + 4, y*27 + 4, tocolor(0, 0, 0, 140), false) dxDrawRectangle(x*1125, y*718, x*100, y*27, tocolor(0, 0, 0, 30), false) if gasosa <= 100 then dxDrawRectangle(x*1125, y*718, x*100/100*gasosa, y*27, tocolor(243, 0, 0, 255), false) else dxDrawRectangle(x*1125, y*718, x*100, y*27, tocolor(243, 0, 0, 255), false) end end end end addEventHandler("onClientRender", root, gas) Ficaria dessa forma ? Link to comment
Other Languages Moderators Lord Henry Posted September 3, 2019 Other Languages Moderators Share Posted September 3, 2019 (edited) Está com erros de indentação, mas a lógica é essa. Edited September 3, 2019 by Lord Henry Link to comment
joao2235 Posted September 4, 2019 Author Share Posted September 4, 2019 (edited) 1 hour ago, Lord Henry said: Está com erros de indentação, mas a lógica é essa. Consegui mestre, valeu pela força! Edited September 4, 2019 by joao2235 Link to comment
Other Languages Moderators Lord Henry Posted September 4, 2019 Other Languages Moderators Share Posted September 4, 2019 De nada, deixe um Thanks nas respostas que lhe ajudaram como agradecimento. 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