addNetworkHandler: Difference between revisions

From GTA Connected
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 1: Line 1:
{{ScriptItem
{{ScriptItem2
|name = addNetworkHandler
|side = shared
|type = function
|games = iii vc sa iv
|desc = add a handler for a custom network event that can be triggered via a server or client script.
|arg1 = string networkEventName The name of the network event, case-insensitive.
|arg2 = function handler The scripting function to call when the network event occurs.
|return = void
|freturn = void
|note = Use [[triggerNetworkEvent|triggerNetworkEvent]] call a custom network event. Clients can only trigger server-side handlers, while the server can trigger a handler on either end.
|offline = false
|offline = false
|endpoint = shared
|cb2arg1SS = Client client The client that triggered the network event.
|type = function
|cb2arg2SS = ... vararg The arguments that were triggered with the network event.
|name = addNetworkHandler
|cb2arg1CS = ... vararg The arguments that were triggered with the network event.
|parameters = string networkEventName, function handler
|parameter1 = string networkEventName The name of the network event, case-insensitive.
|parameter2 = function handler The scripting function to call when the network event occurs.
|callback2SyntaxSS = Client client, ...
|callback2ParameterSS1 = Client client The client that triggered the network event.
|callback2ParameterSS2 = ... vararg The arguments that were triggered with the network event.
|callback2SyntaxCS = ...
|callback2ParameterCS1 = ... vararg The arguments that were triggered with the network event.
|return1 = void
|returnFail1 = void
|usage = add a handler for a custom network event that can be triggered via a server or client script.
|notes = Use [[triggerNetworkEvent|triggerNetworkEvent]] call a custom network event. Clients can only trigger server-side handlers, while the server can trigger a handler on either end.
|exampleJSCS = addNetworkHandler("walkToPos", function(civilian, x, y) {
|exampleJSCS = addNetworkHandler("walkToPos", function(civilian, x, y) {
     let walkToPos = new Vec2(x, y);
     let walkToPos = new Vec2(x, y);

Latest revision as of 20:36, 19 November 2022

Function Server and Client icon-iii.png icon-vc.png icon-sa.png icon-iv.png Online Only

Available since Server 1.0.0, Client 1.0.0

void addNetworkHandler(string networkEventName, function handler)

The addNetworkHandler function is used to add a handler for a custom network event that can be triggered via a server or client script.

Parameters

1) string networkEventName The name of the network event, case-insensitive.
2) function handler The scripting function to call when the network event occurs.

Return

void This function doesn't return a value.

Notes

  • Use triggerNetworkEvent call a custom network event. Clients can only trigger server-side handlers, while the server can trigger a handler on either end.

Examples

Example 1 - JavaScript - Client-Side:

addNetworkHandler("walkToPos", function(civilian, x, y) {
let walkToPos = new Vec2(x, y);
civilian.walkTo(walkToPos);
});

Compatibility

There isn't any compatibility information for this function.

Related

Server Related

icon-iii.png icon-vc.png icon-sa.png icon-iv.png addNetworkHandler
icon-iii.png icon-vc.png icon-sa.png icon-iv.png removeNetworkHandler


Client Related

icon-iii.png icon-vc.png icon-sa.png icon-iv.png addNetworkHandler
icon-iii.png icon-vc.png icon-sa.png icon-iv.png connect
icon-iii.png icon-vc.png icon-sa.png icon-iv.png disconnect
icon-iv.png gta.shutdownAndLaunchNetworkGame
icon-iii.png icon-vc.png icon-sa.png icon-iv.png isConnected
icon-iii.png icon-vc.png icon-sa.png icon-iv.png isConnecting
icon-iii.png icon-vc.png icon-sa.png icon-iv.png removeNetworkHandler