Module command

Functions for registering, hooking, and triggering off of commands.

Functions

hookCommand (name, callback) registers a function to run when a command or skill is attempted.
hookSubCommand (name, callback) registers a function to run when a command is attempted with a specific subcommand.
onCmd (name, callback) registers a function to run when a command or skill is executed.


Functions

hookCommand (name, callback)
registers a function to run when a command or skill is attempted.

Parameters:

  • name string the name of the command or skill to intercept.
  • callback func the function to run.

Usage:

    -- Stop buying cargo in hell. Returning true aborts the command, returning false allows it to proceed
    Command.hookCommand("buycontraband", function(cmd, ch, args)
        local room = ch:getInRoom()
        if ( room ~= nil and room:getVNum() == 6 ) then
            ch:sendTo("&RYou can't buy cargo in hell!")
            return true
        else
            return false
        end
    end)
hookSubCommand (name, callback)
registers a function to run when a command is attempted with a specific subcommand.

Parameters:

  • name string the name of the base command to intercept.
  • callback func the function to run.

Usage:

    -- Adds a "descai" feature/subcommand to the existing C-based "mset" command
    Command.hookSubCommand("mset", function(cmd, ch, args, victim, subcmd, argument)
        if subcmd == "descai" then -- This fires specifically on "mset descai"
            if argument == nil or tonumber(argument) == nil then
                ch:sendTo( "&zSyntax: &Cmset <vnum> descai <anchor vnum>\n\r")
                ch:sendTo( "&zGenerate a mob description based on the mob name and anchor vnum.\n\r")
                return true -- The underlying command was successfully overridden
            end
            local anchorvict = CharProto.getFromVNum( tonumber( argument ) )
            if anchorvict == nil then
                ch:sendTo("Can't find a mob with the provided vnum")
                return true -- The underlying command was successfully overridden
            end
            if anchorvict:getDescription() == nil or anchorvict:getDescription() == "" then
                ch:sendTo("Your anchor mob doesn't have a description")
                return true -- The underlying command was successfully overridden
            end
            -- AI stuff happens here
            return true -- The underlying command was successfully overridden
        end
        return false -- The subcommand didn't match "descai" so the underlying command resolves normally.
    end)
onCmd (name, callback)
registers a function to run when a command or skill is executed.

Parameters:

  • name string the name of the command to trigger off of.
  • callback func the function to run.

Usage:

    -- Triggers based on running ponder. Result 0 is success, 1 is failure.
    Command.onCmd("ponder", function(cmd, arguments, ch, result)
        if ( result == 0 ) then
            LOTJ.log("Character " .. ch:getName() .. " successfully used skill " .. cmd .. ".")
        else
            LOTJ.log("Character " .. ch:getName() .. " failed at the skill " .. cmd .. ".")
        end
    end)
generated by LDoc 1.5.0 Last updated 2026-10-22 21:43:33