emitNet-server
title: EmitNet - server
Use emitNet function when you want to trigger an event from the server to a client or to all clients.
You need to declare the event on the client with onNet first.
Signature
function emitNet(eventName: string, serverId: string | number, ...args?: any ) => void
Signature > Required argument
- eventName: The event name you want to trigger.
- serverId: The player to send to.
Note: set serverId to-1will send the event to all clients.
Signature > Optional arguments
- ...args: The arguments you want to pass.
Examples
// No arg
emitNet("foo:pokedYou", 2);
// With args
emitNet("foo:pokedYouAndGiveMessages", 2, ["Javascript is cool!", "But FiveM is better!"]);
// To all clients
emitNet("foo:pokedYouAll", -1);