Author Topic: Count down exploding barrel?  (Read 319 times)

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Count down exploding barrel?
« on: June 07, 2013, 04:50:07 am »


               I'm trying to make a Gnome engineer, when on perception of the player, he places an Exploding Barrel on the ground, that wil detonate in 10 seconds. 

How can i make the barrel explode w/o using triggers? Can I do it from the heartbeat? 
               
               

               
            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Count down exploding barrel?
« Reply #1 on: June 07, 2013, 05:59:31 am »


               


// Countdown to a fiery explosion. Run via ExecuteScript() on the barrel when it is

// placed/spawned. - The Amethyst Dragon



void TenNineBoom(object oBarrel)

{

if (GetCurrentHitPoints(oBarrel) < 1) { return; } // Don't run if barrel is destroyed before time runs out

location lBarrel = GetLocation(oBarrel);

int nDamage;

effect eVis = EffectVisualEffect(VFX_IMP_FLAME_M);

int nDC = 14; // save DC

ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_FIREBALL), lBarrel);

object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_HUGE, lBarrel, TRUE);

while (oTarget != OBJECT_INVALID)

   {

   nDamage = d6(10); // generic big boom damage

   int nDamage = GetReflexAdjustedDamage(nDamage, oTarget, nDC, SAVING_THROW_TYPE_FIRE, oBarrel);

   if (nDamage > 0)

      {

      ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);

      ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(nDamage, DAMAGE_TYPE_FIRE), oTarget);

      }

   oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_HUGE, lBarrel, TRUE);

   }

}



void main()

{

DelayCommand(10.0, TenNineBoom(OBJECT_SELF));

}


               
               

               


                     Modifié par The Amethyst Dragon, 07 juin 2013 - 08:03 .
                     
                  


            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Count down exploding barrel?
« Reply #2 on: June 07, 2013, 11:33:03 am »


               You could grab my script package called fun doors (111kb download) that has a door with a visible count down before exploding. Actually there are other things in there that you might find useful as well. Just grab whatever scripts you need. I included a table in the package so that people could do that. So have a play with the demo module. Just remember to give credit to whoever's script you go with when you release your work '<img'>.

TR
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Count down exploding barrel?
« Reply #3 on: June 07, 2013, 12:47:54 pm »


               if (GetCurrentHitPoints(oBarrel) > 0) { return; } // Don't run if barrel is destroyed before time runs out

Last time I checked that barrel would be alive... .e.g. if has 1 hp or more means it is alive, then stop the script...  So this should technically stop it from exploding while it is alive, correct?
               
               

               


                     Modifié par _Guile, 07 juin 2013 - 11:49 .
                     
                  


            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Count down exploding barrel?
« Reply #4 on: June 07, 2013, 09:02:42 pm »


               

_Guile wrote...

if (GetCurrentHitPoints(oBarrel) > 0) { return; } // Don't run if barrel is destroyed before time runs out

Last time I checked that barrel would be alive... .e.g. if has 1 hp or more means it is alive, then stop the script...  So this should technically stop it from exploding while it is alive, correct?

D'oh!

Thanks for catching that.  I'll fix it in the script.
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Count down exploding barrel?
« Reply #5 on: June 07, 2013, 09:03:59 pm »


               When the item is placed on the map before hand the heartbeat script triggers. But when the NPC places it down, it doesn't seam to trigger. Any ideas why? I've tripplechecked the resref. Item is usable, no inventory.

He is the primary part of the create object script I'm using.
oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "engineeredexplo", lTarget);
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Count down exploding barrel?
« Reply #6 on: June 07, 2013, 10:06:14 pm »


               Does the blueprint of the item have the script in the proper slot?
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Count down exploding barrel?
« Reply #7 on: June 07, 2013, 10:21:23 pm »


               yes. That was the first thing I thought about. The NPC creates the item just fine, but the script doen't look to run. But if I place the same object into the area, it works just fine. I've compiled the module several time. I also changed to a diff object and the same problem.
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Count down exploding barrel?
« Reply #8 on: June 07, 2013, 10:44:11 pm »


               Can you screenshot the script script on the object and paste every script relevant?  Meaning the script to spawn the object and the script in the heartbeat, if those are the only two involved?
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Count down exploding barrel?
« Reply #9 on: June 07, 2013, 10:53:28 pm »


               What the gnome puts down. OnPerceived script

