Jump to content

"chatbox" Control unbinds, Not working right.


AfuSensi

Recommended Posts

Hey,

I'm trying to make an bind system for my script, it binds a key to a chatbox command.

So for purpose of testing, i made a simple script to showcase what's going wrong.

bindKeyTable = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"} 
  
  
function bindTheKeys() 
    for f, u in pairs(bindKeyTable) do 
        bindKey(tostring(u), "down", "chatbox", tostring(f) ) 
    end 
end 
addEventHandler("onClientResourceStart", resourceRoot, bindTheKeys) 
  
function UnbindThem(n, whatnumber) 
        outputChatBox("Unbound "..whatnumber) 
        unbindKey( tostring(whatnumber), "down", "chatbox" ) 
  
end 
addCommandHandler( "unbindme", UnbindThem) -- usage, /unbindme (number/key) 

As you can see, it creates chatbox binds from number 1 to 10. And adds a command to unbind a cerntain key.

But if i use the command, it deletes all binds for the chatbox made by this resource.

Is this wrong?

unbindKey( tostring(whatnumber), "down", "chatbox" ) 

Thanks.

Link to comment
Your mistake is here:
for f, u in pairs(bindKeyTable) do 

f, u indicates that it's an ipairs which is not the case.

This is actually not the problem, and wasnt really my question. It does not matter in what order the keys bind, only if they bind.

The problem is if i unbind 1 bind,

function UnbindThem(n, whatnumber) 
        outputChatBox("Unbound "..whatnumber) 
        unbindKey( tostring(whatnumber), "down", "chatbox" ) 
  
end 
addCommandHandler( "unbindme", UnbindThem) -- usage, /unbindme (number/key) 

It removes all binds bound the the chatbox control.

This might be an MTA bug, thats why i created this simple script for people to test or if i have the syntax for unbindKey wrong in this case.

If you want to test it on your own way, make 2 binds to the control "chatbox", and then unbind one of them, Both will be gone.

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