Jump to content

[HELP] Command > Bind


Recommended Posts

Posted

Hello,

I have an Engine off/on but I want to use "x" instead of the command /switchengine

function switchEngine ( playerSource ) 
    local theVehicle = getPedOccupiedVehicle ( playerSource ) 
  
    if theVehicle and getVehicleController ( theVehicle ) == playerSource then 
        local state = getVehicleEngineState ( theVehicle ) 
        setVehicleEngineState ( theVehicle, not state ) 
    end 
end 
  
addCommandHandler ( "switchengine", switchEngine ) 

Thanks

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

@Solidsnake14

Should I make something like:

local root = getRootElement () 
local thisResourceRoot = getResourceRootElement(getThisResource()) 
  
function thisResourceStart () 
    local players = getElementsByType ( "player" ) 
    for k,v in ipairs(players) do 
        bindKey ( v, "x", "down", setVehicleEngine ) 
    end 
end 
  
function playerJoin () 
    bindKey ( source, "x", "down", setVehicleEngine ) 
end 
  
addEventHandler ( "onResourceStart", thisResourceRoot, thisResourceStart ) 
addEventHandler ( "onPlayerJoin", root, playerJoin ) 
  
function setVehicleEngine ( player, key, state ) 
    if ( getPedOccupiedVehicleSeat ( player ) == 0 ) then 
        local veh = getPedOccupiedVehicle ( player ) 
        end 
    end 
end 

Please don't be mad if I made a mistake, i'm still learning

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

I know,

I didn't know if there is a unbindKey code

Please help me a bit further

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted
@Solidsnake14

Should I make something like:

local root = getRootElement () 
local thisResourceRoot = getResourceRootElement(getThisResource()) 
  
function thisResourceStart () 
    local players = getElementsByType ( "player" ) 
    for k,v in ipairs(players) do 
        bindKey ( v, "x", "down", setVehicleEngine ) 
    end 
end 
  
function playerJoin () 
    bindKey ( source, "x", "down", setVehicleEngine ) 
end 
  
addEventHandler ( "onResourceStart", thisResourceRoot, thisResourceStart ) 
addEventHandler ( "onPlayerJoin", root, playerJoin ) 
  
function setVehicleEngine ( player, key, state ) 
    if ( getPedOccupiedVehicleSeat ( player ) == 0 ) then 
        local veh = getPedOccupiedVehicle ( player ) 
        end 
    end 
end 

Please don't be mad if I made a mistake, i'm still learning

Read again what I wrote on my first post, it'll be easier for you to do it ;).

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

Can you please tell me which codes I need;

-bindKey

-onVehicleEnter

-onVehicleExit

-getPedoccupiedVehicle

More codes?

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted
Can you please tell me which codes I need;

-bindKey

-onVehicleEnter

-onVehicleExit

-getPedoccupiedVehicle

More codes?

There's no need for 'getPedoccupiedVehicle'

You need :

unbindKey 

  

Posted

Okay,

I readed the Parameters on Wiki

  
bindKey(player, x, down, onEnter) 
  
function onEnter (player, x, down) 
end 
  
addEventHandler("onVehicleEnter", onEnter) 
  
unbindKey(player, x, down, onEnter) 
  
function onExit (player, x, down) 
end 
  
addEventHandler("onVehicleExit", onEnter) 

How does this look?

Only the Engine thing needs to be added

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

Make it easy try this server side :

function SwitchEngine( playerSource ) 
    local theVehicle = getPedOccupiedVehicle ( playerSource ) 
    if theVehicle and getVehicleController ( theVehicle ) == playerSource then 
        local state = getVehicleEngineState ( theVehicle ) 
        setVehicleEngineState ( theVehicle, not state ) 
    end 
end 
  
function BindKeys ( player ) 
    if ( eventName == "onVehicleStartEnter" ) then 
        bindKey ( player,"x","down",SwitchEngine ) 
    else 
        unbindKey ( player,"x","down",SwitchEngine ) 
    end 
end 
addEventHandler ( "onVehicleStartEnter", root, BindKeys ) 
addEventHandler ( "onVehicleStartExit", root, BindKeys ) 

Not tested yet .

  

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