I've been experimenting with some methods for making the 2x2barrel brick asplode when shot.


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.
So what you did is put a delay between deletes? I did something like that too, except with schedule(). Though it got a little glitchy when exploding a lot of objects because the schedules got large...
Yeah this just counts down. I've yet to crash my current setup.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement