function buildStructure(%brick, %rotation, %number, %client, %ghost) {
if(!isObject(%brick.getDatablock().structure)) { echo("Structural-less base!"); return; }
%structure = %brick.getDatablock().structure;
if(%structure.noRot)
%rotation = 0;
echo("Structure " @ %structure.complexBuild[%number, %rotation]);
%data = getField(%structure.complexBuild[%number, %rotation], 0);
%rx = getField(%structure.brick[%number, %rotation], 1);
%ry = getField(%structure.brick[%number, %rotation], 2);
%rz = getField(%structure.brick[%number, %rotation], 3);
%ro1 = getField(%structure.brick[%number, %rotation], 4);
%ro2 = getField(%structure.brick[%number, %rotation], 5);
%ro3 = getField(%structure.brick[%number, %rotation], 6);
%ro4 = getField(%structure.brick[%number, %rotation], 7);
%col = getField(%structure.brick[%number, %rotation], 8);
//echo("Data");
%colfx = getField(%structure.complexBuild[%number, %rotation], 9);
%printID = getField(%structure.complexBuild[%number, %rotation], 10);
%newbrick = new fxDTSBrick() {
dataBlock = %data;
scale = "1 1 1";
client = %client;
stackBL_ID = %client.BL_ID;
angleID = "0";
colorID = %col;
colorFXID = %colfx;
printID = %printid;
shapeFXID = "0";
rotation = %ro1 SPC %ro2 SPC %ro3 SPC %ro4;
};
%pos = strreplace(%brick.getposition(), " ", "\t");
%bx = getField(%pos,0);
%by = getField(%pos,1);
%bz = getField(%pos,2);
%newbrick.setTransform(%bx+%rx SPC %by+%ry SPC %bz+%rz SPC %ro1 SPC %ro2 SPC %ro3 SPC %ro4);
if(!%ghost) {
%newbrick.plant();
%newbrick.setTrusted(1);
}
%newbrick.parent = %brick;
%brick.children[0] = %brick.children[0] + 1;
%brick.children[%number] = %newBrick;
%client.brickGroup.add(%newbrick);
if(!%ghost)
schedule(0,0,"removeGhost",%newbrick);
%number = %number + 1;
if(%number < %structure.complexBuild[0])
schedule(0,0,"buildStructure",%brick,%rotation,%number,%client,%ghost);
}
Then I've got this package:
package MeinPackage{
function fxDTSbrickData::onPlant(%brick) {
Parent::onPlant(%brick);
%client = %brick.getGroup().client;
echo("Brick is " @ %brick @ "; Client is " @ %client);
destroyChildren(%brick);
if(isObject(%brick.getDatablock().structure)) {
plantStruct(%brick,%client);
%brick.setColor(%brick.dataBlock.structure.baseCol);
}
}
function fxDTSbrick::onLoadPlant(%this) {
Parent::onLoadPlant(%this);
echo("Brick planted!");
%client = %this.getGroup().client;
echo("Brick is " @ %this @ "; Client is " @ %client);
destroyChildren(%this);
if(isObject(%this.getDatablock().structure)) {
plantStruct(%this,%client);
%this.setColor(%this.dataBlock.structure.baseCol);
}
}
function brickDeployProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal) {
Parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);
%client = %obj.client;
%player = %client.player;
%tmpBrick = %player.tempBrick;
destroyChildren(%tmpbrick);
if(isObject(%tmpbrick.getDatablock().structure)) {
if(%tmpBrick.rotation $= "1 0 0 0") {
%rt = 0;
} else if(getField(strreplace(%tmpBrick.rotation," ", "\t"),2) == -1 && getField(strreplace(%tmpBrick.rotation," ", "\t"),3) > 89 && getField(strreplace(%tmpBrick.rotation," ", "\t"),3) < 91) {
%rt = 1;
} else if(%tmpBrick.rotation $= "0 0 1 180") {
%rt = 2;
} else if(getField(strreplace(%tmpBrick.rotation," ", "\t"),2) == 1 && getField(strreplace(%tmpBrick.rotation," ", "\t"),3) > 89 && getField(strreplace(%tmpBrick.rotation," ", "\t"),3) < 91) {
%rt = 3;
}
%client.structureRotation = %rt;
//echo("Tempbrickdasd = " @ %tmpBrick);
buildStructure(%tmpBrick,%rt,1,%client, true);
}
}
function serverCmdShiftBrick(%client,%shiftx,%shifty,%shiftz) {
Parent::serverCmdShiftBrick(%client,%shiftx,%shifty,%shiftz);
%tmpBrick = %client.player.tempBrick;
//echo("Shifting Brick." SPC %tmpBrick);
destroyChildren(%tmpbrick);
if(%tmpBrick.getDatablock().structural) {
buildStructure(%tmpBrick,%rt,1,%client, true);
}
}
function serverCmdSuperShiftBrick(%client,%shiftx,%shifty,%shiftz) {
Parent::serverCmdSuperShiftBrick(%client,%shiftx,%shifty,%shiftz);
%tmpBrick = %client.player.tempBrick;
destroyChildren(%tmpbrick);
if(%tmpBrick.getDatablock().structural) {
buildStructure(%tmpBrick,%rt,1,%client, true);
}
}
function fxDTSBrick::setDatablock(%this,%data) {
Parent::setDatablock(%this,%data);
%client = %this.getGroup().client;
%tmpBrick = %this;
destroyChildren(%tmpbrick);
if(%tmpBrick.getDatablock().structural) {
if(%tmpBrick.rotation $= "1 0 0 0") {
%rt = 0;
} else if(getField(strreplace(%tmpBrick.rotation," ", "\t"),2) == -1 && getField(strreplace(%tmpBrick.rotation," ", "\t"),3) > 89 && getField(strreplace(%tmpBrick.rotation," ", "\t"),3) < 91) {
%rt = 1;
} else if(%tmpBrick.rotation $= "0 0 1 180") {
%rt = 2;
} else if(getField(strreplace(%tmpBrick.rotation," ", "\t"),2) == 1 && getField(strreplace(%tmpBrick.rotation," ", "\t"),3) > 89 && getField(strreplace(%tmpBrick.rotation," ", "\t"),3) < 91) {
%rt = 3;
}
%client.structureRotation = %rt;
buildStructure(%tmpBrick,%rt,1,%client, true);
}
}
function servercmdRotateBrick(%client,%side) {
Parent::serverCmdRotateBrick(%client,%side);
%player = %client.player;
%tmpBrick = %player.tempBrick;
destroyChildren(%tmpbrick);
if(%tmpBrick.getDatablock().structural) {
if(%tmpBrick.rotation $= "1 0 0 0") {
%rt = 0;
} else if(getField(strreplace(%tmpBrick.rotation," ", "\t"),2) == -1 && getField(strreplace(%tmpBrick.rotation," ", "\t"),3) > 89 && getField(strreplace(%tmpBrick.rotation," ", "\t"),3) < 91) {
%rt = 1;
} else if(%tmpBrick.rotation $= "0 0 1 180") {
%rt = 2;
} else if(getField(strreplace(%tmpBrick.rotation," ", "\t"),2) == 1 && getField(strreplace(%tmpBrick.rotation," ", "\t"),3) > 89 && getField(strreplace(%tmpBrick.rotation," ", "\t"),3) < 91) {
%rt = 3;
}
%client.structureRotation = %rt;
buildStructure(%tmpBrick,%rt,1,%client, true);
}
}
function fxDTSBrick::onRemove(%id) {
destroyChildren(%id);
Parent::onRemove(%id);
}
};
activatePackage(MeinPackage);
With this enabled or disabled, it will call onLoadPlant() when planting any brick. With it enabled, it calls onLoadPlant() when planting any brick.