Author Topic: A script to have certain words turn into characters  (Read 883 times)

I don't know where to start with this, but this is basically what I want
Say if I type ^point, it will turn into a •
I know how to make it do things like "hi" it will say hi back but I want to have it replace characters.

You can either do it server sided or client sided. I'd recommend client side, as that will allow you to use it on any server, and you can also update the message as you type, as opposed to only formatting after the client has sent the message.

I made a script for this, but I didn't actually make it designed for easy user modification.

Code: [Select]
function AddReplacerItem(%item, %replaceWith, %eval)
{ $ReplacerItem[-1+$ReplacerItems++] = %item TAB %replaceWith TAB %eval; }

package Client_Replacer
{
function NMH_type::send(%this)
{
%text = %this.getValue();
for(%i=0;%i<$ReplacerItems;%i++)
{
if(strPos(%text, %short = getField(%line = $ReplacerItem[%i], 0)) == -1)
continue;
if((%val = getField(%line, 1)) $= "[EVAL]")
%val = eval(getField(%line, 2));
%text = strReplace(%text, getField(%line = $ReplacerItem[%i], 0), %val);
}
%this.setValue(%text);
Parent::send(%this);
}

function RTBCC_Session::send(%this)
{
if(isObject(%obj = %this.window) && isObject(%type = %obj.input))
{
%text = %type.getValue();
for(%i=0;%i<$ReplacerItems;%i++)
{
if(strPos(%text, %short = getField(%line = $ReplacerItem[%i], 0)) == -1)
continue;
if((%val = getField(%line, 1)) $= "[EVAL]")
%val = eval(getField(%line, 2));
%text = strReplace(%text, getField(%line = $ReplacerItem[%i], 0), %val);
}
%type.setValue(%text);
}
Parent::send(%this);
}
};
activatePackage("Client_Replacer");

$ReplacerItems = 0;
AddReplacerItem("[DEG]", "°");
AddReplacerItem("[SQUARE]", "²");
AddReplacerItem("[CUBE]", "³");
AddReplacerItem("[BULLET]", "•");
AddReplacerItem("[RAND]", "[EVAL]", "return ($LRand = getRandom(1, 65536));");
AddReplacerItem("[LRAND]", "[EVAL]", "return $LRand;");
AddReplacerItem("[NULL]", "");

Note that this is case sensitive.

Usage: "[BULLET] Did you know that 8[SQUARE] is the same as 4[CUBE]?"
Chat sent: "• Did you know that 8² is the same as 4³?"

Thank you! What would I edit or do to add new replacers, though?