Jump to content

Why it's not unbinding the key?


King12

Recommended Posts

Hello there,

I just want to know why it's not working and it's not outputing any erros:

function starts() 
    setTimer( 
        function () 
            for i,v in pairs(getElementsByType("player")) do 
                if (isKeyBound (v,"m")) then 
                unbindKey(v, "M") 
                    outputChatBox("Done") 
                else 
                    outputChatBox("Couldn't unbind the key") 
                end 
            end 
        end 
    , 2000, 1) 
end 
addEventHandler("onGamemodeMapStart", root, starts) 
addEventHandler("onClientMapStarting",root, starts) 
addEventHandler("onResourceStart", root, starts) 

It keeps saying Couldn't unbind the key.

Also, I have to functions for drawing a text when the map starts.

I want when the player disable it and the next map starts while it's disabled it reset back to false.

  
function startss() 
setTimer( 
function (thePlayer) 
enabled = false 
removeEventHandler("onClientRender",getRootElement(),mapwindowa) 
removeEventHandler("onClientRender",getRootElement(),mapwindowda) 
unbindKey(getElementData ( resourceRoot, "Bindkey" )) 
bindKey( getElementData ( resourceRoot, "Bindkey" ),"down",toggleHideAll) 
bindKey( getElementData ( resourceRoot, "Bindkey" ),"down",slowvol) 
end 
,50,2) 
end 
addEventHandler("onGamemodeMapStart", root, startss) 
addEventHandler("onClientMapStarting",root, startss) 
  
function toggleHideAll(thePlayer) 
    startTimess = getTickCount() 
        if enabled == false then 
        local removeit = setTimer( function () unbindKey(thePlayer, getElementData ( resourceRoot, "Bindkey" )) end, 50,1) 
        removeEventHandler("onClientRender",getRootElement(),mapwindowa) 
        addEventHandler("onClientRender",getRootElement(),mapwindowda) 
    else 
        local removeit1 = setTimer( function () unbindKey(thePlayer, getElementData ( resourceRoot, "Bindkey" )) end, 50,1) 
        removeEventHandler("onClientRender",getRootElement(),mapwindowda) 
        addEventHandler("onClientRender",getRootElement(),mapwindowa) 
    end 
    enabled = not enabled 
end 
bindKey( getElementData ( resourceRoot, "Bindkey" ),"down", toggleHideAll) 
  
function windowa() 
dxDrawText("Enabled",165+(sx-400)/2,beta+60,((sx-400)/2)+400,beta+85,tocolor(255,255,255),1.7,"default","left","top",true) 
end 
  
function windowda() 
dxDrawText("Disabled",165+(sx-400)/2,beta+60,((sx-400)/2)+400,beta+85,tocolor(255,255,255),1.7,"default","left","top",true) 
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...