LucasMorais Posted August 12, 2011 Share Posted August 12, 2011 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
Castillo Posted August 12, 2011 Share Posted August 12, 2011 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
LucasMorais Posted August 12, 2011 Author Share Posted August 12, 2011 Hey, thanks! It worked, but.. is there anyway to bind the keys without typing "/bindit"? Link to comment
Castillo Posted August 12, 2011 Share Posted August 12, 2011 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
LucasMorais Posted August 12, 2011 Author Share Posted August 12, 2011 Thanks again. Can I ask you a question? (I am already, *laughs*) Can you teach me LUA? Link to comment
Castillo Posted August 12, 2011 Share Posted August 12, 2011 You welcome. And... I haven't got much time even for myself, also I suck at explaining, sorry dude . Link to comment
LucasMorais Posted August 12, 2011 Author Share Posted August 12, 2011 That's okay. But I hope that you answer all my questions Just kidding. Link to comment
Castillo Posted August 12, 2011 Share Posted August 12, 2011 Hehehe, I'll always help here when I can, I like to help ppl around, to learn and then they'll help others in future (I hope ) . Link to comment
LucasMorais Posted August 12, 2011 Author Share Posted August 12, 2011 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) Link to comment
Castillo Posted August 12, 2011 Share Posted August 12, 2011 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 . Link to comment
LucasMorais Posted August 12, 2011 Author Share Posted August 12, 2011 Okay, but... how do I use the guieditor and how I use it to do the GUI part of the iPhone? Link to comment
Castillo Posted August 12, 2011 Share Posted August 12, 2011 Meh, maybe you should real his description? Link to comment
LucasMorais Posted August 12, 2011 Author Share Posted August 12, 2011 Well, I have it in my pc, but I rode the description and I didn't find the way to make it work. Link to comment
Castillo Posted August 12, 2011 Share Posted August 12, 2011 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
LucasMorais Posted August 12, 2011 Author Share Posted August 12, 2011 No, not like that. I put it in "server\resources\guieditor", but I don't know what command I need to type to "activate" it. Link to comment
Castillo Posted August 12, 2011 Share Posted August 12, 2011 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now