Jump to content

Understanding `Sent-To`


CloudLEL

Recommended Posts

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

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

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