AddEventHandler Shared function

From Gothic 2 Online: Wiki
Jump to navigation Jump to search

This function was added in version: 0.0.0.0

NOTE! Events are special function, which are called when something specific happend. For example, when player join to the server, is called event named onPlayerJoin.

NOTE! New event must be registered via addEvent function.

Function add a handler to the specified event.

Syntax

bool addEventHandler(string eventName, function callback[, int priority])

Required Arguments

  • eventName: The name of event.
  • callback: The function, which will be called when event will be triggered.

Optional Arguments

  • priority: Priority by which event will be sorted in event queue and then called in order.

Example

Server

addEventHandler("onPlayerJoin", function(pid)
{
	sendMessageToAll(0, 255, 0, getPlayerName(pid) + " joined to the server");
});

addEventHandler("onPlayerDisconnect", function(pid, reason)
{
	sendMessageToAll(255, 0, 0, getPlayerName(pid) + " disconnected from the server. Reason " + reason);
});

Client

addEventHandler("onInit",function(pid)
{
	setCursorVisible(true);
});

Related functions