Jump to content

[Duvida/Ajuda] Gasolina


Recommended Posts

Posted

Estou utilizando um script de gasolina que está funcionando perfeitamente, porem está consumindo gasolina em bikes, o que tentei fazer é que ao subir nas bikes, a gasolina fosse para 100, mas sem sucesso, e ao meu ver seria muito melhor se em bikes, a gasolina não descesse mas não imagino como poderia ser feito

 

Spoiler

-- server side -- Tentativa de ao subir na bike 

function bike ( player )
	for i,v in ipairs(getElementsByType("vehicle")) do
	local id = getElementModel ( v )
	local fuel2 = 100
	if id == 481 then
	--setElementData(localPlayer, "fuel", fuel2)
      setElementData(v, "fuel", fuel2)
    end
end
end
addEventHandler ( "onPlayerVehicleEnter", root, bike )

 

Spoiler

-- Script Full

factor = 0.03

function createVehicles(player)
	for i,v in ipairs(getElementsByType("vehicle")) do
		fuel = math.random(95,100)
		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(95,100)
		local id = getElementModel ( v )
		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)

--[[function bike ( player )
	for i,v in ipairs(getElementsByType("vehicle")) do
	local id = getElementModel ( v )
	local fuel2 = 100
	if id == 481 then
		setElementData(localPlayer, "fuel", fuel2)
	  --setElementData(v, "fuel", fuel2)
    end
end
end
addEventHandler ( "onPlayerVehicleEnter", root, bike )]]--

 

 

Posted

Quase fez certo, porem, você poderia ter bloqueado diretamente no timer de combustivel.

function processFuel(player)
   for i,v in ipairs(getElementsByType("vehicle")) do
      local id = getElementModel ( v )
      if (id == 509) or (id == 481) or (id == 510) then return end --/> Verifica o ID, caso for o ID da Bike, Então retorna.
         --id 509 :Bike id 481: BMX id 510 : Mountain Bike
         local fuel = getElementData(v, "fuel") or math.random(95,100)
         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

ou, bloquei diretamente na função que cria gasolina nos veiculos.

Posted
Spoiler
2 hours ago, Angelo Pereira said:

Quase fez certo, porem, você poderia ter bloqueado diretamente no timer de combustivel.



function processFuel(player)
   for i,v in ipairs(getElementsByType("vehicle")) do
      local id = getElementModel ( v )
      if (id == 509) or (id == 481) or (id == 510) then return end --/> Verifica o ID, caso for o ID da Bike, Então retorna.
         --id 509 :Bike id 481: BMX id 510 : Mountain Bike
         local fuel = getElementData(v, "fuel") or math.random(95,100)
         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

ou, bloquei diretamente na função que cria gasolina nos veiculos.

 

Testei isso, porem sempre que um carro é spawnado, ele fica com 0 de gasolina, e quando eu removo o if que tu adicionou, ele volta ao normal
 

Spoiler

-- codigo com o que tu adicionou

factor = 0.03

function createVehicles(player)
	for i,v in ipairs(getElementsByType("vehicle")) do
		fuel = math.random(95,100)
		setElementData(v, "fuel", fuel)
	end
end

function processFuel(player)
	for i,v in ipairs(getElementsByType("vehicle")) do
		local id = getElementModel ( v )
	   if (id == 509) or (id == 481) or (id == 510) then return end --/> Verifica o ID, caso for o ID da Bike, Então retorna.
		  --id 509 :Bike id 481: BMX id 510 : Mountain Bike
		  local fuel = getElementData(v, "fuel") or math.random(95,100)
		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)

 


 

  • Other Languages Moderators
Posted

Mais fácil simplesmente verificar se o tipo de veículo é bicicleta e não diminuir o combustível neles.

getVehicleType

  • Like 1
Posted (edited)
1 hour ago, Lord Henry said:

Mais fácil simplesmente verificar se o tipo de veículo é bicicleta e não diminuir o combustível neles.

getVehicleType

Problema, que também afetaria as motos.

Tente isso :

 
-- Script Full

factor = 0.03

--[[function createVehicles( player )
	for i,v in ipairs(getElementsByType("vehicle")) do
		local fuel = math.random(95,100)
		setElementData(v, "fuel", fuel)
	end
end--]]

function processFuel ( )
   for i, v in ipairs(getElementsByType("vehicle")) do
      if not (getElementModel(v) == 509) and not (getElementModel(v) == 481) and not (getElementModel(v) == 510) then --/> Adicione os ID que Bloqueará !
         local fuel = getElementData(v, "fuel") or math.random(95,100)
         if getVehicleEngineState(v) and fuel > 0 then 
            fuel = fuel - factor
            setElementData(v, "fuel", fuel)
         end
         if (fuel <= 0.99) then
            fuel = 0
            setVehicleEngineState(v, false)
         end
      end
   end
end

--createVehicles() --/> Não é necessário, o timer já fez isso.
setTimer(processFuel, 1000, 0)

 

Edited by Angelo Pereira
  • Thanks 1
  • Other Languages Moderators
Posted

Motos são do tipo "Bike" e bicicletas são do tipo "BMX"

Posted
7 minutes ago, Lord Henry said:

Motos são do tipo "Bike" e bicicletas são do tipo "BMX"

Humm, bom saber disso, na WIKI Vehicle, está desatualizado então, pois, dentro de Bike estão motos e bikes

  • Other Languages Moderators
Posted

Não sei onde vc viu isso, aqui pra mim só marca motorbikes (motos).

  • Automobile: Cars, vans and trucks
  • Plane
  • Bike: Motorbikes
  • Helicopter
  • Boat
  • Train
  • Trailer: A trailer for a truck
  • BMX
  • Monster Truck
  • Quad: Quadbikes
Posted
Spoiler
17 hours ago, Angelo Pereira said:

Tente isso :



 
-- Script Full

factor = 0.03

--[[function createVehicles( player )
	for i,v in ipairs(getElementsByType("vehicle")) do
		local fuel = math.random(95,100)
		setElementData(v, "fuel", fuel)
	end
end--]]

function processFuel ( )
   for i, v in ipairs(getElementsByType("vehicle")) do
      if not (getElementModel(v) == 509) and not (getElementModel(v) == 481) and not (getElementModel(v) == 510) then --/> Adicione os ID que Bloqueará !
         local fuel = getElementData(v, "fuel") or math.random(95,100)
         if getVehicleEngineState(v) and fuel > 0 then 
            fuel = fuel - factor
            setElementData(v, "fuel", fuel)
         end
         if (fuel <= 0.99) then
            fuel = 0
            setVehicleEngineState(v, false)
         end
      end
   end
end

--createVehicles() --/> Não é necessário, o timer já fez isso.
setTimer(processFuel, 1000, 0)

 

 

Deu super certo, mais uma vez obrigado ^^

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