Rain Blocking Script

Author Topic: Rain Blocking Script  (Read 8056 times)

Tired of being wet indoors?  Tired of rain going straight through your roof and onto your head?  Download this mod.



It works by creating a physics zone inside of every single brick.

There is an impact to brick loading time and ghosting time.
It does not work well with large ramp bricks as it can only create rectangular/cubular shaped zones.

If you want to make rain go through a brick, turn raycasting off on that brick.

Source & Downloads
Code: [Select]
function fxDTSBrick::createRainBlock(%brick)
{
   if(!(%brick.isRaycasting())||isObject(%brick.rainblock))
   {
      return;
   }
   %pz = new PhysicalZone()
   {
      polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";
   };
   if(!isObject(%pz))
   {
      error("ERROR: Could not create physical zone for " @ %brick.getDatablock().getName() @ "brick!");
      return;
   }
   missionCleanup.add(%pz);

   %brick.rainblock = %pz;

   //set size
   %boxMin = getWords(%brick.getWorldBox(), 0, 2);
   %boxMax = getWords(%brick.getWorldBox(), 3, 5);
   %boxDiff = vectorSub(%boxMax, %boxMin);
   %pz.setScale(%boxDiff);
     
   //set position - this looks wierd because the the physical zone isn't positioned from it's center
   %posA = %brick.getWorldBoxCenter();
   %posB = %pz.getWorldBoxCenter();
   %posDiff = vectorSub(%posA, %posB);
   %pz.setTransform(%posDiff);
}

if(isPackage(BrickUmbrellas))
{
   deactivatepackage(BrickUmbrellas);
}

package BrickUmbrellas
{
   function fxDTSBrick::onPlant(%brick)
   {
      %brick.schedule(150,"createRainBlock");
      Parent::onPlant(%brick);
   }
   function fxDTSBrick::onLoadPlant(%brick)
   {
     %brick.schedule(150,"createRainBlock");
      Parent::onLoadPlant(%brick);
   }
   function fxDTSBrick::onRemove(%brick)
   {
      if(isObject(%brick.rainblock))
      {
         %brick.rainblock.delete();
      }
      Parent::onRemove(%brick);
   }
   function fxDTSBrick::setRaycasting(%brick, %value)
   {
      if(%value==1)
      {
         if(isObject(%brick.rainblock))
         {
            %pz = %brick.rainblock;

            %posA = %brick.getWorldBoxCenter();
            %posB = vectorSub(%pz.getWorldBoxCenter(),%pz.position);
            %posDiff = vectorSub(%posA, %posB);
            %pz.setTransform(%posDiff);
         }
         else
         {
            %brick.createRainBlock();
         }
      }
      else
      {
         if(isObject(%brick.rainblock))
         {
            %brick.rainblock.setTransform("0 0 -500" SPC %brick.rainblock.rotation);
         }
      }
      Parent::setRaycasting(%brick, %value);
   }
};

activatepackage(BrickUmbrellas);

Mediafire: http://www.mediafire.com/file/nn0v8tb5ny4qwz4/Script_BrickUmbrellas.zip
Dropbox: https://www.dropbox.com/s/4ph66knjav7k5oz/Script_BrickUmbrellas.zip?dl=0
Leopard(Pecon's Filehosting): http://leopard.hosting/download.php?f=idwic&name=Script_BrickUmbrellas.zip
Blockland Glass: [waiting for approval]



is there any effect on performance apart from ghosting?

This seems like it might cause a lot of lag if you have say, 100k bricks.

This could and probably will hinder performance on large/atmospheric builds. Otherwise it's pretty cool.

Think that you can make it combine zones whenever possible?

i have wanted something like this for years lol

having zone bricks that are the only bricks affected by this feature would be a nice alternative

v v v  already covered twice
« Last Edit: November 23, 2016, 10:40:09 AM by Zloff »

This seems really unsafe for large builds

This seems like it might cause a lot of lag if you have say, 100k bricks.
This could and probably will hinder performance on large/atmospheric builds. Otherwise it's pretty cool.
This seems really unsafe for large builds
If you're all so worried, why not test it?

Nice. Something very interesting indeed.

I have no clue how you created the physic's zones within' the brick itself (pos/shape/scale) like how you scaled it.
If you could possibly find a way to see the performance impacts by minimizing the physical zone per brick as much as possible?
You may have already. Combined zones sounds cool as well.
« Last Edit: November 23, 2016, 11:14:58 AM by Soretooth »

For live performance, combining zones where possible while the game is not busy would be best.

For a post processing sort of performance you would want zone bricks or some sort of script which fires raycasts down from the sky to figure out where to place zones after the build is complete.

If you used zone bricks you would run into trouble with water or terrain bricks.  As they are all on the same brick layer.

To get around the brick layer conflict you could make brick umbrella placement bricks which create a anti rain zone instead of a brick.

Personally, this script works fine for what I need it for.  I haven't tested it on any large builds.

I have no clue how you created the physic's zones within' the brick itself (pos/shape/scale) like how you scaled it.
You can grab the bricks world box, or you can use some of the fields in the brick's datablock.  This time I just copied code from the default water bricks.  It saved me a lot of time.

There's roughly an 8-10 fps difference between the script and no script on 30 k bricks. It's a nice effect that it blocks rain from each brick individually.

Some large zone bricks can do the same at less cost of fps, but they'll block rain even if it is above the build you want to block rain from, producing an ugly effect.

Take that how you will.

It appears the impact on framerate is significant.  Using the ingame fps count "metrics(fps);" I got these results with the golden gate bridge. (44465 bricks)  All bricks were within draw distance.

~No mods~
Shaders OFF: ~800 fps
Shaders MAX: ~190 fps

~w/anti-rain~
Shaders OFF: ~110 fps
Shaders MAX: ~63 fps

I am running this using these stats:
CPU: i7-3770k @ 3.5Ghz 4 Cores, 8 Logical Cores
GPU: Nvidia GeForce GTX 660


I've seen a similar effect when using dts collision objects on all bricks.  This game doesn't handle the extra objects very well.

I cannot attest to the accuracy of the in-game fps counter.  But for standardized testing within Blockland applications it should work just fine.
« Last Edit: November 23, 2016, 03:18:21 PM by Tendon »

I found a bit of an issue, if the bricks are high enough, than the rain just falls through the bricks anyway.