Jump to content

bindKey on playerlogin and unBindKey on player logout


Fantanic

Recommended Posts

  
[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]

Link to comment
  
-- 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) 
  

Link to comment
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.

Link to comment

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 
) 

Link to comment
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.

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