Jump to content

unbindKey & bindKey problem


novo

Recommended Posts

Hello.

I'm trying to unbind the key "L" but it doesn't seem to work. I'm using server-sided script

I'm using the following code; (Not working)

  
unbindKey(thePlayer, "l") 
bindKey(thePlayer, "l", "both", "chatbox Ad") 
  

I've tried also with using:

  
        if(executeCommandHandler ( "unbind", thePlayer, "l" )) then 
        else 
        outputDebugString("COULDN'T unBIND") 
        end 
        if(executeCommandHandler ( "bind", thePlayer, "l chatbox Ad" )) then 
        else 
        outputDebugString("COULDN'T BIND") 
        end 
  

But it's outputing COULDN'T messages.

Link to comment
  
function joinLang(thePlayer,commandName,lang) 
local languageNames = {} 
for i = 1, #languageNames do 
    if ( lang == languageNames[ i ] ) then 
        bindKey ( thePlayer, "l", "up", "chatbox "..lang ) 
        addCommandHandler(lang, chatMSG) 
        setElementData(thePlayer, "lang", lang) 
    end 
end 
end 
addCommandHandler("join", joinLang) 
  

Link to comment

I just want to do that when you press L it shows you English: and then you can type, like T (added by MTA)

The following code is outputing CANT BIND

  
    if not executeCommandHandler("bind l chatbox English", thePlayer, "") then 
    outputChatBox("CANT BIND") 
    end 
  

Link to comment
What you can do instead is create just one bind, for "Language" chat, and then it checks the player language and sends it to only these with the same language.

I only need to know how to make a bind for L that when you press L it shows you Language: and then you can type..

Only that

Link to comment

Your code is not correct, there should be just one word, the name of the command at argument one, and the additional parameters at the end of the function, like this:

executeCommandHandler("bind", thePlayer, "l chatbox English") 

And I think you cant use executeCommandHandler on commands like say, bind, quit (etc.) and commands from other resources, only on commands that you added with addCommandHandler in the same resource.

Link to comment

Try this:

addEventHandler ( "onPlayerJoin", root, 
    function ( ) 
        bindKey ( source, "l", "down", "chatbox", "Language" ) 
    end 
) 
  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            bindKey ( player, "l", "down", "chatbox", "Language" ) 
        end 
    end 
) 
  
addCommandHandler ( "Language", 
    function ( thePlayer, _, ... ) 
        local playerLanguage = getElementData ( thePlayer, "lang" ) 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            if ( getElementData ( player, "lang" ) == playerLanguage ) then 
                outputChatBox ( playerLanguage ..": ".. getPlayerName ( thePlayer ) ..": ".. table.concat ( { ... }, " " ), player, 255, 255, 255 ) 
            end 
        end 
    end 
) 

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