Main Connecting Starting



Building: Lua Verbs

Lua Verb Objects

Verb objects look pretty much like any other object, but are created and stored slightly differently. They don't live in the game world like other object, but are loaded on demand. To create a new verb, use createverb myverb, which will create a new empty verb object called %verb_myverb which can then be editted like any other object. Changes to verb objects are automatically saved to disk. Run the reloadverbobjects command (or reloadv for short) to activate your new verb.

In order for a verb object to do something useful, it will need a lua.verb set on it. This should contain the code for your verb. Anything that works in a trap will work here.
The id of the object, i.e. "%verb_something", is the name of the verb. In this case, it will create a verb called "something".

There are other things a verb might need.

aliasMakes this verb be an alias for some other verb. The verb for which this is an alias should go in here.
minlenThis is the minimum number of characters which can be used instead of the whole name of the command. This must not be lower than 3, or longer than the command's name.
rank.minThis is the privs level required to be able to use this command, defined as a rank shortcut (eg cpofficer, commodore). Where possible, use a PFlag restriction instead of a level one.
pflagThis is the pflag required to be able to use this command.
descThis is a normal block of text, which may contain pager codes. Use this to document the command instead of adding a new help file.

Lua Code

You define a lua verb by creating a lua.verb trap on the verb's object. The mud supplies just two arguments for you to use in a verb. The first is pl, which is the object which called the command. The second is arg, which is an array of all the words the user supplied as arguments to the command. The index of the last argument may be of use to you, and can be found using getn(arg) within the lua. The first element of the array, arg[0] is the name of the command itself. The rest of the elements, arg[1] through arg[getn(arg)] are the supplied arguments. Be aware that if the user entered any double spaces in the text following the command, these will represented as empty strings in the arg array.

Assuming the command needs to be targetted at an object, you may find it useful to use the matcher libs provided:

local world = match(pl, arg)
local targ = matchplayer(pl, arg[1])
local prep = matchprep(pl, arg, "with")
Match() takes an array as an argument, and will generate an array of every object that pl can interact with at their current location. If you wanted to prevent the command being used on more than one object, you can use getn(world) and check that its value is 1, or generate a suitable error message.

Matchplayer() is rather more simplistic as it takes a single string as an argument, and returns a single object which will be either a player anywhere on the mud, or a mobile next to pl. This lib will not return an object that is not visible to pl.

Matchprep works exactly like match(), only it first searches for the preposition supplied as the third argument in the arg array. For example, calling match on an array that contained 'a and b with c and d' would return an array containing the objects 'a' and 'b'. Matchprep() called on the same array, and "with" wupplied as the preposition, would return and array containing 'c' and 'd'.


You can abort processing of a verb at any point by using 'return'. It doesn't matter what arguments you supply to return, cos they won't do anything. If you want use of your verb to alert the senior officers (and be recorded in the mud log file) you need to use the syslog command:

syslog(priv.SeeInfo,"category",pl,"log message")
The priv.* defines the pflag that is required to see the message... those without that pflag will see nothing. For most system messages, this will be SeeInfo. The other 3 arguments affect what message is displayed: [e[category] (player) in location_1: 'log message' where 'player' is the id of pl, and location_1 is the id of the object which currently contains pl.

Action Contexts

If you want players to be able to use the verb like an action on a command line, you can add standard action object properties to it and it will "just work". Have a look at the kick and fly verbs for an example. Don't forget to read the actions devdoc!