Jump to content

Need unbind help, not working


Marckvdv

Recommended Posts

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 :mrgreen:

Link to comment

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

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

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

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 :o

And, I want it so that it binds a function to a key, but doesn't mess up the actual controls :/

--]]

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