🟪sam.Command.new

Command sam.Command.new( string command_name )

Description

Creates a new command object and returns it.

  • You must create the command in a shared file, which means you create it exactly the same on both Server & Client sides.

  • You need to call command:End() to actually register the command.

Aguments

  1. string command_name

Returns

Example #1

local sam = sam
local Command = sam.Command

Command.new("pm")
    :Help("Send a PM!")

    :SetPermission("pm", "user")

    :AddArg("player", {
        allow_higher_target = true,
        single_target = true,
        cant_target_self = true
    })
    :AddArg("text", {
        hint = "message",
        check = function(str)
            return str:match("%S") ~= nil
        end
    })
    
    :GetRestArgs()
    
    :OnExecute(function(ply, targets, message)
        if ply:sam_get_pdata("unmute_time") then
            return ply:sam_send_message("you_muted")
        end

        local target = targets[1]

        ply:sam_send_message("pm_to", {
            T = targets, V = message
        })

        if ply ~= target then
            target:sam_send_message("pm_from", {
                A = ply, V = message
            })
        end
    end)
:End()

Last updated