Jump to content

Problems with bindKey + setVehicleEngineState.


LucasMorais

Recommended Posts

Hello. I am new at MTA/LUA scripting and I am trying to do a system that when I press one key, the engines turns on, and when I press another key, the engine turns off. But, when I type /bindit, enter the car and press the key, there is an error at the server console. It is like this: "Bad argument @ setVehicleEngineState". This is the system, it's server-side.

function engineOn(player, key, keyState, theVehicle) 
if(keyState == "down") then 
setVehicleEngineState(theVehicle, true) 
end 
end 
  
function engineOff(player, key, keyState, theVehicle) 
if(keyState == "down") then 
setVehicleEngineState(theVehicle, false) 
end 
end 
  
function bindTheKeys(player, commandName) 
bindKey(player, "j", "down", engineOn) 
bindKey(player, "k", "down", engineOff) 
end 
addCommandHandler("bindit", bindTheKeys) 

Thanks.

Link to comment
function engineOn(player, key, keyState) 
    if(keyState == "down") then 
    if not isPedInVehicle(player) then return end 
        local theVehicle = getPedOccupiedVehicle(player) 
        setVehicleEngineState(theVehicle, true) 
    end 
end 
  
function engineOff(player, key, keyState, theVehicle) 
    if(keyState == "down") then 
    if not isPedInVehicle(player) then return end 
        local theVehicle = getPedOccupiedVehicle(player)     
        setVehicleEngineState(theVehicle, false) 
    end 
end 
  
function bindTheKeys(player, commandName) 
    bindKey(player, "j", "down", engineOn) 
    bindKey(player, "k", "down", engineOff) 
end 
addCommandHandler("bindit", bindTheKeys) 

Link to comment

Yup, there is, here:

addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, player in pairs(getElementsByType("player")) do 
        bindKey(player, "j", "down", engineOn) 
        bindKey(player, "k", "down", engineOff)      
    end 
end) 
  
addEventHandler("onPlayerJoin",root, 
function () 
    bindKey(source, "j", "down", engineOn) 
    bindKey(source, "k", "down", engineOff) 
end) 
  
function engineOn(player, key, keyState) 
    if(keyState == "down") then 
    if not isPedInVehicle(player) then return end 
        local theVehicle = getPedOccupiedVehicle(player) 
        setVehicleEngineState(theVehicle, true) 
    end 
end 
  
function engineOff(player, key, keyState, theVehicle) 
    if(keyState == "down") then 
    if not isPedInVehicle(player) then return end 
        local theVehicle = getPedOccupiedVehicle(player)    
        setVehicleEngineState(theVehicle, false) 
    end 
end 

Link to comment

I don't want to be rude... but, it explains how to use it.

Usage:

- to start editing type /guied or press shift + g, do it again to stop

- to edit a GUI element right click on it

- the parent of the element you are creating will be the element you right clicked on

For example: right clicking a window and selecting "Create Button" will create a button within the window

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