Jump to content

A little problem


alcholistu

Recommended Posts

function checkBinds() 
        if getBoundKeys("reconnect") or getBoundKeys("disconnect") then -- if has reconnect and disconnect bound 
                  outputChatBox ("You musn't have this key bound.", 255, 0, 0) -- 
                  unbindKey ( source, getBoundKeys ("reconnect") , "both" ) -- unbind key 
                  unbindKey ( source, getBoundKeys ("disconnect") , "both" ) -- unbind key 
        end 
end 
setTimer(checkBinds, 60000, 0) 

Show the Warning but it doesn't unbind the keys...

Source is the player who has the key bound ?

Link to comment

getBoundKeys returns an array, which means you have to loop through the array and remove each one in it.

local illegalHandlers = { "reconnect", "disconnect" } 
  
function checkBinds( ) 
    local wasWarned 
    for _, handler in ipairs( illegalHandlers ) do 
        if ( getBoundKeys( handler ) ) then 
            for key, state in pairs( getBoundKeys( handler ) ) do 
                unbindKey( key, state, handler ) 
            end 
             
            if ( not wasWarned ) then 
                outputChatBox( "You mustn't have this key bound.", 255, 0, 0, false ) 
                wasWarned = true 
            end 
        end 
    end 
end 
setTimer( checkBinds, 60000, 0 ) 

Note, that this is client-side code, so make sure to have the script set to client-side in meta.xml configuration file.

EDIT: Copy the code again. Been scripting other languages all day long so I went crazy with the brackets, heh.

Link to comment
getBoundKeys returns an array, which means you have to loop through the array and remove each one in it.
local illegalHandlers = { "reconnect", "disconnect" } 
  
function checkBinds( ) 
    local wasWarned 
    for _, handler in ipairs( illegalHandlers ) do 
        if ( getBoundKeys( handler ) ) then 
            for key, state in pairs( getBoundKeys( handler ) ) do 
                unbindKey( key, state, handler ) 
            end 
             
            if ( not wasWarned ) then 
                outputChatBox( "You mustn't have this key bound.", 255, 0, 0, false ) 
                wasWarned = true 
            end 
        end 
    end 
end 
setTimer( checkBinds, 60000, 0 ) 

Note, that this is client-side code, so make sure to have the script set to client-side in meta.xml configuration file.

EDIT: Copy the code again. Been scripting other languages all day long so I went crazy with the brackets, heh.

It unbinds...

Only send the message

(( nothing in debugscript O_o ))

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