Skip to content

Network API (Packet)

Creating and Sending Packets

The Packet class allows building custom network packets to send to clients.

local pkt = Packet()
pkt:WriteByte(1)        -- Write a single byte
pkt:WriteWord(1000)     -- Write a 2-byte value
pkt:WriteDword(50000)   -- Write a 4-byte value
pkt:WriteString("Hello") -- Write a string

SendPacket(aIndex, 0x1234, pkt) -- Send with headcode 0x1234

Packet Methods

Method Description
WriteByte(value) Write 1 byte
WriteWord(value) Write 2 bytes
WriteDword(value) Write 4 bytes
WriteString(text) Write a string
ReadByte() Read 1 byte
ReadWord() Read 2 bytes
ReadDword() Read 4 bytes
ReadString(length) Read a string of given length

SendPacket(aIndex, headcode, packet)

Sends a custom packet to the client. The packet is wrapped in a C2 FE header automatically.

-- Send a custom UI update
local pkt = Packet()
pkt:WriteByte(0x01)  -- sub-opcode
pkt:WriteWord(500)   -- some value
SendPacket(player.Index, 0x0100, pkt)