Server:Packet.sendToAll Server function

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

This function was added in version: 0.0.3.0

Send packet to all connected players.

Syntax

void Packet.sendToAll(int reliability)

Required Arguments

Example

Server

const TEST_MSG_PACKET_ID = 999;

addEventHandler("onPlayerCommand", function(pid, cmd, params)
{
	if (cmd == "msg")
	{
		packet <- Packet();
	
		packet.writeUInt16(TEST_MSG_PACKET_ID);
		packet.writeString(params);

		packet.sendToAll(RELIABLE_ORDERED);
	}
});

Client

const TEST_MSG_PACKET_ID = 999;

addEventHandler("onPacket", function(packet)
{
	local id = packet.readUInt16();

	if (id == TEST_MSG_PACKET_ID)
	{
		Chat.print(255, 255, 0, "This message will be displayed to every player. MSG: " + packet.readString());
	}
});

Related functions