Jump to content

Tanken script!


Recommended Posts

Hallo,

Laatst heb ik een script gedownload die er voor zorgt dat je moet tanken in de server.

Nu heb ik de script geprobeerd en werkt deze bij mij niet.

Het probleem is als ik naar een tankstation toe rij en de marker in rij tankt hij.

Maar hij blijft maar tanken en stopt er niet meer.

Ook als ik weg rij blijft hij de tank vullen.

Ik hoop dat iemand mij kan helpen met dit probleem.

Ik plaats de script hier onder.

(De eigenaar van deze script is Nidza a.k.a CodeMaster)

Meta.xml

    'Nidza a.k.a CodeMaster' version='1.5.0' name='Vehicle Fuel Script BETA' type='script' /> 
    

cvehiclefuel.lua

function onEnterRefillArea(player,sDimension) 
    triggerClientEvent("onGasRefill",getRootElement(),true) 
end 
addEventHandler("onMarkerHit",getRootElement(),onEnterRefillArea) 
  
function onExitRefillArea(playerplayer,sDimension) 
        triggerClientEvent("onGasRefill",getRootElement(),false) 
end 
addEventHandler("onMarkerLeave",getRootElement(),onExitRefillArea) 

cvehiclefuel_c.lua

addEvent("onGasRefill",true) 
function setUp(startedResource) 
    if(startedResource == getThisResource()) then 
        oX,oY,oZ = getElementPosition(getLocalPlayer()) 
        fBar = guiCreateProgressBar(598,158,154,25,false) 
        fLabel = guiCreateLabel(615,140,155,25,"Fuel:",false) 
        setTimer(fuelDepleting,500,0) 
        distance = 0 
        distanceOld = 0 
    end 
end 
addEventHandler("onClientResourceStart",getRootElement(),setUp) 
  
function drawFuelBar() 
    fBar = guiCreateProgressBar(598,158,154,25,false) 
    guiSetVisible(fBar,false) 
end 
addEventHandler("onClientPlayerJoin",getRootElement(),drawFuelBar) 
  
function monitoring() 
    if(isPlayerInVehicle(getLocalPlayer())) then 
        vehicle = getPlayerOccupiedVehicle(getLocalPlayer()) 
        x,y,z = getElementPosition(getLocalPlayer()) 
        distance = distance + getDistanceBetweenPoints3D(x,y,z,oX,oY,oZ) 
        oX = x 
        oY = y 
        oZ = z 
    end 
end 
addEventHandler("onClientRender",getRootElement(),monitoring) 
  
function fuelDepleting() 
    if(isPlayerInVehicle(getLocalPlayer())) then 
        vehicle = getPlayerOccupiedVehicle(getLocalPlayer()) 
        guiSetVisible(fBar,true) 
        if(getElementData(vehicle,"fuel") == false) then 
            fuel = math.random(85,100) 
            setElementData(vehicle,"fuel",tonumber(fuel)) 
        end 
        currentFuel = tonumber(getElementData(vehicle,"fuel")) 
        if(currentFuel > 0) then 
            setElementData(vehicle,"fuel",tostring(currentFuel - math.floor(distance - distanceOld)/200)) 
            currentFuel = tonumber(getElementData(vehicle,"fuel")) 
            guiProgressBarSetProgress(fBar,currentFuel) 
            guiSetText(fLabel,"Fuel Tank: " .. math.floor(currentFuel) .. "%") 
            distanceOld = distance 
        else 
            toggleControl("accelerate",false) 
            toggleControl("brake_reverse",false)     
            guiSetText(fLabel,"Fuel Tank: Empty") 
        end 
    else 
        guiSetText(fLabel,"Fuel Tank: Out Of Vehicle") 
        guiProgressBarSetProgress(fBar,0) 
        guiSetVisible(fBar,false) 
    end 
end 
  
function setFuel(player,seat,jacked) 
    if(getElementData(vehicle,"fuel") == false) then 
        fuel = math.random(70,100) 
        setElementData(source,"fuel",tonumber(fuel)) 
    end 
