Jump to content

bindKey on playerlogin and unBindKey on player logout


Fantanic

Recommended Posts

Posted

Hello ,

I would like to know if its posible to bind a key on playerlogin and unbind the key on playerlogout (i got some problems with login panel wich is ; if i press M for example M panel shows up

bindKey("M", "down", showPanel)

Greetings ,

Jonas

Posted
  
function bind() 
bindKey("M", "down", showPanel) 
end 
addEventHandler("onPlayerLogin",bind) 
  
  
function unbind() 
unBindKey("M", "down", showPanel) 
end 
addEventHandler("onPlayerQuit",unbind) 
  
  

?

Posted
  
[lua]function bind() 
bindKey("M", "down", showPanel) 
end 
addEventHandler("onPlayerLogin",bind) 
  
  
function unbind() 
unBindKey("M", "down", showPanel) 
end 
addEventHandler("onPlayerQuit",unbind) 
  

 

 [/lua]

?

function bind() 
bindKey("M", "down", showPanel) 
end 
addEventHandler("onPlayerLogin",bind) 
  
  
function unbind() 
unbindKey("M", "down", showPanel) 
end 
addEventHandler("onPlayerLogout",unbind) 
  
  

 [/lua]

Posted

Use bindkey("M", "down", showPanel) when player log in and unbindKey("M", "down", showPanel) when the player log out.

If bindkey is on the client-side, you will need to use triggerClientEvent.

Posted

What do u mean exactly with the triggerClientEvent , like this ;

  
function unbind1() 
triggerClientEvent 
end 
addEventHandler("onPlayerLogout",unbind1) 
  
  
  

Posted
  
-- serverside code 
local showPanel = function() 
    triggerClientEvent("onPlayerRequestPanel",player) 
end 
  
addEventHandler("onPlayerLogin",root,function() 
    bindKey(source,"m","down",showPanel,source) 
end) 
addEventHandler("onPlayerLogout",root,function() 
    unbindKey(source,"m","down",showPanel) 
end) 
  
-- clientside code 
addEvent("onPlayerRequestPanel",true) 
addEventHandler("onPlayerRequestPanel",resourceRoot,function() 
    -- your panel function here 
end) 
  

Posted
What do u mean exactly with the triggerClientEvent , like this ;
  
function unbind1() 
triggerClientEvent 
end 
addEventHandler("onPlayerLogout",unbind1) 
  

Like this:

--Server 
addEventHandler( "onPlayerLogin",  
    function() 
        triggerClientEvent(source, "doEnablePanel", source) 
    end 
) 
  
addEventHandler( "onPlayerLogout",  
    function() 
        triggerClientEvent(source, "doDisablePanel", source) 
    end 
) 

--Client 
addEvent("doDisablePanel", true) 
addEvent("doEnablePanel", true) 
  
function disablePanel() 
    unbindKey("M", "down", showPanel) 
end 
addEventHandler("doDisablePanel", root, disablePanel) 
  
function enablePanel() 
    bindKey("M", "down", showPanel) 
end 
addEventHandler("doEnablePanel", root, enablePanel) 

The client must be in the same script that the panel is in.

Posted

You forgot about the baseElement in addEventHandler.

--Server 
addEventHandler( "onPlayerLogin", root, 
    function() 
        triggerClientEvent(source, "doEnablePanel", source) 
    end 
) 
  
addEventHandler( "onPlayerLogout", root, 
    function() 
        triggerClientEvent(source, "doDisablePanel", source) 
    end 
) 

Posted
You forgot about the baseElement in addEventHandler.
--Server 
addEventHandler( "onPlayerLogin", root, 
    function() 
        triggerClientEvent(source, "doEnablePanel", source) 
    end 
) 
  
addEventHandler( "onPlayerLogout", root, 
    function() 
        triggerClientEvent(source, "doDisablePanel", source) 
    end 
) 

Oh, my bad.

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