Server:Packet.writeBool Server function

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

This function was added in version: 0.0.3.0

Insert bool value to packet.

Syntax

void Packet.writeBool(bool value)

Required Arguments

  • value: 'true' or 'false'

Example

Server

const IS_PLAYER_CONNECTED_PACKET = 1001;

function sendIsPlayerConnected(id, askForID)
{
	local packet = Packet();
	packet.writeUInt16(IS_PLAYER_CONNECTED_PACKET);
	packet.writeUInt8(askForID);
	packet.writeBool(isPlayerConnected(askForID));
	packet.send(id);
}

Client

const IS_PLAYER_CONNECTED_PACKET = 1001;

local function onPacket(packet)
{
	switch(packet.readUInt16())
	{
		case IS_PLAYER_CONNECTED_PACKET:
		{
			local askedID = packet.readUInt8();
			if(packet.readBool())
				chat.newMessage(format("Player %d is in game", askedID));
			else
				chat.newMessage(format("Player %d is not in game", askedID));
		}
		break;
	}
}

addEventHandler("onPacket", onPacket);

Related functions