### UI Customization Packet Example Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Demonstrates sending UI configuration data including colors, dimensions, and transparency. Uses Color3, UDim2, and NumberU8 types for efficient transmission. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- UI-related types: -- Color3: RGB color (3 bytes) -- BrickColor: Roblox BrickColor (2 bytes) -- UDim: Scale + Offset (4 bytes) -- UDim2: X and Y UDim (8 bytes) -- Rect: Min/Max rectangle (16 bytes) -- NumberRange: Min/Max range (8 bytes) -- Example: UI customization packet local UIUpdatePacket = Packet("UIUpdate", Packet.Color3, -- background color Packet.Color3, -- text color Packet.UDim2, -- position Packet.UDim2, -- size Packet.NumberU8 -- transparency (0-255) ) -- Server sends UI configuration UIUpdatePacket:FireClient(player, Color3.fromRGB(30, 30, 40), -- dark background Color3.fromRGB(255, 255, 255), -- white text UDim2.new(0.5, -100, 0.5, -50), -- centered position UDim2.new(0, 200, 0, 100), -- fixed size 25 -- slight transparency ) -- Client applies UI changes UIUpdatePacket.OnClientEvent:Connect(function(bgColor, textColor, pos, size, transparency) frame.BackgroundColor3 = bgColor label.TextColor3 = textColor frame.Position = pos frame.Size = size frame.BackgroundTransparency = transparency / 255 end) ``` -------------------------------- ### Binary Data Transfer Example Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Demonstrates sending binary data using a packet that includes a buffer for the payload and a string for its description. The Buffer type supports up to 255 bytes with a 1-byte length prefix. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- String types: -- String: up to 255 characters (1 byte length prefix) -- StringLong: up to 65535 characters (2 byte length prefix) -- Characters: compressed alphanumeric string (6-bit encoding) -- Buffer types: -- Buffer: up to 255 bytes (1 byte length prefix) -- BufferLong: up to 65535 bytes (2 byte length prefix) -- Example: Binary data transfer local DataPacket = Packet("BinaryData", Packet.Buffer, -- small binary payload Packet.String -- description ) local data = buffer.create(16) buffer.writeu32(data, 0, 12345) buffer.writef32(data, 4, 3.14159) DataPacket:Fire(data, "game state snapshot") ``` -------------------------------- ### Define Inventory Packet with Nested Array Structure Source: https://context7.com/mrchigurh/suphi-packet/llms.txt This example demonstrates defining an Inventory packet with a nested array structure for items. Each item in the array has an Id, Quantity, and Equipped status. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- Example: Inventory with nested structure local InventoryPacket = Packet("Inventory", { Gold = Packet.NumberU32, Items = { -- Array of items { Id = Packet.NumberU16, Quantity = Packet.NumberU8, Equipped = Packet.Boolean8 } } }) InventoryPacket:FireClient(player, { Gold = 5000, Items = { {Id = 101, Quantity = 1, Equipped = true}, {Id = 205, Quantity = 5, Equipped = false}, } }) ``` -------------------------------- ### Define Status Packet with Static Strings Source: https://context7.com/mrchigurh/suphi-packet/llms.txt This example defines a Status packet that uses a predefined static string for the message and a NumberU8 for the error code. Ensure static values are configured in the corresponding Static module. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- Example: Status notification with static strings local StatusPacket = Packet("Status", Packet.Static1, -- predefined status message Packet.NumberU8 -- error code ) -- On server (Static1[1] = "DataStore Failed To Load") StatusPacket:FireClient(player, "DataStore Failed To Load", 1) ``` -------------------------------- ### Define Leaderboard Packet with Array of Player Scores Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Use table syntax to define packets with arrays and nested structures. {Type} creates an array, and {key = Type, ...} creates a structured object. This example defines a leaderboard with an array of player entries, each containing Name, Score, and Rank. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- Array syntax: {Type} creates an array of that type -- Table syntax: {key = Type, ...} creates a structured object -- Example: Leaderboard packet with array of player scores local LeaderboardPacket = Packet("Leaderboard", { { -- Array of player entries Name = Packet.Characters, Score = Packet.NumberU32, Rank = Packet.NumberU8 } }) -- Server sends leaderboard data local leaderboard = { {Name = "Player1", Score = 15000, Rank = 1}, {Name = "Player2", Score = 12500, Rank = 2}, {Name = "Player3", Score = 10000, Rank = 3}, } LeaderboardPacket:FireClient(player, leaderboard) ``` -------------------------------- ### Using Numeric Types with Different Precision Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Packet supports various numeric types with different byte sizes for bandwidth optimization. Example shows a compact player state packet using minimal bytes. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- Available numeric types and their ranges: -- NumberS8: -128 to 127 (1 byte, signed) -- NumberS16: -32768 to 32767 (2 bytes, signed) -- NumberS24: -8388608 to 8388607 (3 bytes, signed) -- NumberS32: -2147483648 to 2147483647 (4 bytes, signed) -- NumberU8: 0 to 255 (1 byte, unsigned) -- NumberU16: 0 to 65535 (2 bytes, unsigned) -- NumberU24: 0 to 16777215 (3 bytes, unsigned) -- NumberU32: 0 to 4294967295 (4 bytes, unsigned) -- NumberF16: ±2048 precision (2 bytes, float) -- NumberF24: ±262144 precision (3 bytes, float) -- NumberF32: ±16777216 (4 bytes, float) -- NumberF64: full double precision (8 bytes, float) -- Example: Compact player state packet using minimal bytes local PlayerStatePacket = Packet("PlayerState", Packet.NumberU8, -- health (0-255) Packet.NumberU8, -- stamina (0-255) Packet.NumberS16, -- x velocity Packet.NumberS16, -- y velocity Packet.NumberS16 -- z velocity ) -- Only uses 7 bytes per transmission! PlayerStatePacket:Fire(100, 80, 150, -32, 45) ``` -------------------------------- ### Serialize and Deserialize Data Manually Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Manually serialize packet data to buffers for storage or custom transmission using the Serialize and Deserialize methods. This example defines a SaveDataPacket and demonstrates serializing player data to a buffer and then deserializing it back. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- Define a packet for serialization local SaveDataPacket = Packet("SaveData", Packet.String, -- player name Packet.NumberU32, -- score Packet.Vector3F32 -- last position ) -- Serialize data to buffer (without sending) local serializedBuffer, instances = SaveDataPacket:Serialize( "PlayerName", 50000, Vector3.new(100, 25, -50) ) -- Store buffer in DataStore or use elsewhere print("Serialized size:", buffer.len(serializedBuffer), "bytes") -- Later: Deserialize buffer back to values local name, score, position = SaveDataPacket:Deserialize(serializedBuffer, instances) print(name, score, position) -- "PlayerName", 50000, Vector3.new(100, 25, -50) ``` -------------------------------- ### Chat Message with Compressed Username Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Example of sending a chat message using a packet that includes a compressed alphanumeric username (Characters type), a long string for the message, and a small unsigned integer for the channel ID. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- String types: -- String: up to 255 characters (1 byte length prefix) -- StringLong: up to 65535 characters (2 byte length prefix) -- Characters: compressed alphanumeric string (6-bit encoding) -- Buffer types: -- Buffer: up to 255 bytes (1 byte length prefix) -- BufferLong: up to 65535 bytes (2 byte length prefix) -- Example: Chat message with compressed username local ChatPacket = Packet("Chat", Packet.Characters, -- username (alphanumeric only, ~25% smaller) Packet.StringLong, -- message (supports long messages) Packet.NumberU8 -- channel ID ) ChatPacket:Fire("PlayerName123", "Hello everyone! This is a longer message.", 1) ``` -------------------------------- ### Define Input Packet with EnumItem and Static Types Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Use EnumItem for Roblox enum values and Static types for predefined values from Static modules. This example defines an Input packet that transmits a KeyCode enum, a boolean pressed state, and a float hold duration. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- EnumItem: Any Roblox enum value (3 bytes) -- Static1/Static2/Static3: Predefined values from Static modules (1 byte) -- Configure enums in Packet/Types/Enums.lua: -- return { Enum.KeyCode, Enum.Material, Enum.EasingStyle, ... } -- Configure static values in Packet/Types/Static1.lua: -- return { "Error Message 1", "Success", math.pi, Vector3.new(1,2,3), ... } -- Example: Input action packet with enum local InputPacket = Packet("InputAction", Packet.EnumItem, -- KeyCode enum Packet.Boolean8, -- pressed state Packet.NumberF32 -- hold duration ) InputPacket:Fire(Enum.KeyCode.Space, true, 0.5) ``` -------------------------------- ### Character Position Synchronization with Compact CFrame Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Example of synchronizing character position and velocity using a compact CFrame type (F24 position, U8 rotation angles) and a signed 16-bit vector for velocity. This is useful for efficient character movement updates. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- Vector types with different precision: -- Vector2S16: 4 bytes (signed 16-bit components) -- Vector2F24: 6 bytes (24-bit float components) -- Vector2F32: 8 bytes (32-bit float components) -- Vector3S16: 6 bytes (signed 16-bit components) -- Vector3F24: 9 bytes (24-bit float components) -- Vector3F32: 12 bytes (32-bit float components) -- CFrame types (position + rotation): -- CFrameF24U8: 12 bytes (F24 position, U8 rotation angles) -- CFrameF32U8: 15 bytes (F32 position, U8 rotation angles) -- CFrameF32U16: 18 bytes (F32 position, U16 rotation angles) -- Example: Character position sync with compact CFrame local PositionSyncPacket = Packet("PositionSync", Packet.CFrameF24U8, -- character CFrame (12 bytes) Packet.Vector3S16 -- velocity (6 bytes) ) -- Server broadcasts position updates local function broadcastPosition(player, cframe, velocity) PositionSyncPacket:FireClient(player, cframe, velocity) end -- Client receives updates PositionSyncPacket.OnClientEvent:Connect(function(cframe, velocity) character:PivotTo(cframe) rootPart.AssemblyLinearVelocity = velocity end) ``` -------------------------------- ### Request-Response Pattern with Response and Timeouts Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Create packets that expect a response from the receiver using the Response method. Includes automatic timeout handling. Set ResponseTimeout and ResponseTimeoutValue to customize timeout behavior. Use OnServerInvoke on the server to handle requests and :Fire() on the client to make requests. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- Define a request packet with response types local InventoryRequest = Packet("GetInventory", Packet.String) -- category parameter :Response({ Items = {Packet.String}, Count = Packet.NumberU16 }) -- Set custom timeout (default is 10 seconds) InventoryRequest.ResponseTimeout = 5 InventoryRequest.ResponseTimeoutValue = nil -- value returned on timeout -- Server-side: Handle the request and return response InventoryRequest.OnServerInvoke = function(player, category) local items = getPlayerItems(player, category) return { Items = items, Count = #items } end -- Client-side: Make request and wait for response local response = InventoryRequest:Fire("weapons") if response then print("Got " .. response.Count .. " items") for _, item in response.Items do print(" - " .. item) end end ``` -------------------------------- ### Connect, Once, and Wait for Event Handling Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Utilize the built-in Signal class for custom event handling with Connect, Once, and Wait patterns. Connect establishes a persistent listener, Once creates a single-use listener that auto-disconnects, and Wait yields until the event fires. ```lua local Packet = require(game.ReplicatedStorage.Packet) local MyPacket = Packet("MyEvent", Packet.String) -- Connect: Persistent listener local connection = MyPacket.OnClientEvent:Connect(function(message) print("Received:", message) end) -- Disconnect when no longer needed connection:Disconnect() -- Once: Auto-disconnecting single-use listener MyPacket.OnClientEvent:Once(function(message) print("First message only:", message) end) -- Wait: Yield until event fires (returns event arguments) task.spawn(function() local message = MyPacket.OnClientEvent:Wait() print("Waited for:", message) end) -- Fire triggers all connected listeners -- (internally used by Packet, shown for Signal understanding) ``` -------------------------------- ### Define and Use a Basic Chat Packet Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Define a packet with typed parameters for client-server communication. Packets automatically serialize data using the specified type definitions. Use OnServerEvent to listen for messages on the server and Fire to send messages from the client. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- Define a packet with typed parameters -- Parameters: Name, Type1, Type2, ... local ChatPacket = Packet("ChatMessage", Packet.String, Packet.NumberU8) -- Server-side: Listen for client messages ChatPacket.OnServerEvent:Connect(function(player, message, priority) print(player.Name .. " says: " .. message .. " (priority: " .. priority .. ")") end) -- Client-side: Send a message to server ChatPacket:Fire("Hello World!", 1) ``` -------------------------------- ### Send Dynamic Data with Any Type Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Use the Any type for packet data that varies at runtime. It automatically detects and serializes various data types including nil, numbers, strings, buffers, booleans, Instances, and several Roblox Vector/Color/Sequence types, as well as tables. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- Any type automatically detects and serializes: -- nil, number, string, buffer, boolean, Instance -- Vector2, Vector3, CFrame, Color3, BrickColor -- UDim, UDim2, Rect, Region3, NumberRange -- NumberSequence, ColorSequence, EnumItem, table local DynamicPacket = Packet("DynamicData", Packet.String, -- event type Packet.Any -- payload (any type) ) -- Send different data types through same packet DynamicPacket:Fire("position", Vector3.new(10, 20, 30)) DynamicPacket:Fire("score", 12500) DynamicPacket:Fire("config", { Enabled = true, Value = 3.14, Name = "test" }) DynamicPacket:Fire("color", Color3.fromRGB(255, 128, 0)) ``` -------------------------------- ### Pass Roblox Instance references via packets Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Use the Instance type to transmit direct references to objects rather than serializing their data. Ensure the target exists in the workspace before processing on the server. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- Instance type passes references (not serialized data) local TargetPacket = Packet("SetTarget", Packet.Instance, -- target part/model Packet.Vector3F32, -- offset position Packet.NumberF32 -- duration ) -- Client requests targeting an object local targetPart = workspace:FindFirstChild("TargetPart") TargetPacket:Fire(targetPart, Vector3.new(0, 5, 0), 2.5) -- Server handles target request TargetPacket.OnServerEvent:Connect(function(player, target, offset, duration) if target and target:IsDescendantOf(workspace) then setPlayerTarget(player, target, offset, duration) end end) ``` -------------------------------- ### Server-to-Client Communication with FireClient Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Send packets from the server to specific clients using FireClient. The packet automatically handles serialization and batching. Use OnClientEvent to listen for messages on the client. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- Define a packet for damage notifications local DamagePacket = Packet("DamageNotification", Packet.NumberU16, -- damage amount Packet.Vector3F32, -- hit position Packet.String -- damage type ) -- Client-side: Listen for damage notifications DamagePacket.OnClientEvent:Connect(function(damage, position, damageType) print("Took " .. damage .. " " .. damageType .. " damage at " .. tostring(position)) -- Show damage indicator at position end) -- Server-side: Send damage notification to a specific player local function notifyDamage(player, damage, hitPosition, damageType) DamagePacket:FireClient(player, damage, hitPosition, damageType) end notifyDamage(player, 25, Vector3.new(10, 5, 20), "Fire") ``` -------------------------------- ### Transmit Sequence types for effects Source: https://context7.com/mrchigurh/suphi-packet/llms.txt Use NumberSequence, ColorSequence, and NumberRange types to synchronize particle or UI configurations. These types handle variable-length keypoint data efficiently. ```lua local Packet = require(game.ReplicatedStorage.Packet) -- NumberSequence: Variable-length keypoint sequence -- ColorSequence: Variable-length color keypoint sequence local ParticleConfigPacket = Packet("ParticleConfig", Packet.NumberSequence, -- size over lifetime Packet.ColorSequence, -- color over lifetime Packet.NumberRange -- speed range ) -- Server sends particle configuration local sizeSequence = NumberSequence.new({ NumberSequenceKeypoint.new(0, 0.5), NumberSequenceKeypoint.new(0.5, 1), NumberSequenceKeypoint.new(1, 0) }) local colorSequence = ColorSequence.new({ ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 255, 0)), ColorSequenceKeypoint.new(0.5, Color3.fromRGB(255, 128, 0)), ColorSequenceKeypoint.new(1, Color3.fromRGB(255, 0, 0)) }) ParticleConfigPacket:FireClient(player, sizeSequence, colorSequence, NumberRange.new(5, 10) ) -- Client applies to particle emitter ParticleConfigPacket.OnClientEvent:Connect(function(size, color, speed) particleEmitter.Size = size particleEmitter.Color = color particleEmitter.Speed = speed end) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.