Author Topic: How to place bricks using scripting?  (Read 702 times)

I was thinking of using some script to plant bricks to auto build. I wanna know if this'll work, but I need to know how to place bricks first.

%brick = new fxDTSBrick()
{
     datablock = datablockgoeshere;
     position = "positionhere";
     angle = "anglehere";
     colorID = colorIDHere;
};
MissionGroup.add(%brick);
%brick.setTrusted(1);
%brick.plant();


That should work I think. I probably missed a few functions/arguments.

Code: [Select]
function createBrick(%pos, %Datablock, %AngleID, %ColourID, %ColourFXId)
{
%host = findClientByBL_ID(getNumKeyID());
%hostID = getNumKeyID();
%posx = getWord(%pos, 0);
%posy = getWord(%pos, 1);
%posz = getWord(%pos, 2);
%brick = new fxDTSBrick()
{
client = %host;
datablock = %Datablock;
position = %posx SPC %posy SPC %posz;
rotation = "0 0 0 0";
colorID = %ColourID;
scale = "1 1 1";
angleID = %AngleID;
colorfxID = %ColourFXId;
shapefxID = "0";
isPlanted = 1;
stackBL_ID = %hostID;
};
%brick.setTrusted(1);
%brick.plant();
%host.brickgroup.add(%brick);
}
Use that to create a brick that has the host's ownership. I'm assuming that's what you want, as you're probably using it for your own purposes.

BTW: Brians code will not work.

BTW: Brians code will not work.
It should. This is ripped straight out of my networked terrain generator:
Code: [Select]
function ChunkTCP::makeBrickAtHeight(%this, %pos, %db, %color)
{
        if(getWord(%pos,2) == 0)
                return;
        %brick = new fxDTSBrick()
        {
                position = vectorAdd(%pos,"0 0 1.2");
                dataBlock = %db;
                colorID = %color;
                isBasePlate = 1;
                isPlanted = 1;
        };
        %brick.setTrusted(1);
        BrickGroup_10.add(%brick);
        %brick.plant();
}
Granted mine leaves out some goodies like angleid because they're unneeded when building cubes, but it should work nonetheless.
« Last Edit: February 10, 2012, 10:32:03 PM by Slicksilver »

You make also find this example useful which allows you to bypass specific planting errors, and let other errors be fatal (taken from block_types.cs in my System_Tarpex):
Code: [Select]
function blockType::createBrick( %this, %position, %angleId, %noFloat )
{
%obj = new fxDTSBrick()
{
position = %position;
rotation = "1 0 0" SPC 90 * %angleId;
dataBlock = %this.dataBlock;

angleId = %angleId;
colorId = %this.colorId;
blockType = %this;
};

%obj.setTrusted( true );
getTPXBrickGroup().add( %obj ); // You will probably want to change this line.

%err = %obj.plant();

if ( %err )
{
if ( !%noFloat && %err == 2 ) // You might want to change this line.
{
%obj.isPlanted = true;
%obj.plant();

return %obj;
}
else
{
%obj.delete();
return %err;
}
}

return %obj;
}

This will place a block which is allowed to be floating, but not overlapping, buried, etc.
« Last Edit: February 11, 2012, 05:01:45 AM by Port »

-snip-

Gah, accidental Quote instead of Modify.