Fantanic Posted March 18, 2014 Posted March 18, 2014 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
Fantanic Posted March 18, 2014 Author Posted March 18, 2014 function bind() bindKey("M", "down", showPanel) end addEventHandler("onPlayerLogin",bind) function unbind() unBindKey("M", "down", showPanel) end addEventHandler("onPlayerQuit",unbind) ?
Itachi Posted March 18, 2014 Posted March 18, 2014 [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]
DNL291 Posted March 18, 2014 Posted March 18, 2014 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.
Fantanic Posted March 18, 2014 Author Posted March 18, 2014 What do u mean exactly with the triggerClientEvent , like this ; function unbind1() triggerClientEvent end addEventHandler("onPlayerLogout",unbind1)
cheez3d Posted March 18, 2014 Posted March 18, 2014 -- 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)
DNL291 Posted March 18, 2014 Posted March 18, 2014 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.
Fantanic Posted March 18, 2014 Author Posted March 18, 2014 bad argument expected element at argument 2 got function (server side)
JR10 Posted March 18, 2014 Posted March 18, 2014 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 )
DNL291 Posted March 18, 2014 Posted March 18, 2014 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now