Author Topic: I need some ideas here  (Read 1155 times)

function greetingDB(%client) {
    if(%isObject(%client)) {
        announce(%client // I have absolutely no idea how to use announce properly
       
    }
       
       
//This is my second time ever tinkering with torquescript, care to help a guy out?


I'm working on a greetings add-on, basically whenever a player joins the server a message is displayed that they can set. I plan to make messages monitored, so that no swearing is ever displayed.

The thing is, however, that I have absolutely no idea how I'd accomplish this, and I want to know how I could make this possible?

Thanks!

... so that no swearing is ever displayed.
Haha, good luck with that

Just to show you the complexity of curse filtering, here is what I use:

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

function mStringReplace(%source, %searchTokens, %replace)
{
while("" !$= %searchTokens)
{
%searchTokens = nextToken(%searchTokens, "stripToken", ",");

if(%text $= "")
%text = striReplace(%source, %stripToken, %replace);
else
%text = striReplace(%text, %stripToken, %replace);

}
return %text;
}

function containsSubstring(%msg, %searchTokens)
{
while("" !$= %searchTokens)
{
%searchTokens = nextToken(%searchTokens, "stripToken", ",");
%pos = strPos(%msg, %stripToken);

if(%pos == -1)
continue;

if(getSubStr(%msg, %pos, strLen(%stripToken)) $= %stripToken)
return 1;
}
return 0;
}

function stripRepeatingChars(%string)
{
%length = strLen(%string);

for(%i = 0; %i < %length; %i++)
{
%current = getSubStr(%string, %i, 1);

if (%current !$= %previous)
{
%strip = %strip @ %current;
}
%previous = %current;
}
return %strip;
}

function stringNextToString(%string, %searchTokens)
{
while("" !$= %searchTokens)
{
%searchTokens = nextToken(%searchTokens, "stripToken", ",");
%string = strLwr(%string);
%len = strLen(%stripToken);
%pos = strPos(%string, %stripToken);

if(%pos == -1)
continue;

if(%string $= getSubStr(%string, %pos, %len))
{
//they entire message only contains %stripToken
return 1;
}
else if(getSubStr(%string, %pos + %len, 1) $= " ")
{
return 1;
}
else if(%pos - 1 != -1)
{
if(getSubStr(%string, %pos - 1, 1) $= " ")
{
return 1;
}
}
else if(getSubStr(%string, %pos, %len) $= getSubStr(%string, %pos + %len, %len))
{
return 1;
}
}
return 0;
}

function curseFilter(%msg)
{
%chk = mStringReplace(%msg, "a,A,@", "a");
%chk = mStringReplace(%chk, "b,B", "b");
%chk = mStringReplace(%chk, "c,C,(", "c");
%chk = mStringReplace(%chk, "d,D,I)", "d");
%chk = mStringReplace(%chk, "e,E,3", "e");
%chk = mStringReplace(%chk, "f,F,ph,pH,Ph,PH", "f");
%chk = mStringReplace(%chk, "g,G,6", "g");
%chk = mStringReplace(%chk, "h,H,#", "h");
%chk = mStringReplace(%chk, "i,I,!,1", "i");
%chk = mStringReplace(%chk, "j,J", "j");
%chk = mStringReplace(%chk, "k,K", "k");
%chk = mStringReplace(%chk, "l,L,|_", "l");
%chk = mStringReplace(%chk, "m,M,|\\/|,/\\/\\", "m");
%chk = mStringReplace(%chk, "n,N,|\\|,/\\/", "n");
%chk = mStringReplace(%chk, "o,O,0", "o");
%chk = mStringReplace(%chk, "p,P", "p");
%chk = mStringReplace(%chk, "q,Q,9,?", "q");
%chk = mStringReplace(%chk, "r,R", "r");
%chk = mStringReplace(%chk, "s,S,$,5", "s");
%chk = mStringReplace(%chk, "t,T,7", "t");
%chk = mStringReplace(%chk, "u,U", "u");
%chk = mStringReplace(%chk, "v,V", "v");
%chk = mStringReplace(%chk, "w,W,vv,VV,\/\/", "w");
%chk = mStringReplace(%chk, "x,X", "x");
%chk = mStringReplace(%chk, "y,Y", "y");
%chk = mStringReplace(%chk, "z,Z,2", "z");
%chk = mStringReplace(%chk, " ,_,-,.", "");
%chk = strLwr(%chk);

if(containsSubstring(%chk, "assassin,urstar fish,titanium"))
return 0;

if(containsSubstring(%chk, "ass,cum,brown town,arse,spic,nig,azz,hell,tit,pron"))
{
if(stringNextToString(%chk, "ass,cum,brown town,arse,spic,nig,azz,hell,tit,pron") == 1)
{
return 1;
}
else if(containsSubstring(%chk, "starfish,asshoel,asss"))
{
return 1;
}
}

//strip repeating characters, handles stuff like fuuuuck or diiick, would break ass, so this comes after the ass check.
%chk = stripRepeatingChars(%chk);

if(containsSubstring(%chk, "forget,fvck,Riddler,bitch,kunt,stuff,niger,niglet,richard,rooster,cunt,dic,dik,fuc,fvc,fvk,cvnt,fuk,research,love,secks,star fish,damn,pusy,bastard,carrot,slut,creep,suckmy,snake,vagina,jiz,wtf,handicap,rape,interject,redskin,wetback,cracker,chollo,downsyndrome,autism,cigarette,cigaretteot,kike,"))
{
return 1;
}
return 0;
}

In this code, use curseFilter("message");
It will return a '1' if it has curse words, and a '0' if it doesn't.

Or I can simplify the forget out of that for you.

Code: [Select]
function swearFilter(%string) {
    %tsvWords=strReplace("forget,fvck,Riddler,bitch,kunt,stuff,niger,niglet,richard,rooster,cunt,dic,dik,fuc,fvc,fvk,cvnt,fuk,research,love,secks,star fish,damn,pusy,bastard,carrot,slut,creep,suckmy,snake,vagina,jiz,wtf,handicap,rape,interject,redskin,wetback,cracker,chollo,downsyndrome,autism,cigarette,cigaretteot,kike,", "\t"); // This would be faster if you tab separated the values to begin with, but I'm too lazy.

    %wordCnt = getFieldCount(%tsvWords);

    while(%x++) {
        for(%i = 0; %i < %wordCnt; %i++) {
            if((%pos = striPos(%string, %word = getField(%tsvWords, %i))) > -1) {
                %wordLength = strLen(%word);
                for(%y = 0; %y < %wordLength; %y++) { %repl = %repl @ "*"; }
                %string = getSubStr(%string, 0, %pos) @ %repl @ getSubStr(%string, %start = %pos+%wordLength, strLen(%string)-%start-1);
                %repl = "";
        }

        if(%x >= 2) break;

        %strLen = strLen(%string);
        for(%i = 1; %i < %strLen; %i++) {
            if(getSubStr(%string, %i, 1) == getSubStr(%string, %i-1, 1)) {
                %string = getSubStr(%string, 0, %i) @ getSubStr(%string, %i+1, %strLen - %i);
                %strLen--;
            }
        }
    }
    return %string;
}

You can add in whatever /\/ -> N kind of stuff you want, but that seems petty to me. Both yours and mine will catch "titillating". Mine will swap it to "***illating" which seems more acceptable than blocking the message entirely. When it comes down to it, you can write your code to be as all-inclusive as you possibly can, but at the end of the day, other people are going to think of more permutations than you can. If I was employed to write a swear filter, I would implement a simple neural networking algorithm so that over time it would pick up on nuances.
« Last Edit: June 25, 2015, 07:29:45 AM by $trinick »

You are legends, sirs, but I think the real issue is my understanding of console commands. Anyone have a good resource for learning them besides the rtf file Badspot gave us?


Ignore our messages. Darksaber's was meant to discourage you from doing what you're trying to do, and mine was in direct response to his lack of humility.

Code: [Select]
function greetingDB(%client) {
    if(%isObject(%client)) {
        announce(%client // I have absolutely no idea how to use announce properly
       
    }

This is what you have. There's a couple of issues with this code, but that's alright.

The first issue you have is on the second line. The % symbol tells Torque you're talking about a variable, something that holds a value. isObject is a function, not a variable, so there's no need for the % before it.

Announce is also a function, so you're right on point with not putting a % before it. Announce is actually pretty easy to use as far as functions go. The function takes one input, in programming we call inputs parameters or arguments. There's no difference, the words are used interchangeably. The only parameter it takes is the message to send to everyone. So you use the function like so: announce("Hello World!");. The semicolon is put on the end of lines that tell Torque to do something.

Finally, you're missing a closing bracket at the end. Every opening bracket needs a closing bracket. So if I just tidy up and correct your code, this is what it should look like:

Code: [Select]
function greetingDB(%client) {
    if(isObject(%client)) {
        announce(%client);
    }
}

This code is fine as far as Torque is concerned. It just probably doesn't do what you want it to do. When this function is run, it just shows everyone the object ID number of the client you provided, assuming it exists.

You could change this to say "A player has joined!" pretty easily: just replace announce(%client); with %announce("A player has joined!");. Not hard stuff.

However, you want this code to run when a player joins. That's a little more complex. You have to make it run when a player joins. This post explains how to inject your code into a function that already exists. You should read it, but I'll show you how you do it when a player joins.

Code: [Select]
package whenAPlayerJoins {
    function GameConnection::AutoAdminCheck(%client) { // this function is called when a player is checked to see if they have auto admin, which happens when they join. Convenient.
         greetingDB(%client); // You'll want to run your function here.
         parent::AutoAdminCheck(%client); // This makes sure that the function does what it's supposed to after your code is run.
    }
};
activatePackage(whenAPlayerJoins);

Ignore our messages. Darksaber's was meant to discourage you from doing what you're trying to do, and mine was in direct response to his lack of humility.

Code: [Select]
function greetingDB(%client) {
    if(%isObject(%client)) {
        announce(%client // I have absolutely no idea how to use announce properly
       
    }

This is what you have. There's a couple of issues with this code, but that's alright.

The first issue you have is on the second line. The % symbol tells Torque you're talking about a variable, something that holds a value. isObject is a function, not a variable, so there's no need for the % before it.

Announce is also a function, so you're right on point with not putting a % before it. Announce is actually pretty easy to use as far as functions go. The function takes one input, in programming we call inputs parameters or arguments. There's no difference, the words are used interchangeably. The only parameter it takes is the message to send to everyone. So you use the function like so: announce("Hello World!");. The semicolon is put on the end of lines that tell Torque to do something.

Finally, you're missing a closing bracket at the end. Every opening bracket needs a closing bracket. So if I just tidy up and correct your code, this is what it should look like:

Code: [Select]
function greetingDB(%client) {
    if(isObject(%client)) {
        announce(%client);
    }
}

This code is fine as far as Torque is concerned. It just probably doesn't do what you want it to do. When this function is run, it just shows everyone the object ID number of the client you provided, assuming it exists.

You could change this to say "A player has joined!" pretty easily: just replace announce(%client); with %announce("A player has joined!");. Not hard stuff.

However, you want this code to run when a player joins. That's a little more complex. You have to make it run when a player joins. This post explains how to inject your code into a function that already exists. You should read it, but I'll show you how you do it when a player joins.

Code: [Select]
package whenAPlayerJoins {
    function GameConnection::AutoAdminCheck(%client) { // this function is called when a player is checked to see if they have auto admin, which happens when they join. Convenient.
         greetingDB(%client); // You'll want to run your function here.
         parent::AutoAdminCheck(%client); // This makes sure that the function does what it's supposed to after your code is run.
    }
};
activatePackage(whenAPlayerJoins);
I'll do some more reading up on TorqueScript before I continue, but thank you so much anyway! I'm used to Ruby and its beautiful syntax, and high-level programming is much more strict than Ruby, so it's instantly uncomfortable.

check out other addons that have similar functionality
in an autosaver addon I found
Code: [Select]
function serverCmdStartAutoSaver(%client)
{
if(%client.isSuperAdmin)
{
AutoSaver_Bomb.start();
messageAll('',%client.getPlayerName() @ "\c6 has started the auto saver.");
}
else
messageClient(%client,'',"\c6Only \c0Super Admins\c6 may start the auto saver.");
}
which has an admin check that you'll probably want
and how to message clients/the server
the first/second arguments that are '' can be sounds, like 'MsgAdminForce', but not sure what other sounds can be played