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(event/targers): multiple IDs method #464

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ Syntax
------

```lua
TriggerClientEvent(string eventName, int playerId[, ...])
TriggerClientEvent(string eventName, int or array playerIds[, ...])
```

### Required arguments
- **eventName**: A string representing the event name to call on the client.
- **playerId**: The ID of the player to call the event for. Specify -1 for all clients.
- **playerIds**: The ID of the player to call the event for. Specify -1 for all clients or an array for specific IDs.

### Optional arguments
- **...**: Any additional data that should be passed along.

Examples
--------

### Specific Player ID
-- CLIENT

Don't forget to [RegisterNetEvent][]!
Expand All @@ -31,6 +32,20 @@ end)
```
-- SERVER
```lua
local playerId = 1
TriggerClientEvent('eventName', playerId, 'Hello world!')
```
[RegisterNetEvent]: /docs/scripting-reference/runtimes/lua/functions/RegisterNetEvent/

### Multiple Players ID

To call an event for multiple players, you need to include their IDs in an array. Here’s an example in Lua:

```lua
-- Define the player IDs to target
local playerIds = {1, 3, 5} -- Replace with actual player IDs

-- Trigger the event for the specified players
TriggerClientEvent('eventName', -1, playerIds, { example = 0 })
PsychoShock marked this conversation as resolved.
Show resolved Hide resolved
```
This format ensures that the event is called for each player specified in the `playerIds` array.