Server:Packet.readInt16 Server function

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

This function was added in version: 0.0.3.0

Get number from packet. (2 byte)

Syntax

int Packet.readInt16()

Returns

  • number in range -32767...32767;

Example

Server

const STRENGTH_DEBUFF_PACKET = 1003,
local globalStrengthDebuf = -20;

function sendStrenghtDebuf(id)
{
	local packet = Packet();
	packet.writeUInt16(STRENGTH_DEBUFF_PACKET);
	packet.writeInt16(globalStrengthDebuf);
	packet.send(id);
}

Client

const STRENGTH_DEBUFF_PACKET = 1003,

local function onPacket(packet)
{
	switch(packet.readUInt16())
	{
		case STRENGTH_DEBUFF_PACKET:
		{
			chat.newMessage(format("Your strength is decreased by %d", packet.readInt16));
		}
		break;
	}
}

addEventHandler("onPacket", onPacket);

Related functions