BuildBot's method of finding the ghost brick is horrible. If there's a brick closer to you than your ghost brick, everything breaks.
I know, but it is literally the best option available without more input from user. If there is another ghost brick of the same datablock closer, there is no way inside or outside of script to be sure just by looking at them for the first time. I know that sometimes I'll be walking through my build and see a ghost brick, then try to clear it thinking it is mine, but it turns out someone left it there. The script doesn't know something you don't, there just isn't a way to be sure. I could probably revamp the code, though to include a check for the color of the ghost brick and something that locks your aim onto the ghost brick and asks "is this your ghostbrick?" and if you click no it locks onto the next one until it either runs out or you click yes. However, that still cannot guarantee the correct one.
for the purposes of jes00, this should work well enough
if(!isobject(%pl = serverconnection.getcontrolobject()))
{
echo("Warning! You are not spawned.");
return 0;
}
%group = %pl.getgroup(); //I'm sure there is a better way, but meh.
%ppos = %pl.getposition();
for(%a=0; %a<%group.getcount(); %a++)
{
if((%b=%group.getobject(%a)).getclassname() $= "fxDTSBrick")
{
if(%b.isplanted() $= "0")
{
%gdist = vectordist(%b.getposition(), %ppos);
if(%gdist < %bestgdist || %bestgdist $= "")
{
%bestgdist = %gdist;
%ghost = %b;
}
}
}
}
if(%ghost $= "")
{
echo("No ghost bricks were found!");
return 0;
}
%pos = %ghost.getposition();