xScatta Posted October 21, 2013 Posted October 21, 2013 (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 October 21, 2013 by Guest
Castillo Posted October 21, 2013 Posted October 21, 2013 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.
xScatta Posted October 21, 2013 Author Posted October 21, 2013 Does that is correct? i don't tried with more than 1 player. ( Sent code at PM @Solidsnake14 )
xScatta Posted October 23, 2013 Author Posted October 23, 2013 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)
Castillo Posted October 23, 2013 Posted October 23, 2013 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 )
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