Input line alias/trigger scripts.
Posted: Thu Feb 16, 2017 2:27 pm
As per request, some details about my alias/trigger scripts.
In order to make Mudlet more accessible to both newbies and mushclient players, I added the ability to set aliases and mushclient like triggers via the input line. This makes it easier for people to use simple aliases and triggers without having to learn the Mudlet interface, which is overwhelming to a lot of non-technical players.
The aliases and triggers support custom variables (set with /set), which adds a layer of flexibility. There are no regular expressions involved. The name of the alias has to be a single word, and each alias has to be prefixed with a slash (/) when called. This to differentiate between client side and server side aliases. Aliases aren't added as Mudlet aliases, but instead stored separately in a hash.
The usage of the alias engine is fairly straightforward:
Triggers were a little more difficult. I couldn't get around creating actual Mudlet triggers, and I had to create a special Trigger folder for them.
I used percentage (%) instead of dollar signs ($) here because that's what mushclient uses, and this command was created specifically for mushclient players.
What this command does internally, is translate the pattern to a proper regular expression, creates a Mudlet trigger with it, and adds that to a special "Generated Triggers" trigger folder. Deleting triggers from lua is impossible as far as I can tell, so when a trigger is removed, it is actually just disabled.
For example, the command:
Will generate the following trigger:
The trigger IDs and original patterns are stored in a separate hash. If someone deletes an entry manually from the Generated Triggers folder, it will also be removed from the hash. This hash is only used for people to keep track of the triggers they've made:
As you can see, the triggers aren't sorted. It's on the todo list
Creating a large number of triggers this way might cause performance issues, but I've found I'm often adding triggers this way instead of proper Mudlet triggers because of convenience.
In order to make Mudlet more accessible to both newbies and mushclient players, I added the ability to set aliases and mushclient like triggers via the input line. This makes it easier for people to use simple aliases and triggers without having to learn the Mudlet interface, which is overwhelming to a lot of non-technical players.
The aliases and triggers support custom variables (set with /set), which adds a layer of flexibility. There are no regular expressions involved. The name of the alias has to be a single word, and each alias has to be prefixed with a slash (/) when called. This to differentiate between client side and server side aliases. Aliases aren't added as Mudlet aliases, but instead stored separately in a hash.
The usage of the alias engine is fairly straightforward:
Code: Select all
/alias [name] [actions]
A local alias command separate from the server. This allows for using
variables and local commands in your aliases not available from the server.
/alias will show the currently set aliases
/alias equipbow /getbag bow; wield bow; /getbag arrow; hold arrow would create an
alias called 'equipbow', which would execute the following commands when called:
/getbag bow
wield bow
/getbag arrow
hold arrow
You can reference arguments the same way as the server side alias,
using $* for all arguments or $1 $2 $3 $etc for individual arguments.
Giving only the alias name without actions will clear an alias.
For instance:
/alias equipbow will clear the alias called 'equipbow'
It is also possible to limit aliases to specific zones or rooms by using
/zonealias and /roomalias respectfully.
Code: Select all
/trigger '<pattern>' <actions>
The pattern must be enclosed with single quotes. Currently, the pattern
cannot contain a single quote. If this is a problem, let me know.
The pattern system is fairly simple. It matches the text you give
it (it is case sensitive), and executes the actions you specified.
The actions are parsed clientside, so you can call other plugin
commands. You can separate multiple commands with a semi-colon (;).
For example:
/trigger '* has arrived.' say hello %1!
Would create a trigger that says hello to anyone arriving in the room.
/trigger without arguments shows you your current triggers:
mt_1: '* has arrived' -> 'say hello %1!'
You can remove triggers with /removetrigger <id>, for example:
/removetrigger mt_1
What this command does internally, is translate the pattern to a proper regular expression, creates a Mudlet trigger with it, and adds that to a special "Generated Triggers" trigger folder. Deleting triggers from lua is impossible as far as I can tell, so when a trigger is removed, it is actually just disabled.
For example, the command:
Code: Select all
/trigger '* has arrived.' say hi %1!; hug %1
The trigger IDs and original patterns are stored in a separate hash. If someone deletes an entry manually from the Generated Triggers folder, it will also be removed from the hash. This hash is only used for people to keep track of the triggers they've made:
As you can see, the triggers aren't sorted. It's on the todo list
Creating a large number of triggers this way might cause performance issues, but I've found I'm often adding triggers this way instead of proper Mudlet triggers because of convenience.