I've been experimenting with some methods for making the 2x2barrel brick asplode when shot.
Code:
I made it's maxDamage = 10; in brickdata.cs to account for radius damage.
It "explodes" when shot by most weapons (I added the same code from the hackprojectile to all other non-exploding projectiles) but not when the brick dies from radius damage. Also, the actual explosion particle effect isn't showing up for other clients, even though it shows up fine for other projectiles that use it, like the grenade. It's also not scaling the projectile to the size of the brick, allthough this isn't much of a problem.
EDIT- got it to show up to clients, that had to do with when the code was being read, and so moving it to the grenade launcher script fixed that. However, I'm having trouble getting it to apply the effect to radius damage:
Code:
I put that in TBMradiusdamge.cs just before damage is applied.
EDIT- problems fixed. AND I fixed the crashing that results from destroying large numbers of objects with radius damage. I feel so awesome now I could get high off myself. Now where's my lighter?
http://tbm.pastebin.com/f3835591
pastebin'd for profanity
http://www.youtube.com/watch?v=h122BgiglXE
demonstration video.
Code:
function HackProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
if(%col.getDatablock().getName() $= "staticBarrel2x2")
{
%projectile = BarrelProjectile;
%initPos = %obj.getTransform();
%p = new (projectile)()
{
dataBlock = %projectile;
initialVelocity = "0 0 10";
initialPosition = %initPos;
sourceObject = %col;
sourceSlot = 0;
client = %obj.client;
};
MissionCleanup.add(%p);
%p.setTransform(%col.getTransform());
%p.setscale(%col.getscale());
%col.delete();
}
else
{
tbmcollison(%this,%obj,%col,%fade,%pos,%normal);
tbmcollison(%this,%obj,%col,%fade,%pos,%normal);
tbmradiusDamage
(%obj, VectorAdd(%pos, VectorScale(%normal, 0.01)),
%this.damageRadius,%this.radiusDamage,%this.damageType,%this.impulse);
}
}
function Hack2Projectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
tbmcollison(%this,%obj,%col,%fade,%pos,%normal);
tbmcollison(%this,%obj,%col,%fade,%pos,%normal);
tbmradiusDamage
(%obj, VectorAdd(%pos, VectorScale(%normal, 0.01)),
%this.damageRadius,%this.radiusDamage,%this.damageType,%this.impulse);
}
datablock ProjectileData(BarrelProjectile)
{
projectileShapeName = "tbm/data/shapes/weapons/barrel2x2.dts";
directDamage = 0;
radiusDamage = 100;
damageRadius = 8;
explosion = GLExplosion;
particleEmitter = mortarcannontrailEmitter;
muzzleVelocity = 0;
velInheritFactor = 1;
armingDelay = 0;
lifetime = 3000;
fadeDelay = 2500;
bounceElasticity = 0;
bounceFriction = 0;
isBallistic = true;
gravityMod = 1;
damagetype = '%1 died in an epic barrel explosion';
};
function BarrelProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
tbmcollison(%this,%obj,%col,%fade,%pos,%normal);
tbmcollison(%this,%obj,%col,%fade,%pos,%normal);
tbmradiusDamage
(%obj, VectorAdd(%pos, VectorScale(%normal, 0.01)),
%this.damageRadius,%this.radiusDamage,%this.damageType,20);
}
function staticbarrel2x2::onDeath(%this, %obj)
{
%projectile = BarrelProjectile;
%initPos = %obj.getTransform();
%p = new (projectile)()
{
dataBlock = %projectile;
initialVelocity = "0 0 10";
initialPosition = %initPos;
sourceObject = %obj;
sourceSlot = 0;
client = %obj.client;
};
MissionCleanup.add(%p);
%p.setTransform(%obj.getTransform());
%p.setscale(%obj.getscale());
parent::onDeath();
}
I made it's maxDamage = 10; in brickdata.cs to account for radius damage.
It "explodes" when shot by most weapons (I added the same code from the hackprojectile to all other non-exploding projectiles) but not when the brick dies from radius damage. Also, the actual explosion particle effect isn't showing up for other clients, even though it shows up fine for other projectiles that use it, like the grenade. It's also not scaling the projectile to the size of the brick, allthough this isn't much of a problem.
EDIT- got it to show up to clients, that had to do with when the code was being read, and so moving it to the grenade launcher script fixed that. However, I'm having trouble getting it to apply the effect to radius damage:
Code:
if(%targetObject.getDatablock().getName() $= "staticBarrel2x2")
{
%projectile = BarrelProjectile;
%initPos = %targetObject.getTransform();
%p = new (projectile)()
{
dataBlock = %projectile;
initialVelocity = "0 0 10";
initialPosition = %initPos;
sourceObject = %col;
sourceSlot = 0;
client = %sourceObject.client;
};
MissionCleanup.add(%p);
%p.setTransform(%targetObject.getTransform());
%p.setscale(%targetObject.getscale());
}
I put that in TBMradiusdamge.cs just before damage is applied.
EDIT- problems fixed. AND I fixed the crashing that results from destroying large numbers of objects with radius damage. I feel so awesome now I could get high off myself. Now where's my lighter?
http://tbm.pastebin.com/f3835591
pastebin'd for profanity
http://www.youtube.com/watch?v=h122BgiglXE
demonstration video.