CloudLEL Posted November 26, 2017 Share Posted November 26, 2017 Hi, I was just curious about something in my script. I'm triggering a server event using the following: triggerServerEvent("server-create-account", getRootElement(), u, p) I'm confused who this event is actually sent to? Wouldn't getRootElement() be sending it to everyone? I thought I would use localPlayer but from reading the wiki, it says that it is un-secure and bad practice. I just want to trigger the event from the client that actually triggered it. So when I do my event handler, the code inside the callback would be sent to the client that triggered it in the beginning. I hope that makes sense and someone could explain this to me, thanks. Link to comment
Miika Posted November 26, 2017 Share Posted November 26, 2017 I've always used getRootElement() when triggering serverside event without problems. Make sure you use 'client' instead of source in serverside function. Link to comment
Addlibs Posted November 26, 2017 Share Posted November 26, 2017 Triggering of server events is, by definition, sent to the server - always. 'Send to' is only a parameter of triggering client events, to choose on whose client to trigger the event on. What you're discussing is the event source element, and the wiki doesn't say it's bad practise to send localPlayer. In fact, using localPlayer as the source will use less CPU than sending on root, since after an event is triggered, it is also triggered on all elements under it. Since everything is under root, it means that the event will be triggered on every single element, increasing the CPU usage. The wiki only states not to use the source of the event to verify which client actually triggered the event, and instead use the predefined variable client, as the event source can be spoofed by fake packets sent from dishonest clients. You should be aware that there's a difference between an event's source and the trigger. A source is simply a reference to the element that is central to the event. For example, let's use the event onVehicleEnter, (the following is just a generic description of a hypothetical event I named onVehicleEnter for the sake of example, and not actual inner workings on the triggering of onVehicleEnter) although the source is the vehicle that was entered, the event would actually be triggered by the client that entered the vehicle. Link to comment
CloudLEL Posted November 26, 2017 Author Share Posted November 26, 2017 Okay, thanks for the explanation, highly appreciated! 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