Optional message type (defaults to NET_MESSAGE_GAME_MESSAGE)
-- Send with default message typepacket.send_text("action|respawn", true)-- Send with specific message typepacket.send_text("action|respawn", true, packet.NET_MESSAGE_GENERIC_TEXT)
command.register("warp", "Warp to a world", function(ctx) if #ctx.args < 1 then ctx:reply("Usage: /warp <world_name>") return false end local world_name = ctx.args[1] local join = JoinRequestPacket.new() join.world_name = world_name:upper() send.to_server(join) ctx:reply("`2Warping to ``{}", world_name) return trueend)
function send_custom_log(message, to_server) local log = LogPacket.new() log.msg = message if to_server then send.to_server(log) else send.to_client(log) endendcommand.register("notify", "Send a notification", function(ctx) if #ctx.args < 1 then ctx:reply("Usage: /notify <message>") return false end local message = "`2[Notification] ``" .. table.concat(ctx.args, " ") send_custom_log(message, false) return trueend)
event.on("server:SendToServer", function(ctx) if ctx:has_packet() then local pkt = ctx:parse() -- Modify packet fields directly if pkt.net_id then pkt.net_id = 999 end -- IMPORTANT: Cancel original before sending modified ctx:cancel() send.to_server(pkt) endend)
Always cancel before resendingWhen you modify and resend a packet, you must cancel the original first to avoid sending it twice: