Author Topic: How do you check for particular bricks planted by individual players?  (Read 3303 times)

The echos print out fine, but it does not seem to register %BadCount >= 1.  So is the problem in onAdd or in the for loop?
Code: [Select]
new SimSet(BadBrickTracker);

package BadBricks
{
function brick1x1x5Data::onAdd(%this)
{
BadBrickTracker.add(%this);
parent::onAdd(%this);
}


function ProjectileData_tez::onCollision(%this, %obj, %col, %fade, %pos, %normal)
{
parent::onCollision(%this, %obj, %col, %fade, %pos, %normal);
echo("===> tez 1: beginning onCollision");

if(%col.getClassName() $= "fxDTSBrick")
{
echo("===> tez 2: hit a brick");
%brick = %col;
%Owner = %brick.client;
%OwnerID = %brick.client.bl_id;

if(%OwnerID != %obj.client.bl_id) //don't want them to do this to their own bricks
{
echo("===> tez 3: brick not hit by owner");

%count = BadBrickTracker.getCount();

for(%i = 0; %i < %count; %i++)
{
if(BadBrickTracker.getObject(%i).getGroup().BL_ID == %ownerID)
%BadCount++;
}
if(%BadCount >= 1)
{
%BadBrick = %col.getdatablock().getID();

if(%BadBrick == brick1x1x5Data.getID())
%brick.delete();
}
}
}
}
};
activatePackage(BadBricks);

try putting an echo inside the for loop
see if it's getting called at all

Instead of using both ::onPlant and ::onLoadPlant, you can just do ::onAdd since it covers both cases.

Except you only want planted bricks in that group. Using ::onAdd will include ghost bricks and the preview on the duplorcator. So I recommend using onPlant and onLoadPlant since they're the intended

Anyway, to get owner BLID use %brick.getGroup().BL_ID since if the owner isn't connected the brick's client object won't exist. That's likely your problem since I'm assuming you're loading a save without the builder connected.
« Last Edit: July 06, 2015, 07:18:14 PM by $trinick »

You'll also get bricks that failed to plant (it seems to trigger when attempting to plant floating bricks, but not when planting stuck bricks..)

There's ways to check for that, but like I said in the end it's just a messy workaround. The best way is to just recreate ServerCmdPlantBrick and friends and add packagable checks and modifiers, so people can make it do whatever they want without having a loss of integrity.


Edit: see http://forum.blockland.us/index.php?topic=281430.msg8445534#msg8445534
« Last Edit: July 06, 2015, 11:43:09 PM by Val »

Except you only want planted bricks in that group. Using ::onAdd will include ghost bricks and the preview on the duplorcator. So I recommend using onPlant and onLoadPlant since they're the intended

Anyway, to get owner BLID use %brick.getGroup().BL_ID since if the owner isn't connected the brick's client object won't exist. That's likely your problem since I'm assuming you're loading a save without the builder connected.
Yes getting the builder when offline is also something I wanted.  Although, this test was done immediately after the person planted the brick, no loaded saves involved.  I think something is wrong with the loop or onAdd.  I will use the plant functions instead, but that doesn't seem likely to solve the error of the loop not registering %badCount

try putting an echo inside the for loop
see if it's getting called at all
just shove echos everywhere and let us know what is actually getting called
it's literally the easiest way of debugging it
especially if you have it print out variables too

After digging through some old scripts I found out that YourBrickDataHere::onTrustCheckFinished(%this, %obj) is a fantastic solution to find out whenever your brick is planted (via loading and planting manually) and passed all checks, including trust, errors, etc. It's also called after all the brick's members are finalized such as color, position, print, and so on.

If your code decides that it doesn't want that brick being planted, just do %obj.TrustCheckFailed() and it will clean up the player's undo stack, delete the brick, and also call YourBrickDataHere::onTrustCheckFailed(%this, %obj) (though I don't suggest putting extra code there related to your scripted failure).

It wasn't done by the person planting the brick, right? It can be easy to overlook stuff like if(%OwnerID != %obj.client.bl_id) when testing.

Try getting the brick's ID with /getid and running this console command:

%b=BadBrickTracker;%cnt=%b.getCount();for(%i=0;%i<%cnt;%i++)if(%b.getObject(%i).getID()==INSERT_ID) return call(echo,1);continue;echo(0);

If that echos 1, that brick is in the group (as it should be). If it echos 0, it isn't, and that needs to be corrected.