Server:Packet.writeUInt16 Server function

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

This function was added in version: 0.0.3.0

Insert number to packet. [2 bytes]

Syntax

void Packet.writeUInt16(int value)

Required Arguments

  • value: number in range 0-65535;

Example

Server

const PLAYERS_AMOUNT_PACKET = 1002,

function sendPlayersAmount(id)
{
	local packet = Packet();
	packet.writeUInt16(PLAYERS_AMOUNT_PACKET);
	packet.writeUInt16(getPlayersCount());
	packet.send(id);
}

Client

const PLAYERS_AMOUNT_PACKET = 1002,

local function onPacket(packet)
{
	switch(packet.readUInt16())
	{
		case PLAYERS_AMOUNT_PACKET:
		{
			chat.newMessage(format("Players in game: %d", packet.readUInt16));
		}
		break;
	}
}

addEventHandler("onPacket", onPacket);

Related functions