Jump to content

[HELP] Command > Bind


Recommended Posts

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

Link to comment

@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

Link to comment
@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 ;).

Link to comment

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

Link to comment

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 .

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