Blockland Forums > Modification Help
How to filter and replace a chat segment
<< < (5/5)
frogger3140:

--- Quote from: Uristqwerty on November 29, 2010, 01:53:09 PM ---I didn't notice that one.

In that case:


--- Code: ---function striReplace(%source, %search, %replace)
{
    if(strlen(%search) < 1)
      return;
    %len = strlen(%search);
    %i = 0;
    while((%i = stripos(%source, %search, %i)) >= 0)
    {
        %source = getSubStr(%source, 0, %i) @ %replace @ getSubStr(%source, %i + %len, strlen(%source) - %i - %len);
        %i += strlen(%replace);
    }
    return %source;
}

--- End code ---

Make use of that optional third argument!

(Edit: input check)

--- End quote ---
Is that case-sensitive?

EDIT: That script isn't working, why do your scripts always break!

Here's the code to my chat filter

--- Code: ---function striReplace(%source, %search, %replace)
    {
    if(strlen(%search) < 1)
      return;
    %len = strlen(%search);
    %i = 0;
    while((%i = stripos(%source, %search, %i)) >= 0)
    {
        %source = getSubStr(%source, 0, %i) @ %replace @ getSubStr(%source, %i + %len, strlen(%source) - %i - %len);
        %i += strlen(%replace);
    }
    return %source;
}
package FroPack_ChatStuff
{
function ChatSound()
{
   for(%i=0; %i < ClientGroup.getCount(); %i++) {
      %cl = ClientGroup.getObject(%i);
     
      %cl.play2D(Sawtooth);
   }   
}
     function serverCmdMessageSent(%cl,%msg)
     {
          %msg = striReplace(%msg,"rotten frog","morsch Frosch"); //begin tenda-to-german conversions
          %msg = striReplace(%msg,"frying pan","Bratpfanne");
          %msg = striReplace(%msg,"yiff","983d909713cf1feb33ee821c1915e0ae"); //begin furryspeak-to-MD5 conversions
          %msg = striReplace(%msg,"vore","03b45bce682586cafb346f27e076d97b");
          %msg = striReplace(%msg,"furcigarette","4e38bbe5e0ec1d0709f9c283a7b1d195");
          %msg = striReplace(%msg,"furry","f96af09d8bd35393a14c456e2ab990b6");
          %msg = striReplace(%msg,"furries","1ff7f8b0b702e9de1b1e6a72e4550361");
          Parent::serverCmdMessageSent(%cl,%msg);
          ChatSound();
     }
};
activatepackage(FroPack_ChatStuff);
datablock AudioProfile(Sawtooth)
{
   filename = "./Chat.wav";
   description = AudioClose3d;
   is3D = true;
preload = true;
};

--- End code ---
Ethan:
Use this one, it's from Truce:

--- Quote from: Truce on November 29, 2010, 12:43:24 PM ---Ok, fine. Complication for case changing go:


--- Code: ---function striReplace(%source,%search,%replace)
{
if(%search $= "")
return %source;

%lena = strLen(%source);
%lenb = strLen(%search);

for(%i = 0; %i < %lena; %i++)
{
%part = getSubStr(%source,%i,%lenb);

if(%part !$= %search)
{
%clean = %clean @ getSubStr(%source,%i,1);
continue;
}

%clean = %clean @ %replace;
%i    += %lenb - 1;
}

return %clean;
}
--- End code ---

--- End quote ---
frogger3140:
It works! Problem SOLVED
Navigation
Message Index
Previous page

Go to full version