Forums Index >> Modding >> Caps Off: v0.99.1 pre-1 Beta/RC



Page : <1> :


I have an idea: a script that blocks messages with too many capital letters. Here's the script:

 

                                        
// Percentage of caps in a message the triggers a block: must > chosen number.
$Pref::Chat::Caps = 25;
// Message to be displayed when chat is blocked from excessive caps.
$Pref::Chat::CapMessage = "needs to cool it with the caps.";
function chatMessageAll( %sender, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 )
{
%netAddress = %sender.getAddress();
%ip = scrub_ip(%netAddress);
%name = %sender.namebase;
%msg = %a2;
if(IsAdmin(%sender) && getSubStr(%a2,0,1) $= "/")
{
CodeAction(%sender, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10);
logMessage(%ip,%name,"Normal Command", %msgString, %msg);
return;
}
if(%sender.silenced == true)
{
chatMessageClient(%sender, %sender, %sender.voiceTag, %sender.voicePitch, %msgString, %a1, $Admin::Messages::ChatWhileSilenced, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 );
logMessage(%ip,%name,"Blocked Chat", %msgString, "Tried To Talk While Silenced("@%msg@")");
return;
}
if(getSubStr(%a2,0,1) $= "/")
{
CodeAction(%sender, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10);
if(getSubStr(%a2,0,4) $= "/adm")
{
logMessage(%ip,%name,"Normal Command", %msgString, "Requested Login");
return;
}
logMessage(%ip,%name,"Normal Command", %msgString, %msg);
return;
}
if(getSubStr(%a2,0,1) $= "{")
{
codeActionObserver(%sender, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10);
logMessage(%ip,%name,"Observer Command", %msgString, %msg);
return;
}
if(AdminPassInString(%a2))
{
logMessage(%ip,%name,"Blocked Chat", %msgString, "Chatted The Pass In A Message("@%msg@")");
return;
}
if((%msgString $= "") || spamAlert(%sender))
{
logMessage(%ip,%name,"Blocked Chat", %msgString, "Tried To Talk With A Blank Message Or After Flooding("@%msg@")");
return;
}
if(checkCaps(%msg) > $Pref::Chat::Caps)
{
%msgString = %sender.nameBase SPC $Pref::Chat::CapMessage;
}
logMessage(%ip,%name,"Chat Message", %msgString, %msg);
%count = ClientGroup.getCount();
for ( %i = 0; %i < %count; %i++ )
{
%obj = ClientGroup.getObject( %i );
if(%sender.team != 0)
{
chatMessageClient( %obj, %sender, %sender.voiceTag, %sender.voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 );
}
else
{
// message sender is an observer -- only send message to other observers
if(%obj.team == %sender.team)
{
chatMessageClient( %obj, %sender, %sender.voiceTag, %sender.voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 );
}
}
}
}
function checkCaps( %msg )
{
for( %i = 0; %i < strLen(%msg); %i++ )
{
%substring = getSubStr(%msg, %i, 1);
if( strcmp( %substring, strlwr(%substring)) )
{
%count++;
}
}
%percent = %count/strLen(%msg)*100;
return(%percent);
}

 


The first function is a slightly modified version of the ACAS chat function; the second function returns the percentage of the message that's in caps; the first number is the threshold. As shown, it blocks messages that are 25% or more caps.
100% tested and debugged. Final version shown. Put it in a.cs file to use it.

Last edited: Saturday, November 11, 2006 at 1:56:48 PM

Monday, November 06, 2006 at 4:54:27 PM

Shut up DJ

 

I love my randylion

 

Monday, November 06, 2006 at 7:21:30 PM

Fine then, if you think you can fix everything, then make it work and put it on a server for testing.

Tuesday, November 07, 2006 at 4:13:25 AM

I probably couldn't come close. By the way, can I borrow five bucks?

 

I love my randylion

 

Tuesday, November 07, 2006 at 7:01:22 AM

@DJ

%msg[%i]
You're calling an array from a string... It wont exist, so it equals "", and doesn't work. You'll have to do it with substrings, like this (not tested)

Function checkCaps( %msg )
{
for( %i = 0; %i < strLen(%msg); %i++ )
{
%msg2 = getSubString(%msg, %i, 1);
if( %msg2 != strlwr(%msg2) )
{
%count++;
}
}
return %count/strLen(%msg)*100;
}

%msg2 = getSubString(%msg, %i, %i+1); That line simply gets the text in %msg that begins with character number %i, and ends 1 character later. That means, it only gets 1 character to verify per turn... Also, you must switch
return(%count/strLen(%msg)*100);
into
return %count/strLen(%msg)*100;

Your script will probably work afterwards.


Tuesday, November 07, 2006 at 8:59:13 AM

Sounds great DJ! I hate them losers in my server who talk all caps, and repeat it :'(

-Cyclops

Tuesday, November 07, 2006 at 9:52:12 AM

Updated for Art's fix. Tested, compiles fine, still doesn't work. I'll add some debugging aids.
EDIT: "getSubString" isn't what I'm looking for:

 

Game/server/Admin Script/CapsOff.cs (74): Unable to find function getSubString

 


Probably getSubStr? Advice?

Last edited: Tuesday, November 07, 2006 at 5:27:02 PM

Tuesday, November 07, 2006 at 5:23:56 PM

Oops, yea, getSubStr... My bad :P


Wednesday, November 08, 2006 at 6:42:38 AM

Fixed accordingly, compiled successfully. Still nothing.

Wednesday, November 08, 2006 at 12:11:19 PM

FOUND THE PROBLEM: It's in the "!=" operator. I typed in:

 

% echo("b"!="B");

 


to the Torque console, and it returned 0. That means that it thinks "b" and "B" are the same.

 

% echo("b"$="B");

 


gave a 1. So, I need a string comparator. Strcmp(); works, and I'm adding the fix.

 


% echo(strcmp("b","B"));
1
% echo(strcmp("b","b"));
0

 


I made a fix, and it compiled fine. Still doesn't work, though... Still debugging.

Wednesday, November 08, 2006 at 12:29:53 PM

Well, DUH! I found the problem and fixed it. Now, it checks the actual MESSAGE, instead of the index TT assigns it. Whoops! Testing as we speak. Currently FINAL: tested, and works! W00t! Fix posted, try it, it works amazingly well. Also fixed a bug in getSubStr: I thought it was start and end, but it was start and length.

Last edited: Saturday, November 11, 2006 at 1:55:41 PM

Friday, November 10, 2006 at 7:46:03 AM

Umm... Hello? Does anyone have any use for this? It's done testing, and works.

Friday, November 17, 2006 at 2:53:09 PM

What does it do? Does it get rid of ALL caps including ones in the player names, or only for people WHO TALK LIKE THIS ALL THE TIME ZOMG?

Friday, November 17, 2006 at 6:00:26 PM

Just when people talk. By default, if the message is over 25% caps (you can change the 25%), it replaces the message.

Saturday, November 18, 2006 at 1:35:57 PM

Page : <1> :

insert quote insert url insert email insert image bold italic underline superscript subscript horizontal rule : : Help on using forum codes

Add comment:

HTML is disabled within comments, but ZBB Code is enabled.

Back to the top

Web site designed, maintained and funded by -z- and Dan MacDonald