jiMUD allows you to use javascript for macros, trigger, aliases, buttons, or context items. This allows for powerful and more advanced features over the basic #functions and just sending text.
To use scripting you just have to select script as the type from the type dropdown in the item editor.
$selected
- selected text$selectedword
- word under mouse when right clicked$selectedline
- line under mouse when right clicked$selectedurl
- url under mouse when right clicked$selword
same as $selectedword$selline
sane as $selline$selurl
same as $selected url$action
last triggered action executed$trigger
last text, event, or pattern that caused last trigger to fire$contextMenu
access to the context menu item array, manipulating this will effect the displayed context menu, WARNING this could break the context menu, if broken you can refresh by causing a profile to be re-saved
You can access them by doing client.getVariable('name') or this.getVariable('name'). Some variables may not be accessible to the parser: i and repeatnum are special variables and are used i loops and are not accessible in parse style, named arguments in parse style will be used instead of any user defined of the same name, variables lost when client is closed
client.getVariable('name')
- return value of variable name
client.setVariable('name', value)
- Set variable name to value
client.hasVariable('name')
- return if variable exists
client.removeVariable('name')
- return a variable
client.setVariables(Object)
- set a group of batch of variable at once in format of {'name':value,...}
Note older access methods: client.variables['NAME'], client.variables.NAME, this.variables['NAME'], or this.variables.NAME should be avoided in case variable collection changes in the future to add saveable variables
Example:
this.setVariable('test', 5);
client.setVariable('test', 5);
this.setVariables({'test':5, 'test2':5});
let val = this.getVariable('test');//val would be 5
Set or created variables can be access in the expression system by name eg ${test + 5} would be 10 based from example
Naming convention use javascript identifier rules, which are must be at least 1 character of a-z,A-Z,$, or _ followed by a-z,A-Z,$,_, or 0 - 9, and not a javascript keyword
Aliases allow named arguments set using a command delimited list which are converted into local scoped javascript variables, Example: Alias with named arguments: name,message
this.print(name + ' says ' + message);
Triggers allow named capturing which are converted into local scoped javascript variables Example: Trigger pattern: (?<name>.*) says (?<message>.*)
this.print(name + ' says ' + message);
client.id()
return current client idclient.setName(name, id?)
set name for id or if no id set current client nameclient.getName(id?)
return name for id, if no id return current client nameclient.clearName(id?)
clears client name of supplied if, if no id clears current client idclient.closeWindow(name|id)
Close an open window or tabname|id
if no name or id will attempt to close current tab/window, otherwise will attempt to close named window or by id
client.beep()
play system beep soundclient.readClipboard()
read text from clipboard, can also access from window.readClipboard()client.writeClipboard(text, html)
write text to clipboard, can also access from window.writeClipboard(text), html argument is optional, allows formatted html markup of text for applications that support pasting htmlclient.readClipboardHTML()
read HTML from clipboard, can also access from window.readClipboardHTML()client.send(text, echo?)
send text directly to the mud, telnet code IAC is escaped, note you should always try and append a new line as most muds require it to process any text.text
the text to sendecho
echo text to display
client.sendAll(text, echo?)
send text directly to the mud, telnet code IAC is escaped, note you should always try and append a new line as most muds require it to process any text to all clientstext
the text to sendecho
echo text to display
client.sendTo(name|id, text, echo?)
send text directly to the mud, telnet code IAC is escaped, note you should always try and append a new line as most muds require it to process any text to all clientsname|id
the client name or id of the mud to send totext
the text to sendecho
echo text to display
client.sendRaw(text)
sends raw text directly to the mud as isclient.sendAllRaw(text)
sends raw text directly to the mud as is for all clientsclient.sendToRaw(name|id, text)
sends raw text directly to the client name or idname|id
the client name or id of the mud to send totext
the text to send
client.sendCommand(text, noEcho?, comments?)
sends a command as if sent from the command linetext
the text to sendnoEcho
do not echo text to screencomments
parse inline and block comments
client.sendAllCommand(text, noEcho?, comments?)
send a command to all client windowstext
the text to sendnoEcho
do not echo text to screencomments
parse inline and block comments
client.sendToCommand(name|id, text, noEcho?, comments?)
send a command to all client windowsname|id
the client name or id of the mud to send totext
the text to sendnoEcho
do not echo text to screencomments
parse inline and block comments
client.sendBackground(text, noEcho?, comments?)
sends a command as if sent from the command line with out modifying the current command linetext
the text to sendnoEcho
do not echo text to screencomments
parse inline and block comments
client.sendAllBackground(text, noEcho?, comments?)
send a command to all client windows with out modifying current command linetext
the text to sendnoEcho
do not echo text to screencomments
parse inline and block comments
client.sendToBackground(name|id, text, noEcho?, comments?)
send a command to all client windows with out modifying current command linename|id
the client name or id of the mud to send totext
the text to sendnoEcho
do not echo text to screencomments
parse inline and block comments
client.print(text, newline)
print text to screen, newline argument is optional and controls weather to start a newline if last line was a fragment/promptclient.echo(text, fore, back, newline, forceline)
echo text to the screentest
the text to echofore
ansi foreground code default is local echoback
background colornewline
see this.printforceline
always force a new line regardless of current last line state
client.parse(text)
send raw text to the screen to be parsed and displayed, can be used to send raw ansi or MXP codedclient.sendGMCP(text)
send a GMCP formatted string to the mud, see GMCP spec notes for formatting, its mostly in {module, data} where data is a JSON formatted stringclient.notify(title, message, options)
display a windows notification for systems that support it, options are optionaltitle
the title of the notificationmessage
the message to displayoptions
additional options to customize the display Notification Optionsdir
- auto, rtl, ltricon
- full icon path, supports {variables}silent
- play sound or not, default false
client.raise(event, args, delay)
fire an event with optional delay and argumentsevent
the event name to fireargs
an optional array of arguments to pass to the event, if you do not want to pass arguments but want a delay just pass 0 or []delay
the number of milliseconds to wait before firing event- Example"
client.raise('get all', [], 2000);
client.show()
show client's parent windowclient.hide()
hide client's parent windowclient.toggle()
toggle hide and showclient.sendChat(text)
send text to chat windowclient.indices
return the current indices for trigger or an empty array same as %x1..$x99
WARNING: you can effect the client if you access the wrong function, so any function used other then this list may caused unknown results and could cause the client to stop working
Notice how all the functions have a client. in front of them, this is the client object that has all functions related to the client. For backward compatible with the ShadowMUD web client we also support OoMUD and this for non ES6 arrow function formats.
- Name: alarm
- Style: script
- Value:
/*
Syntax to use: <alarm [message] [seconds]>
*/
//store message in local variable so it can be passed to timer
var message = arguments[1];
//convert to number and multiply by 1000 to convert to milliseconds
var ms = 1000 * parseInt(arguments[2], 10);
setTimeout( function() {
//echo message to screen
client.sendCommand("#echo " + message);
}, ms);
setTimeout(()=> {
//send a command to the mud
client.sendCommand("say Hello world.");
}, 2000);
//wait additional time to say it again
setTimeout(()=> {
//send a command to the mud
client.sendCommand("say Hello world again");
}, 4000);
//notice the timing is 4000 this is 2000 from the original + 2000 for the new for a total of 4 seconds
//Unlike zMUD where timing is build up, with javascript you will have to handle your own consecutive timing
/*
Start mono gray-scale rainbow example
syntax: monoline [line] [text]
to use this alias in OoMUD, create a new alias named monoline, set the style to Script
and ensure append arguments is checked
*/
//the line to display text on
var line = arguments[1];
//new string
var str = '';
//colors to use
var colors = [];
//random start
var offset = Math.ceil(Math.random()*1000);
//build color list
for(var i=0; i < 20; i++)
{
if(3+i < 10)
colors[i] = '%^mono0'+(3+i)+'%^';
else
colors[i] = '%^mono'+(3+i)+'%^';
if(23-i < 10)
colors[i+20] = '%^mono0'+(23-i)+'%^';
else
colors[i+20] = '%^mono'+(23-i)+'%^';
}
//start at arguments 2 since 0 is full line, and 1 is the line,
//so any thing after 2 is the text we want
var args = Array.prototype.slice.call(arguments);
var oldStr = args.slice(2).join(' ');
for(var c = 0; c < oldStr.length;c++)
{
var i = (c + offset) % colors.length;
str += colors[i]+oldStr.charAt(c);
}
this.sendCommand(line + ' ' + str);
//End mono grayscale example
/*
Start Rainbow 256 example
syntax: rs [text]
to use this alias, create a new alias named rs, set the style to Script
and ensure append arguments is checked and paste this in the value
*/
//the string to send to the mud
var out = '';
//counter variable for looping
var i;
//build table once and store to speed up
if(!window.forecolors256)
{
//initialize color table
window.forecolors256 = [];
for(i=0; i<30; i++)
window.forecolors256.push([0,0,0]); //set each color to [R,G,B] array for manipulation
//build rainbow colors
for(i=0; i<5; i++)
{
/*0-4*/ window.forecolors256[i][0]+=5; window.forecolors256[i][1]+=i+1;
/*5-9*/ window.forecolors256[i+5][0]+=4-i; window.forecolors256[i+5][1]+=5;
/*10-14*/ window.forecolors256[i+10][1]+=5; window.forecolors256[i+10][2]+=i+1;
/*15-19*/ window.forecolors256[i+15][1]+=4-i; window.forecolors256[i+15][2]+=5;
/*20-24*/ window.forecolors256[i+20][2]+=5; window.forecolors256[i+20][0]+=i+1;
/*25-29*/ window.forecolors256[i+25][0]+=5; window.forecolors256[i+25][2]+=4-i;
}
//Build final color codes using the R,G,B array
window.forecolors256 = window.forecolors256.map(c => `%^RGB${c[0]}${c[1]}${c[2]}%^`);
}
//random color offset
var offset=Math.ceil(Math.random()*1000);
//build the string, this ensures all arguments are gotten
var args = Array.prototype.slice.call(arguments);
//start at the first argument as 0 is the alias + arguments, and convert to an array
var str = [...args.slice(1).join(' ')];
//store length for a little extra speed
var l = str.length;
//loop array and build new string inserting color codes
for(i=0; i<l; i++)
{
var i2= (i+offset) % window.forecolors256.length;
out += window.forecolors256[i2]+str[i];
}
client.sendCommand("'%^RESET%^"+out+"%^DEFAULT%^");
/*
Status display dots
syntax:
statuschange id color - change a status dot color
statuschange reset - reset all dots to default
statuschange remove - remove all dots
to use this alias, create a new alias named statuschange, set the style to Script
and ensure append arguments is checked and paste this in the value
*/
//add a reset option
if(arguments.length === 2 && arguments[1] === 'reset')
$('#dot-status').remove();
//remove dots
if(arguments.length === 2 && arguments[1] === 'remove') {
$('#dot-status').remove();
return;
}
//create status display
if($('#dot-status').length === 0){
//first try web client
var body = $('#phil');
//# of columns, change this if you add more then 6 dots to allow better formatting
var columns = 1;
//if not found use jimud
if(body.length === 0) {
body = $('#limbs');
body.append('<span id="dot-status" class="dot-container" style="display: inline-block;bottom: 70px;position: absolute;left: 0;width:'+(columns * 20)+'px;">');
} //position based on phill
else
body.append('<span id="dot-status" class="dot-container" style="display: inline-block;bottom: 0;position: absolute;width:'+(columns * 20)+'px;left: -25px;">');
//get container
body = $('#dot-status');
//easy build of status
var cStatus = function(id) {
return '<span class="dot" id="'+id+'" style="height: 10px;width: 10px;background-color: white;border-radius: 50%;display: inline-block;margin-left: 5px;"></span>';
}
//create status dots
//create a dot named stat, use statuschange stat [color] to change its color
body.append(cStatus('stat')); //copy this line and change stat to a unique name, then use statuschange [name] [color]
//create as many other dots with unique ids as you want, if you add more then 6 add more columns above, remove // from below to add these dots
//body.append(cStatus('buffer'));
//body.append(cStatus('mantle'));
//body.append(cStatus('quicken'));
//body.append(cStatus('poison'));
//body.append(cStatus('wbreathing'));
}
if(arguments.length === 3)
$('#' + (arguments[1] || 'stat')).css('background', arguments[2] || 'white');
else
$('#' + ('stat')).css('background', arguments[1] || 'white');