Forums Index >> Modding >> Caps Off: v0.99.1 pre-1 Beta/RC
Page : <1> :
Shut up DJ
I love my randylion
I probably couldn't come close. By the way, can I borrow five bucks?
I love my randylion
@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.
Sounds great DJ! I hate them losers in my server who talk all caps, and repeat it :'(
-Cyclops
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
Oops, yea, getSubStr... My bad :P
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.
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
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