Blockland Forums > Modification Help
Client-Side Message Modifier?
Lil Robot:
Irk89 helped me make a script, in which he did most of the work because I suck at coding.
--- Code: ---// Author: Irk89
// Desc: replace a with 4, and s with 5
// a % at the beginning of whenever i chat
// since we are overriding a function (inserting what we want into it)
// we have to set up a package.
package MessageOverrider
{
//the function we are going to override
function serverCmdMessageSent(%client, %message)
{
// this is called right before the script sends the message to the server.
// now we can do anything we want with %message
if(%client.bl_id == 1279)
{
%message = strreplace(%message, "a", "4");
%message = strreplace(%message, "s", "5");
%message = strreplace(%message, "A", "4");
%message = strreplace(%message, "S", "5");
%message = "%"@%message;
}
// end changing message, send it to the server
Parent::serverCmdMessageSent(%client, %message);
return;
}
};
activatePackage(MessageOverrider);
// end of file
--- End code ---
I want to make this client-sided, so that everyone sees it, but the server doesn't have to have the script running, just me. Is this possible?
For example: LilRobot: %h4s 4nyone 5een my gl455e5? -except the server doesn't need the script running, only I do and it converts it to something like that example there.
I want it just so I can use my trollhandle in BL, just for fun.
MegaScientifical:
--- Code: ---package MessageOverrider {
function serverCmdMessageSent(%cl, %msg) {
if(%cl.bl_id == 1279)
%msg = LilRobotTextConvert(%msg);
Parent::serverCmdMessageSent(%cl, %msg);
}
};
activatePackage(MessageOverrider);
function LilRobotTextConvert(%m) {
return "%" @ strReplace(strReplace(strReplace(strReplace(%m, "a", "4"), "s", "5"), "A", "4"), "S", "5");
}
function NMH_Type::send(%this) {
%text = stripTrailingSpaces(%this.getValue());
if(strStr(%text, "/") == 0) {
%command = getSubStr(firstWord(%text), 1, strLen(firstWord(%text))-1);
%vars = restWords(%text);
if(strLen(%vars)) {
%varlist = "\"" @ getWord(%vars, 0) @ "\"";
for(%i = 1; %i < getWordCount(%vars); %i++)
%varlist = %varlist @ ", \"" @ getWord(%vars, %i) @ "\"";
eval("commandToServer(\'" @ %command @ "\'," @ %varlist @ ");");
}
else
eval("commandToServer(\'" @ %command @ "\');");
canvas.popdialog(NewMessageHud);
return;
}
else if(strLen(%text)) {
%text = LilRobotTextConvert(%msg);
if(NewMessageHud.channel $= "TEAM")
commandToServer('teamMessageSent', %text);
else
commandToServer('messageSent', %text);
}
canvas.popdialog(NewMessageHud);
}
--- End code ---
Someone correct me.
Destiny/Zack0Wack0:
--- Quote from: MegaScientifical on April 08, 2011, 02:07:25 AM ---Someone correct me.
--- End quote ---
Sure.
1) You don't need to compress the code. He is trying to understand how to script.
2) Simpler version:
--- Code: ---package Client_LilRobotChat
{
function NMH_Type::send(%this)
{
if(getSubStr(%msg,0,1) !$= "/")
{
%text = trim(%this.getValue());
%text = strReplace(%text,"a","4");
%text = strReplace(%text,"s","5");
%text = strReplace(%text,"A","4");
%text = strReplace(%text,"S","5");
%text = "%" @ %text;
%this.setValue(%text);
}
return Parent::send(%this);
}
};
activatePackage(Client_LilRobotChat);
--- End code ---
EDIT: Not sure if it'll work, but if it doesn't I have another just as simple way of doing it.
MegaScientifical:
Oh, you edited it while I was quoting. o.o Well, it should work. I think send takes that text. But that method does seem iffy in a way.
Edit: Capitalized the B in But. :cookieMonster:
Destiny/Zack0Wack0:
It works.