network.add_send_hook
Intercepts outgoing packets.
Syntax
Signature
network.add_send_hook(Callback: function) -> numberAliases
raknet.add_send_hookpackets.add_send_hookRakNet.add_send_hooknetwork.addsendhookraknet.addsendhookpackets.addsendhookRakNet.addsendhook
Parameters
| Parameter | Type | Description |
|---|---|---|
Callback | function | Called as Callback(Packet) for each intercepted outgoing packet. |
Returns
| Type | Description |
|---|---|
number | Hook ID accepted by network.remove_send_hook. |
Notes
The callback receives an editable Packet. Return false or call Packet:Block() to discard it. Return a replacement payload to replace it. Returning nil or true keeps the packet, including changes made with SetData or SetDecoded. Callbacks must not yield. A callback error, yield, invalid replacement, or exceeded pump budget discards the packet. At most 32 hooks total can be registered.
Example
Luau
-- Observe outgoing chat packets without changing them.
local Hook = network.add_send_hook(function(Packet)
if Packet.type ~= "Chat" then
return
end
local Fields = Packet.decoded
if Fields then
print("Outgoing chat:", Fields.text)
else
warn(Packet.decodeError)
end
-- Returning nothing leaves the packet unchanged.
end)
task.delay(15, function()
network.remove_send_hook(Hook)
end)