Server:Packet.writeFloat Server function

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

This function was added in version: 0.0.3.0

Insert float number to packet. (4 bytes)

Syntax

void Packet.writeFloat(float value)

Required Arguments

  • value: number in range 3.4e-38...3.4e+38 and maxium 5 decimal digits accuary after the decimal point.

Example

Server

const PI_PACKET_ID = 999;
const C_PI = 3.14159; // creating PI constant

addEventHandler("onPlayerCommand",function(pid, cmd, params)
{
	if (cmd == "pi")
	{
		packet <- Packet();

		packet.writeUInt16(PI_PACKET_ID);
		packet.writeFloat(C_PI); // writing PI value to packet

		packet.send(pid, RELIABLE_ORDERED);
	}
});

Client

const PI_PACKET_ID = 999;

addEventHandler("onPacket",function(packet)
{
	if (packet.readUInt16() == PI_PACKET_ID)
	{
		Chat.print(255, 255, 255, "PI is equal " + packet.readFloat())
	}
})

Related functions