harryh Posted March 21, 2017 Share Posted March 21, 2017 (edited) Hi, so I have never really used event handlers properly so if I trigger a client event using the element getLocalPlayer() what must I put in the server add event handler to return the same element. I put getRootElement() but I think thats wrong. Code below is just an example of how I use addEventHandler Client: function check() triggerServerEvent("stuff", getLocalPlayer()) end addEventHandler("check", getLocalPlayer(), theFunction) server: addEventHandler("stuff", getRootElement(), stuffFunction) <------------ I would use this if calling in serverside because I dont know how to get the player. Normally I use source inside the function because that returns what executed the command or event Thanks Edited March 21, 2017 by harryh Link to comment
Gordon_G Posted March 21, 2017 Share Posted March 21, 2017 (edited) Ok, I'll explain you a little trick I use : When you trigger a server event by client use like this : -- Server : function helloWorld(source,message) outputChatBox(getPlayerName(source),source) end addEventHandler("helloWorld", root, helloWorld) -- Client : function helloWorld() message = "I like potatoes" triggerServerEvent("helloWorld", localPlayer, getLocalPlayer(), message) -- localPlayer and getLocalPlayer() will return the same USERDATA (the local player) but, like this, you can have source into server side end addCommandHandler("hello",helloWorld) I hope you understand Edited March 21, 2017 by Gordon_G 2 Link to comment
harryh Posted March 21, 2017 Author Share Posted March 21, 2017 Yes I see. Thank you. @Gordon_G 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