This should work:
function SERVERCMDToggleMTR(%client)
{
if(!%client.isSuperAdmin)
return;
//Toggle ModTer Interior Build Restriction (by using /ToggleMTR chat command)
if($Pref::Server::ModTerIntBuildRes)
{
$Pref::Server::ModTerIntBuildRes = false;
messageAll('',"\c6ModTer interior building is now \c2\"ENABLED\"");
}
else
{
$Pref::Server::ModTerIntBuildRes = true;
messageAll('',"\c6ModTer interior building is now \c0\"DISABLED\"");
}
}
package Package_MTR
{
function fxDtsBrick::onPlant(%brick)
{
%parent = Parent::onPlant(%brick);
//If ModTer restriction is enabled, don't run ModTer brick check
if(!$Pref::Server::ModTerIntBuildRes)
return %parent;
//Find planted brick's client, angle ID, datablock and position
%client = %brick.client;
%BrAngID = %brick.angleID;
%BrDB = %brick.getDataBlock();
%BrPosXYZ = %brick.getPosition();
//Determine brick size for container search below (take planted brick's rotation into account)
switch(%BrAngID)
{
case 0 or 2:
%BrSizeX = %BrDB.brickSizeX * 0.5;
%BrSizeY = %BrDB.brickSizeY * 0.5;
case 1 or 3:
%BrSizeX = %BrDB.brickSizeY * 0.5;
%BrSizeY = %BrDB.brickSizeX * 0.5;
}
%BrSizeZ = %BrDB.brickSizeZ * 0.2;
//Run a container search (relative to planted brick's position and size) to see if brick is within a ModTer brick
%BrSizeXYZ = %BrSizeX - 0.1 SPC %BrSizeY - 0.1 SPC %BrSizeZ - 0.1;
initContainerBoxSearch(%BrPosXYZ,%BrSizeXYZ,$TypeMasks::FxBrickObjectType);
//Check all bricks within container search area (failsafe is just a precaution, but not necessary)
while(isObject(%TmpBrObj = containerSearchNext()) && %failSafe++ <= 1000)
{
//If brick has the ModTer print aspect ratio, it's probably a ModTer brick ("%TmpBrObj != %brick" prevents issues with planting ModTer bricks)
if(%TmpBrObj.getDataBlock().printAspectRatio $= "ModTer" && %TmpBrObj != %brick)
{
if(isObject(%client))
commandToClient(%client,'centerPrint',"ModTer interior building is currently disabled.",5);
//Destroy brick if within a ModTer brick (delay of 100 ms is to prevent issues with removing brick before returning parent)
%brick.schedule(100,killBrick);
break;
}
}
return %parent;
}
};
activatePackage(Package_MTR);
I just tested it in-game and it should work just fine. You can use /ToggleMTR to toggle the restriction; it runs a container search relative to the planted brick to check if it's within a ModTer brick, and destroys the brick if so.
Edit: Modified script to also take brick's rotation into account.