Author Topic: Clear Spam Bricks Server Script- Need help- Can't fit in title  (Read 953 times)

/title
I'm trying to code an automatic spam brick clearer, here's what I've come up with so far:
Quote
//By Setro2, clears spam bricks automatically
function servercmdclearspambricks() {
}
exec("blah blah blah");
Yeah, not that much. I have some questions and need help.
1. What's the console commands for clearing spam bricks?
2. How do I make it loop with certain intervals?
Please help. All help is appreciated.

1. commandtoserver('clearspambricks',""); OR servercmdclearspambricks(%client);
2. schedule(time,0,Function,argument);

function clearloop(%time){
if (%stop != 1)
{
commandtoserver('clearspambricks',"");
schedule(%time,0,'clearloop',%time);
}
}

function servercmdClearLoop(%client, %time){
if (%client.isSuperAdmin && %time >= 30)
{
%stop = 0;
%time *= 1000; //seconds to miliseconds
clearloop(%time);
}
}

function serverCmdStopClearLoop(%client){
if (%client.isSuperAdmin)
%stop = 1;
}
I believe, that should work, but i do not advise you use it...
-edit
added turning it off

^^ un needed, but didnt want to delete

edit - answered questions
« Last Edit: October 10, 2012, 09:54:45 PM by MARBLE MAN »

I have my own client-sided spam clearer for when I'm an admin on a server and the host wants me to clear spam when he/she doesn't want to.

Code: [Select]
$ASC::LoopTime = 120;

package Auto_Spam_Clear
{
function ASC()
{
cancel($ASC::Loop);
schedule(1000,0,commandtoserver,'clearspambricks');
commandtoserver('messageSent',"{Auto Spam Clear} Clearing spam bricks...");
$ASC::Loop = schedule($ASC::LoopTime*1000,0,'ASC');
}

function StopASC()
{
cancel($ASC::Loop);
schedule(250,0,deactivatepackage,"auto_spam_clear"); //you can take this out if you want
}
};
activatePackage(Auto_Spam_Clear);

(I just ripped this out of my bot's auto-spam-clearer just edited)

If this is not exactly what you're asking for, please say so.
« Last Edit: October 10, 2012, 10:09:53 PM by tkepahama »

If this is not exactly what you're asking for, please say so.
Quote from: Thread Title
Clear Spam Bricks Server Script


snip
1. no, that will only work client-side looks like you either added the second part while I was typing, or I just didn't see it
2. I'd add more instruction than that
Small text code contains errors


1. serverCmdClearSpamBricks(%client);
If you never host a dedicated server, you could just use yourself: serverCmdClearSpamBricks(findLocalClient());
But if you ever host a dedicated server, or plan on publically releasing this, you need a way to ensure that there will always be client available that is always able to call the command. In situations like this I just create an AIConnection with isAdmin set to 1.
Personally I would just start off with the method that works in dedicated servers, so you don't have to change it later.

2.
Code: [Select]
function genericLoopingFunction(%arg1,%arg2,...%argN)
{
cancel($genericLoopingFunctionTick);
//do stuff
$genericLoopingFunctionTick = schedule(timeInMS,0,genericLoopingFunction,%arg1,%arg2,...%argN);
}
« Last Edit: October 10, 2012, 10:12:10 PM by Headcrab Zombie »


If you never host a dedicated server, you could just use yourself: serverCmdClearSpamBricks(findLocalClient());
doesn't localClientConnection work too?

Or you can just copy-paste the code used in the servercmd into a regular function, and then put it in a loop.

Code: [Select]
//Time is in minutes.
$ClearSpamLoopTime = 20;

function clearSpamBricks()
{
   if(getBrickCount() > 0)
messageAll('MsgClearBricks', "\c0Spam bricks have been cleared.");

   //loop through all bricks
   %groupCount = MainBrickGroup.getCount();
   for(%i = 0; %i < %groupCount; %i++)
   {
      %group = MainBrickGroup.getObject(%i);
      %count = %group.getCount();
      for(%j = 0; %j < %count; %j++)
      {
         %brick = %group.getObject(%j);

         //we're only interested in bricks...
         if(!(%brick.getType() & $TypeMasks::FxBrickAlwaysObjectType))
            continue;

         //that are on the ground...
         if(%brick.getDistanceFromGround() != 0)
            continue;

         //and planted...
         if(!%brick.isPlanted)
            continue;
         
         //and not dead...
         if(%brick.isDead)
            continue;

         %brickData = %brick.getDataBlock().getID();
         if(%brickData.category $= "Baseplates")
         {
            //it's a baseplate, but if it's all alone and red or has an item attached to it, it's probably still spam
            if(%brick.getNumUpBricks() == 0 && (%brick.getColorID() == 0 || isObject(%brick.item)) )
            {
               %brick.killBrick();
            }
            //if this is a red "plain" or "road" baseplate with an identical baseplate on top of it, it's probably spam
            else if(%brick.getNumUpBricks() == 1 && %brick.getColorID() == 0 && (%brickData.subCategory $= "Plain" || %brickData.subCategory $= "Road"))
            {
               %upBrick = %brick.getUpBrick(0);
               if(%upBrick.getDataBlock().getID() == %brickData && %upBrick.getColorID() == 0)
                  %brick.killBrick();
            }
         }
         else
         {
            //not a baseplate, kill it
            %brick.killBrick();
         }
      }
   }
}

function spamClearLoop(%x)
{
cancel($ClearSpamLoop);

if(%x)
clearSpamBricks();
else
return;

//Just make sure the loop time doesn't have decimals.
schedule($ClearSpamLoopTime * 6 @ "0000", 0, spamClearLoop, 1);
}

function startClearLoop()
{
cancel($ClearSpamLoop);

schedule($ClearSpamLoopTime * 6 @ "0000", 0, spamClearLoop, 1);
}

function stopClearLoop()
{
cancel($ClearSpamLoop);
}