Jump to content

Boost Script problem...


Ninja

Recommended Posts

Hey all,

can anyone help me?

Why do the second boost not work?

--Made by Ninja-- 
local root = getRootElement() 
boostTimer = false 
local currentlyBoosting = false 
  
function onCarDownResourceStart(resource) 
    bindKey("lalt", "down", startBoost) 
    bindKey("lalt", "up", stopBoost) 
    bindkey("lshift", "down", startBoost2) 
    bindkey("lshift", "up", stopBoost2) 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onCarDownResourceStart) 
  
  
function startBoost (key, keyState) 
    local vehicle = getPlayerOccupiedVehicle ( getLocalPlayer () ) 
    if ( vehicle ) then 
        if ( getVehicleController ( vehicle ) == getLocalPlayer () ) then 
            boostTimer = setTimer(startCarBoost, 50, 0, vehicle) 
            --outputChatBox ( "boostTimer=" .. tostring(boostTimer) ) 
            currentlyBoosting = true 
        else 
            outputChatBox( "You need to be the driver!", 255, 0, 0 ) 
        end 
    end 
end 
  
function startCarBoost(vehicle) 
    local vehSpeedX, vehSpeedY, vehSpeedZ = getElementVelocity ( vehicle ) 
    setElementVelocity ( vehicle, vehSpeedX*1.1, vehSpeedY*1.1, vehSpeedZ*1) 
end 
  
function startBoost2 (key, keyState) 
    local vehicle = getPlayerOccupiedVehicle ( getLocalPlayer () ) 
    if ( vehicle ) then 
        if ( getVehicleController ( vehicle ) == getLocalPlayer () ) then 
            boostTimer = setTimer(startCarBoost2, 50, 0, vehicle) 
            --outputChatBox ( "boostTimer=" .. tostring(boostTimer) ) 
            currentlyBoosting = true 
        else 
            outputChatBox( "You need to be the driver!", 255, 0, 0 ) 
        end 
    end 
end 
  
function startCarBoost2(vehicle) 
    local vehSpeedX, vehSpeedY, vehSpeedZ = getElementVelocity ( vehicle ) 
    setElementVelocity ( vehicle, vehSpeedX*1, vehSpeedY*1, vehSpeedZ*1.1) 
end 
  
function stopBoost( key, keystate ) 
    if ( currentlyBoosting ) then 
        --outputChatBox ( "boostTimer=" .. tostring(boostTimer) ) 
        killTimer( boostTimer ) 
        currentlyBoosting = false 
    end 
end 
  
function stopBoost2( key, keystate ) 
    if ( currentlyBoosting ) then 
        --outputChatBox ( "boostTimer=" .. tostring(boostTimer) ) 
        killTimer( boostTimer ) 
        currentlyBoosting = false 
    end 
end 

Link to comment

try this:

--Made by Ninja-- 
boostTimer = false 
local currentlyBoosting = false 
  
function onCarDownResourceStart(resource) 
    bindKey("lalt", "down", startBoost) 
    bindKey("lalt", "up", stopBoost) 
    bindKey("lshift", "down", startBoost2) 
    bindKey("lshift", "up", stopBoost2) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onCarDownResourceStart) 
  
  
function startBoost (key, keyState) 
    local vehicle = getPedOccupiedVehicle (localPlayer) 
    if ( vehicle ) then 
        if ( getVehicleController ( vehicle ) == getLocalPlayer() ) then 
            boostTimer = setTimer(startCarBoost, 50, 0, vehicle) 
            --outputChatBox ( "boostTimer=" .. tostring(boostTimer) ) 
            currentlyBoosting = true 
        else 
            outputChatBox( "You need to be the driver!", 255, 0, 0 ) 
        end 
    end 
end 
  
function startCarBoost(vehicle) 
    local vehSpeedX, vehSpeedY, vehSpeedZ = getElementVelocity ( vehicle ) 
    setElementVelocity ( vehicle, vehSpeedX*1.1, vehSpeedY*1.1, vehSpeedZ*1) 
end 
  
function startBoost2 (key, keyState) 
    local vehicle = getPedOccupiedVehicle ( getLocalPlayer () ) 
    if ( vehicle ) then 
        if ( getVehicleController ( vehicle ) == getLocalPlayer () ) then 
            boostTimer = setTimer(startCarBoost2, 50, 0, vehicle) 
            --outputChatBox ( "boostTimer=" .. tostring(boostTimer) ) 
            currentlyBoosting = true 
        else 
            outputChatBox( "You need to be the driver!", 255, 0, 0 ) 
        end 
    end 
end 
  
function startCarBoost2(vehicle) 
    local vehSpeedX, vehSpeedY, vehSpeedZ = getElementVelocity ( vehicle ) 
    setElementVelocity ( vehicle, vehSpeedX*1, vehSpeedY*1, vehSpeedZ*1.1) 
end 
  
function stopBoost( key, keystate ) 
    if ( currentlyBoosting == true ) then 
        --outputChatBox ( "boostTimer=" .. tostring(boostTimer) ) 
        killTimer( boostTimer ) 
        currentlyBoosting = false 
        boostTimer = false 
    end 
end 
  
function stopBoost2( key, keystate ) 
    if ( currentlyBoosting == true) then 
        --outputChatBox ( "boostTimer=" .. tostring(boostTimer) ) 
        killTimer( boostTimer ) 
        boostTimer = false 
        currentlyBoosting = false 
    end 
end 

Edited by Guest
Link to comment
local bBoostState, pTimer 
  
addEventHandler( 'onClientKey', root, 
    function( sButton, bPressed ) 
        local pVehicle = getPedOccupiedVehicle ( localPlayer ) 
        if getVehicleController ( pVehicle ) == localPlayer  then 
            if sButton == 'lshift' and not bBoostState then 
                bBoostState = true 
                pTimer = setTimer( 
                    function( pVehicle ) 
                        if pVehicle and isElement( pVehicle ) and getElementType( pVehicle ) == 'vehicle' then 
                            local fVehSpeedX, fVehSpeedY, fVehSpeedZ = getElementVelocity ( pVehicle ) 
                            setElementVelocity ( pVehicle, fVehSpeedX * 1.1, fVehSpeedY * 1.1, fVehSpeedZ * 1 ) 
                        end 
                    end, 
                50, 0, pVehicle ) 
            elseif sButton == 'lalt' and bBoostState then 
                if isTimer( pTimer ) then 
                    bBoostState = nil 
                    killTimer( pTimer ) 
                    pTimer = nil 
                end 
            end 
        else 
            outputChatBox( 'You need to be the driver!', 255, 0, 0 ) 
        end 
    end 
) 
  

Edited by Guest
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...