Jump to content

Problems with bindKey + setVehicleEngineState.


LucasMorais

Recommended Posts

Posted

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.

Posted
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) 

Posted

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 

Posted

By the way, i want to make some work with GUI now. I want to start with something like... a phone system. If i want to do an iPhone, do I need a clean image, without the icons or it can be with the icons? (I'll see the topic tomorrow, gotta sleep)

Posted

Well... I would say that you need it without the Icons, and they has to be apart, else they'll be just part of the iPhone main image.

P.S: I suggest you to use guieditor for GUI/DX Drawing scripts ;).

Posted

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

Posted

guieditor is a resource just like any other, type /start guieditor and done.

WARNING: DON'T PUT THE RESOURCE AS A .ZIP, MUST BE A FOLDER ONLY.

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