Author Topic: Client-Side Message Modifier?  (Read 1968 times)

Irk89 helped me make a script, in which he did most of the work because I suck at coding.
Code: [Select]
// 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
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.

Code: [Select]
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);
}

Someone correct me.

Someone correct me.
Sure.
1) You don't need to compress the code. He is trying to understand how to script.
2) Simpler version:
Code: [Select]
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);

EDIT: Not sure if it'll work, but if it doesn't I have another just as simple way of doing it.
« Last Edit: April 08, 2011, 05:08:27 AM by Destiny/Zack0Wack0 »

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:
« Last Edit: April 08, 2011, 07:10:10 AM by MegaScientifical »


It works.

Well that's good, although I never trust disconnected methods like this. I can imagine accidentally adding something... I don't know, but sounds like the best you can do. I rebuild the whole function to be sure I don't have a change of text re-editing.

It's what you're supposed to do.

So I would just drop this in my BL or Add-Ons folder and exec it whenever I enter a server?
I appreciate the help, too. Maybe I can figure out what makes this script do its thing, and start doing this kind of stuff myselfff.

You could do that, but it'd be far easier if you:

1. Put that code in a file called "client.cs"
2. Put that client.cs file you just created into a .zip file that's called "Client_LilRobotChat"

You could do that, but it'd be far easier if you:

1. Put that code in a file called "client.cs"
2. Put that client.cs file you just created into a .zip file that's called "Client_LilRobotChat"

3: Make a "description.txt" in the correct format.
4: Put that in the .zip, too.

3: Make a "description.txt" in the correct format.
4: Put that in the .zip, too.

unless your going to distribute the mod, a .zip isnt required

unless your going to distribute the mod, a .zip isnt required

Manually executing it every load would be annoying, sir. We're lazy Blocklanders, after all.

Manually executing it every load would be annoying, sir. We're lazy Blocklanders, after all.
but you don't need a zip for it to automatically execute, sir. as long as it's named script_something or client_something or something of the likes, and it has a .cs in it named server.cs or client.cs, it should execute automatically.


Now I'm confused what the forget you two are going on about. You're saying make files. But where do they go? Didn't Badspot require all automatically-loaded script must be within a .zip? Where do you put all the files you're saying? If you really mean directly in the Add-Ons folder, that sounds like it could get extremely messy extremely fast.