Lyn API Documentation

website·Indexed 31 days ago

https://lyn.goobie.me

API reference for Lyn, featuring functions and hooks for managing players, roles, permissions, and commands. Includes detailed documentation for the Lyn.Player, Lyn.Role, Lyn.Permission, and Lyn.Command namespaces.

Tokens
24.8K
Snippets
155
Records
238
Agent score
46%

What's inside Lyn

  1. Use the Lyn.Player.Role.Add hook to detect role assignments

    The Lyn.Player.Role.Add hook is called after a player has been assigned a role. It provides details about the player, their SteamID64, the role granted, and the expiration timestamp. If the expires_at value is 0, the role is permanent.
    -- Hook signature
    Lyn.Player.Role.Add(ply, steamid64, role, expires_at)
  2. Handle player ban events with Lyn.Player.Ban hook

    The Lyn.Player.Ban hook is a shared hook called immediately after a player has been banned. It provides details about the banned player, the ban duration, the reason for the ban, and the administrator who issued it.
    -- Example usage of the Lyn.Player.Ban hook
    -- Lyn.Player.Ban(ply, steamid64, duration, reason, admin_steamid64)
  3. Lyn.Role.PreDelete hook parameters

    The Lyn.Role.PreDelete(string name, Role role) hook accepts two parameters:

    1. name (string): The name of the role that is about to be deleted.
    2. role (Role table): The data table associated with the role being deleted.
  4. Send notifications within a command's Execute method

    When sending messages from within a command's :Execute method, use LYN_NOTIFY instead of Lyn.Player.Chat.Send. This allows the Lyn.Command.Notify hook to intercept and override the output if necessary.
  5. Create custom alias prefixes and sticky aliases

    Use :CustomAlias() to override the prefix behavior for a specific alias. This is particularly useful for symbol-based shortcuts.

    CustomAlias Options:

    • chat_prefix (string): Override the chat prefix for this specific alias.
    • console_prefix (string): Override the console prefix for this specific alias.
    • sticky (boolean): If true, the alias matches even if text follows immediately without a space. If false (default), a space or end-of-input is required after the alias.
    Command("adminsay")
        :CustomAlias("@", { chat_prefix = "", sticky = true })
        :Param("string", { hint = "message" })
        :GetRestArgs()
        :Execute(function(caller, message)
            -- ...
        end)
        :Add()
    -- Result: !adminsay message (standard) or @message (sticky, no prefix)
  6. Create a custom UI theme in Lyn

    To create a new UI theme, create a Lua file at addons/lyn-themes/lua/lyn/themes/yourthemename.lua. The file must return a table containing the theme's display name and color definitions. You can optionally use Lyn.I18n.Register to provide localized names for the theme.
    Lyn.I18n.Register({
        en = {
            themes = {
                ["My Theme"] = "My Theme",
            },
        },
        ["zh-cn"] = {
            themes = {
                ["My Theme"] = "我的主题",
            },
        },
    })
    
    return {
        name               = "My Theme",
        blur               = true,
    
        -- Base surfaces
        ["bg"]             = "#1A1B1EBB",
        ["bg-200"]         = "#3E3F42BB",
        ["bg-300"]         = "#2C2D30BB",
    
        ["fg"]             = "#F0F2F5",
        ["fg-200"]         = "#C5CEDC",
        ["fg-300"]         = "#8A939E",
    
        -- Primary
        ["primary"]        = "#5B21B6",
        ["primary-200"]    = "#6A28D9",
        ["primary-300"]    = "#7537E1",
    
        ["primary-fg"]     = "#F5F0FF",
        ["primary-200-fg"] = "#FAF8FF",
        ["primary-300-fg"] = "#FFFFFF",
    
        -- Accent
        ["accent"]         = "#0A6B75",
        ["accent-200"]     = "#14B8A6",
    
        ["accent-fg"]      = "#F4FEFF",
        ["accent-200-fg"]  = "#F0FFFF",
    
        -- Error / Success / Warning
        ["error"]          = "#D33732",
        ["error-fg"]       = "#f8f8f2",
    
        ["success"]        = "#28a745",
        ["success-fg"]     = "#f8fdf9",
    
        ["warning"]        = "#fcb700",
        ["warning-fg"]     = "#2d2006",
    }
  7. Override an existing Lyn theme

    To override an existing theme, create a theme file using the same name as the theme you wish to modify. The values provided in your file will replace the original theme's values.
    return {
        name      = "Blur",
        ["bg"]    = "#000000BB",
        ["fg"]    = "#FFFFFF",
    }
  8. Create a basic command in Lyn

    Commands are created using the Lyn.Command object. You define the command name, optional permissions, parameters, and an execution function. It is critical to call :Add() at the end of the chain to register the command.
    local Command = Lyn.Command
    
    Command("commandname")
        :Permission("permission_name", "default_role")
        :Param("type", { options })
        :Execute(function(caller, arg1, arg2, ...)
            -- Your code here
        end)
        :Add()
  9. Add simple aliases to a command

    Use the :Aliases() method to provide multiple names for a single command. All simple aliases inherit the global chat and console prefixes defined in the configuration.
    Command("teleport")
        :Aliases("tp", "goto", "warp")
        :Execute(function(caller, targets, destination)
            -- ...
        end)
        :Add()
  10. Optimize network bandwidth using constants in Lyn

    Constants in Lyn act as identifiers for shared variables or hooks sent from the server to the client. They function similarly to util.AddNetworkString by replacing long string keys with small integer identifiers, significantly reducing the bytes sent over the network. For example, using a constant can reduce a 27-byte string key to just two bytes.
    -- Example of setting a shared variable
    Lyn.Player.SetSharedVar(Entity(1), "HeyThisIsMyKeyThatIsAwesome", true)
  11. Restrict command parameter values using Role Constraints

    Constraints limit the values a role can pass to a specific command parameter (e.g., capping a moderator's !ban duration). Constraints are indexed by the parameter's position (1-based) and are inherited through the extends property of roles.

    If a player possesses multiple roles, the least restrictive constraint is applied. If any of the player's roles have no constraint defined for that parameter, the restriction is removed entirely. Note that the superadmin role is never constrained.

    -- For number or duration parameters: define min and max bounds
    { min = 60, max = 3600 }
    
    -- For string or role parameters: provide a whitelist of allowed values
    { "user", "vip" }