Jump to content

[Help] Set and get Data


MAB

Recommended Posts

why the fuel isn't going down?! am i using the data wrong?

*NOTE: this isn't the full script it is just the function that the error is in..

function updateFuel() 
local veh = getPedOccupiedVehicle( localPlayer ) 
                   if isPedInVehicle ( localPlayer ) then 
                      if getVehicleEngineState ( veh ) == true then 
                         CurrentFuelValue = getElementData(veh,"Fuel")  
                         NewFuelValue   = CurrentFuelValue - 1 
                         timer = setTimer ( setElementData, 10*1000, 0, veh, "fuel", tonumber(NewFuelValue) ) 
                       end 
                      if getVehicleEngineState ( veh ) == false then 
                         if timer then 
                            killTimer ( timer ) 
                          end 
                       end 
                    end 
 if (CurrentFuelValue==0) then 
  setVehicleEngineState(veh,false) 
 end 
end 
addEventHandler ("onClientRender", getLocalPlayer(), updateFuel) 

Link to comment
lastTick = 0 
function updateFuel() 
    if isPedInVehicle ( localPlayer ) then 
        local veh = getPedOccupiedVehicle( localPlayer ) 
        if getVehicleEngineState ( veh ) == true then 
            CurrentFuelValue = getElementData(veh,"Fuel") 
            if (CurrentFuelValue == 0) then 
                setVehicleEngineState(veh,false) 
                return 
            end 
            if getTickCount() - lastTick <= 10000 then 
                lastTick = getTickCount() 
                setElementData(veh,"Fuel",CurrentFuelValue-1) 
            end 
        end 
    end 
end 
addEventHandler ("onClientRender", getLocalPlayer(), updateFuel) 

Link to comment

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