void main()
{
object oPC = GetLastPerceived();
object oTarget;
object oSpawn;
location lTarget;
oTarget = oPC;


if (!GetIsPC(oPC)) return;

if (!GetLastPerceptionSeen()) return;

ClearAllActions();

ActionMoveToObject(oPC);

ActionWait(5.0f);

ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0f, 4.0f);

lTarget = GetLocation(OBJECT_SELF);

oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "engineeredexplo", lTarget);

ClearAllActions();

ActionMoveAwayFromObject(oPC);

}



exploding barrel script is the script The Amethyst Dragon posted above. Place directly into the heartbeat of the object.
               
               

               
            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Count down exploding barrel?
« Reply #10 on: June 08, 2013, 12:44:56 am »


               The script I posted before wasn't meant for a heartbeat script, it was meant to go in the script that spawns the barrel.

Here's a revised script to replace your onPerception one.  It should cause the calling NPC to try to run to the PC, 5 seconds later stop and do an animation, dropping the barrel a few seconds later.  10 seconds after it's spawned, then it explodes.  It's set to run once, but your can change that number if your NPC is meant to drop more than one barrel...in which case you'll need a way to keep him from running off to plant another while in the process of planting the first if he perceives another PC during that time.


// Use for gnome's onPerception to place 1 exploding barrel.
// - The Amethyst Dragon

void DropTheBoomer(location lTarget, object oDropper)
{
// This function lets the spawning of the barrel be delayed.
object oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "engineeredexplo", lTarget);
SetLocalObject(oDropper, "theboom", oSpawn);
}

void TenNineBoom(object oDropper)
{
object oBarrel = GetLocalObject(oDropper, "theboom");
DeleteLocalObject(oDropper, "theboom");
if (GetCurrentHitPoints(oBarrel) < 1) { return; } // Don't run if barrel is destroyed before time runs out
location lBarrel = GetLocation(oBarrel);
int nDamage;
effect eVis = EffectVisualEffect(VFX_IMP_FLAME_M);
int nDC = 14; // save DC
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_FIREBALL), lBarrel);
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_HUGE, lBarrel, TRUE);
while (oTarget != OBJECT_INVALID)
   {
   nDamage = d6(10); // generic big boom damage
   nDamage = GetReflexAdjustedDamage(nDamage, oTarget, nDC, SAVING_THROW_TYPE_FIRE, oBarrel);
   if (nDamage > 0)
      {
      ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);
      ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(nDamage, DAMAGE_TYPE_FIRE), oTarget);
      }
   oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_HUGE, lBarrel, TRUE);
   }
}

void main()
{
object oPC = GetLastPerceived();

if (!GetIsPC(oPC)) return;
if (!GetLastPerceptionSeen()) return;

if (GetLocalInt(OBJECT_SELF, "droppedtheboom") != 1)
   {
   ClearAllActions();
   ActionMoveToObject(oPC, TRUE);
   DelayCommand(5.0, ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0f, 4.0f));
   location lTarget = GetLocation(OBJECT_SELF);                   // get location to drop barrel
   DelayCommand(9.0, DropTheBoomer(lTarget, OBJECT_SELF));        // drop it like it's hot!
   DelayCommand(9.0, SetLocalInt(OBJECT_SELF, "droppedtheboom", 1)); // set to only drop 1 barrel
   DelayCommand(9.1, ClearAllActions());
   DelayCommand(9.2, ActionMoveAwayFromObject(oPC, TRUE, 20.0));  // run away! run away!
   DelayCommand(19.0, TenNineBoom(OBJECT_SELF));                  // start the timer
   }
}

               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Count down exploding barrel?
« Reply #11 on: June 08, 2013, 12:52:09 am »


               Thanks Amethyst Dragon. No doubt the greatest game community (and most likely oldest). I'm very thankful.