Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es_extended/server/functions): add ESX.TriggerClientEvent #1342

Merged

Conversation

Kenshiin13
Copy link
Contributor

@Kenshiin13 Kenshiin13 commented Apr 4, 2024

Description

This pull request introduces a new function ESX.TriggerClientEvent to the ESX framework. In the FiveM environment, the native TriggerClientEvent is limited to triggering events for a single player ID at a time. This limitation incurs significant overhead when sending events to multiple clients, as the data must be re-serialized for each client. The new function addresses this issue by serializing the data once using msgpack and efficiently triggering events for multiple clients using the internal native TriggerClientEventInternal.

Changes Made

  • Added ESX.TriggerClientEvent function to the ESX framework.
  • Utilized msgpack for serializing additional arguments once, reducing overhead.
  • Implemented logic to trigger events for multiple clients using the internal native TriggerClientEventInternal.

Motivation

In my experience, many scripts resort to inefficient practices when sending data to multiple clients. Some scripts send data to all clients to avoid the overhead of serialization, disregarding the principle that clients should only receive data relevant to them. Others use the TriggerClientEvent native for multiple clients, leading to significant performance implications such as server thread hitches. These practices are not only inefficient but can also degrade server performance and overall player experience.

Introducing ESX.TriggerClientEvent aims to address these challenges by providing developers with a unified solution within the ESX framework. By serializing data once and efficiently triggering events for multiple clients using the internal native, this function ensures that clients receive only the data relevant to them while minimizing performance overhead. This not only promotes best practices in script development but also enhances the overall performance and stability of FiveM servers utilizing the ESX framework.

Testing

As I am currently on vacation and unable to conduct testing, the implementation of the ESX.TriggerClientEvent function has not undergone direct testing. However, testing by a maintainer would be greatly appreciated to ensure the reliability and effectiveness of the new function. Alternatively, I will be back in a couple of days and can perform the testing myself.

Has been tested locally on a single, and multiple clients. Work as expected.

@Kenshiin13 Kenshiin13 changed the title add(ESX.TriggerClientEvent) feat(server/functions): add ESX.TriggerClientEvent Apr 8, 2024
@Kenshiin13 Kenshiin13 changed the title feat(server/functions): add ESX.TriggerClientEvent feat(es_extended/server/functions): add ESX.TriggerClientEvent Apr 8, 2024
@Arctos2win Arctos2win merged commit 8cb9f48 into esx-framework:dev Apr 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants