Jump to content

[AJUDA] Script de Gasolina


Recommended Posts

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

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