Author Topic: Brick Health Script  (Read 767 times)

I made a script that gives bricks a health value.  Shoot the bricks with a gun, and the health goes down.  When a brick's health reaches 0, the brick is fake-killed, and then deleted.  Reload bricks if you want it back.

Currently it works for any default weapon, and also the complex weapons pack(The one I was using).  I had to manually add in the complex weapons as they store their damage values in their damage function and it was faster to just add them than try to find some way of making the script figure it out.

Enjoy.

Code: (server.cs) [Select]
function fxDTSBrick::initHealth(%brick)
{
%boxMin = getWords(%brick.getWorldBox(), 0, 2);
%boxMax = getWords(%brick.getWorldBox(), 3, 5);
%boxDiff = vectorSub(%boxMax, %boxMin);
%health = mAbs(getWord(%boxDiff,0)*getWord(%boxDiff,1)*getWord(%boxDiff,2)*60);
if(%health<=3841)
{
%brick.health = %health;
}
}

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

package BrickHealthPackage
{
function fxDTSBrick::onPlant(%brick)
{
%brick.initHealth();
Parent::onPlant(%brick);
}
function fxDTSBrick::onLoadPlant(%brick)
{
%brick.initHealth();
Parent::onLoadPlant(%brick);
}
function fxDTSBrick::onProjectileHit(%brick, %proj, %client)
{
if(isObject(%proj)&&%brick.health!$="")
{
if(!isObject(%proj.damageRef))
{
%dmg = %proj.getDatablock().directDamage;
%brick.health-=%dmg;
if(%brick.health<=0)
{
%brick.fakekillbrick(vectorscale(%proj.getVelocity(),0.05), 2);
%brick.schedule(1000,"delete");
}
}
else
{
switch$ (%proj.damageRef.getName())
{
case "ColtWalkerImage":
%dmg = 75;
case "Colt1911Image":
%dmg = 16;
case "M1GarandImage":
%dmg = 30;
case "M24RifleScopeImage":
%dmg = 90;
case "M24RifleImage":
%dmg = 90;
case "MicroUziImage":
%dmg = 10;
case "Remington870Image":
%dmg = 10;
case "RevolverImage":
%dmg = 25;
case "ThompsonImage":
%dmg = 7.5;
default:
%dmg = 1;
}
%brick.health-=%dmg;
if(%brick.health<=0)
{
%brick.fakekillbrick(getrandom("0,4") SPC getrandom("0,4") SPC getrandom("0,4"), 2);
%brick.schedule(1000,"delete");
}
}
}
Parent::onProjectileHit(%brick, %proj, %client);
}
};
activatepackage(BrickHealthPackage);

http://www.mediafire.com/file/rq734nvv818nnnb/Script_BrickHealth.zip

Did you mean to post this in add-ons?

Nope.  I don't consider it a "finished" add-on.  It does not work with most ray-cast style weapons.

Normally I would put this in Modification Discussion, but that's gone.

You know you could probably package the raycast collision method to account for brick damage

I looked closer at the code.

For the S&W Revolver the amount of damage a weapon does is stored in function RevolverImage::damage(%this, %obj, %col, %position, %normal)
That function does some checks on where it's hitting, and then triggers %col.damage(%obj, %position, %damage, %damageType);

I need to catch the input of %col.damage
I shouldn't replace %col with the brick ID and create a fxDTSBrick::Damage function as if the revolver did a check such as %col.isCrouched() it would throw an error.

I could create a bot, and package up AIPlayer::damage() so that it catches the amount of damage for me.
If I need to use this mod in the future, that is what I will try.