Marckvdv Posted January 14, 2012 Share Posted January 14, 2012 So here I made a script, which allows me to bind functions to keys. Everything works fine, but I'm not able to unbind the keys EDIT: Im not receiving anny errors, and it doesn't give me the message "key has been binded to do: command" function bind(thePlayer, command, key, cmdToExecute, valueEntered) if(cmdToExecute == "unbind")then unbindKey(tostring(key)) outputChatBox(tostring(key) "succesfully unbinded.", thePlayer) else bindKey(thePlayer, tostring(key), cmdToExecute, valueEntered) outputChatBox(tostring(key) + "has been binded to do:" + tostring(cmdToExecute), thePlayer) end end addCommandHandler("bind", bind) PS: I'm new to lua scripting, and this forum Link to comment
codeluaeveryday Posted January 14, 2012 Share Posted January 14, 2012 bind is one of the main MTA commands, i think you should change it to something like /bindfunc. Here function bind(thePlayer, command, key, cmdToExecute, valueEntered) if(cmdToExecute == "unbind")then unbindKey(thePlayer,tostring(key)) outputChatBox(tostring(key) "successfully unbinded.", thePlayer,255,255,255) else bindKey(thePlayer, tostring(key), cmdToExecute, valueEntered) outputChatBox(tostring(key) + "has been binded to do:" + tostring(cmdToExecute), thePlayer, 255, 255, 255) end end addCommandHandler("bind", bind) I am not sure if you can bind other commands to bind key. Also look at executeCommandHandler(). Link to comment
Marckvdv Posted January 14, 2012 Author Share Posted January 14, 2012 Yes you can bind other commands to bind key. As i told, it works, the only thing I can't do is unbind the key function bindf(thePlayer, command, key, cmdToExecute, valueEntered) if(cmdToExecute == "unbind")then unbindKey(thePlayer, tostring(key), down) outputChatBox(tostring(key) "succesfully unbinded.", thePlayer) else bindKey(thePlayer, tostring(key), down, cmdToExecute, valueEntered) outputChatBox(tostring(key) + "has been binded to do:" + tostring(cmdToExecute), thePlayer) end end Forgot to add the player as argument of unbindkey, like you showed. Also: Im not receiving anny errors, and it doesn't give me the message "key has been binded to do: command" Link to comment
codeluaeveryday Posted January 14, 2012 Share Posted January 14, 2012 Ok, but is it now working? Link to comment
Marckvdv Posted January 14, 2012 Author Share Posted January 14, 2012 ...the only thing I can't do is unbind the key Im not receiving anny errors, and it doesn't give me the message "key has been binded to do: command" like it's supposed to do. Link to comment
codeluaeveryday Posted January 14, 2012 Share Posted January 14, 2012 I couldnt seem to unbind it either. Try this: function bind(thePlayer, command, key, cmdToExecute, valueEntered) if(cmdToExecute == "unbind")then unbindKey(thePlayer, tostring(key),"down") outputChatBox(key.." successfully unbinded.", thePlayer) else bindKey(thePlayer, tostring(key), "down", cmdToExecute, valueEntered) outputChatBox(key.." has been binded to do: "..cmdToExecute, thePlayer) end end addCommandHandler("bindf", bind) It shows chat now. Link to comment
Marckvdv Posted January 14, 2012 Author Share Posted January 14, 2012 EDIT: EVERYTHING WORKS NOW YAY! Just changed bind and unbind to bindf and unbindf like you told. Didnt know those commands worked in chat, aswell as in console. Thx for helping! --[[ I've lost my hope, i just changed it to: function bind(thePlayer, command, key, cmdToExecute, valueEntered) bindKey(thePlayer, tostring(key), "down", cmdToExecute, valueEntered) outputChatBox(key.."has been bound to do:"..cdmToExecute, thePlayer) end function unbind(thePlayer, command, key) unbindKey(thePlayer, tostring(key), "down") outputChatBox(key.."has been unbound!", thePlayer) end addCommandHandler("bindf", bind) -- <-- addCommandHandler("unbind", unbind) Binding works now, But for some reason, it doesn't print the text Also, even tough it says bindf, it works when you use bind And, I want it so that it binds a function to a key, but doesn't mess up the actual controls --]] Link to comment
Klesh Posted January 14, 2012 Share Posted January 14, 2012 Did you put in meta client side or server side? Is server side. 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