I have been trying to figure out how to refill a brick with smaller bricks. Here is a small test I have been performing, but have run into some problems. Here is my script:
function fxDtsBrick::Refill(%this)
{
if(isObject(%this) && %this.getDatablock().getName() $= "brick16xCubeData")
{
%pos = %this.getPosition();
%client = findClientByName(lil);
%DB = brick8xCubeData;
%colorId = %this.getColorId();
%colorFxId = %this.getColorFxId();
%shapeFxId = %this.getShapeFxId();
%this.delete();
for(%y=1;%y<4;%y+=2)
{
for(%z=1;%z<4;%z+=2)
{
for(%x=1;%x<4;%x+=2)
{
%newPos = vectorAdd(%pos,4-%x*2 SPC 4-%z*2 SPC 4-%y*2);
%brick = new fxDtsBrick()
{
position = %newPos;
datablock = %DB;
colorId = %colorId;
colorFxId = %colorFxId;
shapeFxId = %shapeFxId;
client = %client;
};
%brick.isPlanted = 1;
%brick.setTrusted(1);
%error = %brick.plant();
echo(%brick SPC "-" SPC %error);
if(%error)
{
%brick.delete();
}
else
{
%client.brickGroup.add(%brick);
%client.UndoStack.Push(%brick TAB "PLANT");
$Server::BrickCount++;
}
}
}
}
}
}
Now I get the id of a 16x Cube and type ID.Refill(); into the console. It does something very weird then. It deletes the 16x Cube and creates all the 4x cubes within the 16x Cube, but they're all invisible and I can't see their wireframe with my wrench out. I go up and hit the "space" with my hammer, and it then makes all the bricks visible, but breaks them all, while leaving all their collisions behind until I hit their space with the hammer again. What's happening and what do I need to fix? It now creates all the bricks and they are all visible, but when I hammer one of them (even the middle ones), the whole column breaks and leaves their collision behind until I hammer their space again. It now just deletes the 16x Cube and does not refill with smaller bricks. I think its returning an error in .plant(), but do any of you have any ideas?