end 
addEventHandler("onClientVehicleEnter",getRootElement(),setFuel) 
  
function setFuelOnRespawn() 
    local fuel = math.random(70,100) 
    setElementData(source,"fuel",tonumber(fuel)) 
end 
addEventHandler("onClientVehicleRespawn",getRootElement(),setFuelOnRespawn) 
  
function enableDriving(player,seat) 
    toggleControl("accelerate",true) 
    toggleControl("brake_reverse",true) 
end 
addEventHandler("onClientVehicleExit",getRootElement(),enableDriving) 
  
function refillGas() 
    if(isPlayerInVehicle(getLocalPlayer()) and isPlayer) then 
        local vehicle = getPlayerOccupiedVehicle(getLocalPlayer()) 
        setElementData(vehicle,"fuel","100") 
        outputChatBox("Refilled") 
        toggleControl("accelerate",true) 
        toggleControl("brake_reverse",true) 
    end 
end 
addCommandHandler("refill",refillGas) 
  
function setTimerRefillGas(enabled) 
    if(isPlayerInVehicle(getLocalPlayer())) then 
        if(enabled == true) then 
            refillTimer = setTimer(timerRefillGas,100,0) 
        else 
            killTimer(refillTimer) 
        end 
    else 
        outputChatBox("You have to be in vehicle to refill!") 
    end 
end 
addEventHandler("onGasRefill",getRootElement(),setTimerRefillGas) 
  
function timerRefillGas() 
    if(isPlayerInVehicle(getLocalPlayer())) then 
        local player = getLocalPlayer() 
        local vehicle = getPlayerOccupiedVehicle(player) 
        local fuel = getElementData(vehicle,"fuel") 
        if(tonumber(fuel) < 100) then 
            setElementData(vehicle,"fuel",tostring(fuel + 1)) 
            distanceOld = distance 
        end 
    end 
end 
  

markers.map

    "-2024.2071533203" posY="156.86796569824" posZ="29.8359375" type="cylinder" color="#FF0000" />  
    "2114.6799316406" posY="920.03802490234" posZ="10.8203125" type="cylinder" color="#FF0000" />  
    "2639.9396972656" posY="1106.4301757813" posZ="10.376944541931" type="cylinder" color="#FF0000" />  
    "2147.025390625" posY="2747.4851074219" posZ="10.392276763916" type="cylinder" color="#FF0000" />  
    "2202.6599121094" posY="2474.2084960938" posZ="10.389625549316" type="cylinder" color="#FF0000" />  
    "1595.8334960938" posY="2199.1372070313" posZ="10.392153739929" type="cylinder" color="#FF0000" />  
    "292.55081176758" posY="2541.2055664063" posZ="16.820880889893" type="cylinder" color="#FF0000" />  
    "611.92376708984" posY="1694.8377685547" posZ="6.9921875" type="cylinder" color="#FF0000" />  
    "-1328.3668212891" posY="2677.4641113281" posZ="50.0625" type="cylinder" color="#FF0000" />  
     
    "-2024.2071533203" posY="156.86796569824" posZ="29.8359375" icon="40" />  
    "2114.6799316406" posY="920.03802490234" posZ="10.8203125" icon="40" />  
    "2639.9396972656" posY="1106.4301757813" posZ="10.376944541931" icon="40" />  
    "2147.025390625" posY="2747.4851074219" posZ="10.392276763916" icon="40" />  
    "2202.6599121094" posY="2474.2084960938" posZ="10.389625549316" icon="40" />  
    "1595.8334960938" posY="2199.1372070313" posZ="10.392153739929" icon="40" />  
    "292.55081176758" posY="2541.2055664063" posZ="16.820880889893" icon="40" />  
    "611.92376708984" posY="1694.8377685547" posZ="6.9921875" icon="40" />  
    "-1328.3668212891" posY="2677.4641113281" posZ="50.0625" icon="40" />  

Link to comment
  • 4 weeks later...

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