Jump to content

Fuel Script... [ HELP / CODE ]


xScatta

Recommended Posts

Posted (edited)

Hey guys code here problem below.

CODE REMOVED

The problem is that when players will multiply have own cars and enter and re-enter it then debugscript outputs warning look at the addEventHandler Line at DropFuel().

Edited by Guest

It's fine to celebrate success but it is more important to heed the lessons of failure.

Posted

You aren't killing the timer on exit.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

That's wrong, that'll keep adding the event every time.

Do this:

Create a table to store the timers, then store the timers using the vehicle element as index, then create a function like 'dropFuel' but to kill the timer if exist.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Does that is correct? i don't tried with more than 1 player. ( Sent code at PM @Solidsnake14 )

It's fine to celebrate success but it is more important to heed the lessons of failure.

Posted

That code you sent me is wrong.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Why it is wrong?

CODE:

fuelTimers = {} 
  
function aFuel() 
    if not ( getElementData(source,"fuel") ) then 
    setElementData(source,"fuel",25) 
    end 
end 
  
function dropFuel(player,seat,jacked,vehicle,timer) 
    if getElementData(source,"fuel") then if  
      getVehicleController(source) then if 
          getVehicleEngineState(source)== true 
       then 
       vehicle = source 
       timer = setTimer ( function (vehiclex) local vehiclex = vehicle if getVehicleController(vehiclex) then if getVehicleEngineState(vehiclex)==true then if getElementData(vehiclex,"fuel")~= 0 then local vehiclex = vehicle setElementData(vehiclex,"fuel",getElementData(vehiclex,"fuel")-1)end end end end, 1000, 0 ) 
       fuelTimers[vehicle] = timer 
       addEventHandler("onVehicleExit",getRootElement(),killFuelTimer) 
end 
end 
end 
end 
  
function killFuelTimer() 
if source == fuelTimers[vehicle] then 
killTimer(fuelTimers[vehicle]) 
end 
end 
  
function testFuel(playerSource) 
    if isPedInVehicle(playerSource) then 
        if getVehicleController(getPedOccupiedVehicle(playerSource))== playerSource then 
            if getElementData(getPedOccupiedVehicle(playerSource),"fuel") then 
                if getElementData(getPedOccupiedVehicle(playerSource),"fuel")==0 then 
                    setVehicleEngineState(getPedOccupiedVehicle(playerSource),false) 
                    outputChatBox("Nie masz paliwa w samochodzie",playerSource) 
                    else 
                    outputChatBox("Masz paliwo w samochodzie",playerSource) 
                end 
                else outputChatBox("Ten pojazd nie ma paliwa w sobie",playerSource) 
            end 
        end 
    end 
end 
  
addCommandHandler("tf",testFuel) 
addEventHandler("onVehicleStartEnter",getRootElement(),aFuel) 
addEventHandler("onVehicleEnter",getRootElement(),dropFuel) 

It's fine to celebrate success but it is more important to heed the lessons of failure.

Posted
fuelTimers = { } 
  
function aFuel ( ) 
    if ( not getElementData ( source, "fuel" ) ) then 
        setElementData ( source, "fuel", 25 ) 
    end 
end 
  
function dropFuel ( player, seat, jacked ) 
    if getElementData ( source, "fuel" ) then 
        if getVehicleController ( source ) then 
            if ( getVehicleEngineState ( source ) == true ) then 
                fuelTimers [ source ] = setTimer ( 
                    function ( vehiclex ) 
                        if getVehicleController ( vehiclex ) then 
                            if ( getVehicleEngineState ( vehiclex ) == true ) then 
                                if ( getElementData ( vehiclex, "fuel" ) ~= 0 ) then 
                                    setElementData ( vehiclex, "fuel", getElementData ( vehiclex, "fuel" ) - 1 ) 
                                end 
                            end 
                        end 
                    end 
                    ,1000, 0, source 
                ) 
            end 
        end 
    end 
end 
  
function killFuelTimer ( _, seat ) 
    if ( seat == 0 ) then 
        if isTimer ( fuelTimers [ source ] ) then 
            killTimer ( fuelTimers [ source ] ) 
        end 
    end 
end 
addEventHandler ( "onVehicleExit", getRootElement(), killFuelTimer ) 
  
function testFuel ( playerSource ) 
    if isPedInVehicle ( playerSource ) then 
        local vehicle = getPedOccupiedVehicle ( playerSource ) 
        if ( getVehicleController ( vehicle ) == playerSource ) then 
            if getElementData ( vehicle, "fuel" ) then 
                if ( getElementData ( vehicle, "fuel" ) == 0 ) then 
                    setVehicleEngineState ( vehicle, false ) 
                    outputChatBox ( "Nie masz paliwa w samochodzie", playerSource ) 
                else 
                    outputChatBox ( "Masz paliwo w samochodzie", playerSource ) 
                end 
            else 
                outputChatBox ( "Ten pojazd nie ma paliwa w sobie", playerSource ) 
            end 
        end 
    end 
end 
addCommandHandler ( "tf", testFuel ) 
addEventHandler ( "onVehicleStartEnter", getRootElement(), aFuel ) 
addEventHandler ( "onVehicleEnter", getRootElement(), dropFuel ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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