raknet. add_send_hook Synchronous
RakNet.add_send_hookRakNet.addsendhookraknet.addsendhook
Register a persistent callback for outgoing packets. Use it for brief inspection or for a specific, intentional packet edit before the packet is sent.
raknet.add_send_hook(callback: (RakNetPacket) -> ()) -> FunctionParameters
| Parameter | Type | Description |
|---|---|---|
callback | (RakNetPacket) -> () | Function receiving a temporary RakNetPacket view for each outgoing packet. |
Argument fields
RakNetPacket = {
Data: buffer, AsArray: {number}, AsBuffer: buffer, AsString: string,
Size: number, PacketId: number, ID: number, Id: number, PacketID: number, Priority: number,
Reliability: number, OrderingChannel: number,
SystemIdentifier: string, Broadcast: boolean, ForceReceiptNumber: number
}Returns
FunctionThe same callback function, which you pass to raknet.remove_send_hook to unregister it.
Usage notes
The RakNet library must be enabled in Environment settings and connected to an active game generation.
Callbacks must not yield. If a callback raises, Kawaii reports a warning and continues dispatching.
The RakNetPacket view is valid only during its callback. Save fields or copy Data inside the callback if you need them later.
Registering the same callback again does not create a second hook registration.
Availability
RakNet is disabled by default. RakNet and raknet are removed when the setting is off; retained references can still call is_enabled().
Example
if raknet.is_enabled() then
local function onSend(packet)
print("Sending packet ID", packet.ID, "with", packet.Size, "bytes")
end
raknet.add_send_hook(onSend)
task.delay(5, function() raknet.remove_send_hook(onSend) end)
end