I posted this in another thread but I feel it deserves its own thread. After all, I use this code a lot and I feel that many others would find it useful as well.
function createBrick(%cl, %data, %pos, %color, %angleID)
{
//This function was made by Xalos.
//Its purpose is to create a brick owned by a player on which they are able to build.
if(!isObject(%data) || %data.getClassName() !$= "fxDTSBrickData")
return -1;
if(getWordCount(%pos) != 3)
return -1;
if(%angleID $= "")
%angleID = 0;
if(isObject(%cl) && (%cl.getClassName() $= "GameConnection" | %cl.getClassName() $= "AIConnection"))
{
%blid = %cl.bl_id;
if(%blid $= "")
%blid = -1;
%flag = 1;
}
else if(isObject(%cl) && %cl.getClassName() $= "SimGroup" && MainBrickgroup.isMember(%cl))
%group = %cl;
else
%cl = 0;
switch(%angleID)
{
case 0:
%rot = "1 0 0 0";
case 1:
%rot = "0 0 1 90";
case 2:
%rot = "0 0 1 180";
case 3:
%rot = "0 0 -1 90";
}
(%brick = new fxDtsBrick()
{
client = %cl;
colorFxID = 0;
colorID = %color;
datablock = %data;
isPlanted = 1;
position = getWord(%pos, 0) SPC getWord(%pos, 1) SPC getWord(%pos, 2);
rotation = %rot;
shapeFxID = 0;
stackBL_ID = %blid;
}).angleID = %angleID;
%err = %brick.plant();
%brick.setTrusted(1);
missionCleanup.add(%brick);
if(%flag)
%cl.brickgroup.add(%brick);
else if(isObject(%group))
%group.add(%brick);
return %brick TAB %err;
}
createBrick(findClientByName(Xal), brick2x4Data, "0 0 4", 5, 1);