Disable brick planting inside Modter

Author Topic: Disable brick planting inside Modter  (Read 2509 times)

isWaterBrick is a datablock variable and should not be messed around with after load like the above are suggesting, there is only one real right/simple way to do it and it is the way I explained above.
I could make an add-on to check when people plant a brick to see if it is inside a brick, unless you're going to post one

This should work:

Code: [Select]
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.
« Last Edit: November 13, 2015, 02:28:39 AM by [GSF]Ghost »

Instead of manually calculating the size of the box search you can just do:
Code: [Select]
%minPoint = getWords(%brick.getWorldBox(), 0, 2);
%maxPoint = getWords(%brick.getWorldBox(), 3, 5);
%box = vectorSub(%maxPoint, %minPoint);

initContainerBoxSearch(%BrPosXYZ, %box, $TypeMasks::FxBrickObjectType);

This also takes rotation into account by itself.

That should prevent floating too?


That should prevent floating too?
Yes, it'll treat ramp and corner bricks like cubes, so players won't be able to plant bricks on top of slopes. It'll also prevent floating bricks from being planted inside cubes.


Instead of manually calculating the size of the box search you can just do:
Code: [Select]
%minPoint = getWords(%brick.getWorldBox(), 0, 2);
%maxPoint = getWords(%brick.getWorldBox(), 3, 5);
%box = vectorSub(%maxPoint, %minPoint);

initContainerBoxSearch(%BrPosXYZ, %box, $TypeMasks::FxBrickObjectType);

This also takes rotation into account by itself.
Using the world box is a better solution, thanks. We need to offset the container search area by 0.1 for X, Y and Z however, due to how it works.



Here's an updated script using the world box method jes00 suggested, along with the 0.1 area offset:

Code: [Select]
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 interior building is allowed, don't run ModTer brick check
if(!$Pref::Server::ModTerIntBuildRes)
return %parent;

//Find planted brick's client, position and world box size
%client = %brick.client;
%BrPosXYZ = %brick.getPosition();
%BrWrldBox = %brick.getWorldBox();

//Determine brick size to use for container search below
%BrWBx = getWord(%BrWrldBox,3) - getWord(%BrWrldBox,0);
%BrWBy = getWord(%BrWrldBox,4) - getWord(%BrWrldBox,1);
%BrWBz = getWord(%BrWrldBox,5) - getWord(%BrWrldBox,2);

//Run a container search to see if brick is within a ModTer brick
%BrSizeXYZ = %BrWBx - 0.1 SPC %BrWBy - 0.1 SPC %BrWBz - 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);

Is it ready for me to try it out? Anyone confirmed it works yet?

Is it ready for me to try it out? Anyone confirmed it works yet?
why don't you just frickin try it yourself?

why don't you just frickin try it yourself?

I'm busy at the moment.
« Last Edit: November 17, 2015, 04:43:07 PM by Lord Tony® »

Is it ready for me to try it out? Anyone confirmed it works yet?
Yes it should be ready to use; I tried it in-game using a 1x4 brick just to make sure, so it should work great:


Just copy and paste the code in a Server.cs file in the appropriate add-on folder, or let me know if you want me to set it up as a .zip file.

I think zip would be best.