function createBrick(%cl, %data, %pos, %color, %angleID)
{
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;
%cl = %group.client;
%blid = %group.bl_id;
}
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;
}
People keep complaining that it's wrong because I'm setting angleID outside the brick, except it never works properly if I set it inside.
If the 'correct' way doesn't work, it's by definition not correct.
Plus most functions people seem to use don't let you use a brickgroup as opposed to a client, or return both the brick and the error code.