murilo2929 Posted September 24, 2019 Share Posted September 24, 2019 function funcInput ( thePlayer, key, keyState ) triggerClientEvent(thePlayer, "enableRoadblockGUI", getRootElement(), true) end function bindTheKeys ( thePlayer, commandName ) bindKey ( thePlayer, "F5", "down", funcInput ) end addCommandHandler ( "bindme", bindTheKeys ) how do I bind this key without the player having to type the command "bindme"? Link to comment
Addlibs Posted September 24, 2019 Share Posted September 24, 2019 function bindKeysForPlayer(plr) bindKey(source or plr, "F5", "down", funcInput) -- bind it to the event's source (onPlayerJoin) or the first parameter if source doesn't exist (i.e. function wasn't called by an event but by script) end addEventHandler("onPlayerJoin", root, bindKeysForPlayer) function bindKeysForAllPlayers() for k, v in pairs(getElementsByType("player")) do bindKeysForPlayer(v) -- call the binding function for each player end end addEventHandler("onResourceStart", resourceRoot, bindKeysForAllPlayers, false) Unless the server code does anything else other than trigger the client event (e.g. access control), you may just as well move this whole part over to the client. That way you can just bind the key in the main scope of the file outside of any function and it'll bind as soon as the script loads. On the server, you have to use an event to bind the key when a player joins. Link to comment
murilo2929 Posted September 25, 2019 Author Share Posted September 25, 2019 5 hours ago, MrTasty said: function bindKeysForPlayer(plr) bindKey(source or plr, "F5", "down", funcInput) -- bind it to the event's source (onPlayerJoin) or the first parameter if source doesn't exist (i.e. function wasn't called by an event but by script) end addEventHandler("onPlayerJoin", root, bindKeysForPlayer) function bindKeysForAllPlayers() for k, v in pairs(getElementsByType("player")) do bindKeysForPlayer(v) -- call the binding function for each player end end addEventHandler("onResourceStart", resourceRoot, bindKeysForAllPlayers, false) Unless the server code does anything else other than trigger the client event (e.g. access control), you may just as well move this whole part over to the client. That way you can just bind the key in the main scope of the file outside of any function and it'll bind as soon as the script loads. On the server, you have to use an event to bind the key when a player joins. function funcInput ( thePlayer, key, keyState ) triggerClientEvent(thePlayer, "enableRoadblockGUI", getRootElement(), true) end addEventHandler( "funcInput", getRootElement(), funcInput ) function bindTheKeys ( thePlayer ) bindKey ( thePlayer, "F5", "down", funcInput ) end addEventHandler("onClientResourceStart", resourceRoot, bindTheKeys) addEventHandler ( "onPlayerJoin", getRootElement(), bindTheKeys) I try this on client side and no success. Link to comment
Addlibs Posted September 25, 2019 Share Posted September 25, 2019 (edited) If you want to use it on the client, you can't use functions like triggerClientEvent. As I've outlined in my post above, on the client, you can literally just add bindKey("F5", "down", func_that_handles_enableRoadblockGUI_event) outside any function and it'll bind as soon as the script loads on the client. If you prefer to use server-side, you can just use the code I gave in that other post Edited September 25, 2019 by MrTasty Link to comment
murilo2929 Posted September 25, 2019 Author Share Posted September 25, 2019 4 hours ago, MrTasty said: If you want to use it on the client, you can't use functions like triggerClientEvent. As I've outlined in my post above, on the client, you can literally just add bindKey("F5", "down", func_that_handles_enableRoadblockGUI_event) outside any function and it'll bind as soon as the script loads on the client. If you prefer to use server-side, you can just use the code I gave in that other post Got it, ty help alot Link to comment
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