-
-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): triggerClientEvent with multi-target support
Since that once fivem PR is forever pending review.
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
---Triggers an event for the given playerIds, sending additional parameters as arguments.\ | ||
---Implements functionality from [this pending pull request](https://github.com/citizenfx/fivem/pull/1210) and may be deprecated. | ||
--- | ||
---Provides non-neglibible performance gains due to msgpacking all arguments _once_, instead of per-target. | ||
---@param eventName string | ||
---@param targetIds number | number[] | ||
---@param ... any | ||
function lib.triggerClientEvent(eventName, targetIds, ...) | ||
local payload = msgpack.pack_args(...) | ||
local payloadLen = #payload | ||
|
||
if type(targetIds) == 'table' and table.type(targetIds) == 'array' then | ||
for i = 1, #targetIds do | ||
TriggerClientEventInternal(eventName, targetIds[i] --[[@as string]], payload, payloadLen) | ||
end | ||
|
||
return | ||
end | ||
|
||
TriggerClientEventInternal(eventName, targetIds --[[@as string]], payload, payloadLen) | ||
end | ||
|
||
return lib.triggerClientEvent |
e476736
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, very nice!!!! How'd you even come up with this?!