Advertisement
ZoriaRPG

ZScript: Vulcan Explosion Requested by Cedric

May 21st, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.54 KB | None | 0 0
  1. ///////////////////////////
  2. /// Vulcan FFC          ///
  3. /// By: ZoriaRPG        ///
  4. /// Requested by Cedric ///
  5. /// 21st May, 2017      ///
  6. /// v0.5                ///
  7. ///////////////////////////////////////////////////////////////////////////////////////////
  8. /// D0: Sprite of the fireball from Quest->Graphics->Sprites->Weapons/Misc
  9. /// D1: Damage of projectiles
  10. /// D3:Time in seconds beforwe fireballs land. Defaults to 1.75 seconds.
  11. /// D4: Time in frames before the eruption begins, randomised by +/- 80 frames.
  12. /// D5: Sound of rumbling
  13. /// D6: Sound of eruption
  14. /// D7: Time before we can erupt again.
  15.  
  16. ffc script erupt{
  17.     void run(int fireball_sprite, int damage, float falltime, float erupt_time, int rumble_sfx, int erupt_sfx, float time_return){
  18.         eweapon e[10]; //The eight fireballs, and generic indices for looping.
  19.         int q[10];      //[0]: Q loop,
  20.                 //[1]: Radians counter,
  21.                 //[2]: ffmarker,
  22.                 //[3]: Exploding
  23.                 //[4]: Remaining fireballs on-screen
  24.                 //[5]: Used for positive Angle variation
  25.                 //[6]: Used for negative Angle variation
  26.                 //[7]: Unused,
  27.                 //[8]: Unused,
  28.                 //[9]: Unused
  29.         int timers[4];  //[0]: Eruption Timer,
  30.                 //[1]: Frame at which rumbling begins.
  31.                 //[2]: time before second eruption, randomised.,
  32.                 //[3]: Unused,
  33.  
  34.         //Do initial var set-up.
  35.         if ( falltime <= 0 ) { falltime = 1.75; } //Sanity
  36.         if ( erupt_time <= 0 ) { erupt_time = 300; }
  37.         else { erupt_time = erupt_time * 60; } //Turn seconds into frames.
  38.         timer[0] = Abs(erupt_time + Rand(-80,80)); timer[1] = Rand(30,90); //A slightly randomised eruption rate.
  39.  
  40.         //Determine the UID to bind a fireball to its parent ffc.
  41.         q[2] = ComboAt(this->X, this->Y) + 1; //A way of determining which ffc made the fireballs.
  42.         //If you place more then one ffc over the same location, this will BREAK.
  43.        
  44.         //If we want to erupt more than one time, then set the value.
  45.         if ( time_return > 0 ) { time_return *= 60; timer[2] = Abs(time_return + Rand(-80,80)); }
  46.        
  47.         while(true){
  48.             //Wait to erupt.
  49.             while ( timer[0]-- > 0 ) {
  50.                 if ( timer[0] == timer[1] ) {
  51.                     //One second before the eruption...
  52.                     ///Rumble sound
  53.                     if ( rumble_sfx > 0 ) Game->PlaySound(rumble_sfx);
  54.                     //Shake screen
  55.                     Screen->Quake = timer[1]; //A slightly randomised eruption rate.
  56.                     q[3] = 1;
  57.                 }
  58.                 Waitframe();
  59.             }
  60.            
  61.             //Animate eruption at this ffc.
  62.             if ( q[3] == 1 ) { //We are exploding )
  63.                 //Make the eruption sound.
  64.                 if ( erupt_sfx > 0 ) Game->PlaySound(erupt_sfx);
  65.                
  66.                 //Spew eweapons
  67.                 for ( q[0] = 0; q [0] < 8l q[0]++ ) {
  68.                     e[q] = Screen->CreateEWeapon(EW_SCRIPT);
  69.                     e[q]->UseSprite = fireballsprite;
  70.                     e[q]->Power = Damage;
  71.                     e[q]->Angular = true;
  72.                     e[q]->Angle = q[1]; //This angle will be varied a bit as they fall.
  73.                     e->Misc[15] = q[2]; //The UID that links them to this specific ffc, because this->ID is not implemented in 2.50.x.
  74.                     q[1] += 0.25; //Adust the radians.
  75.                     e->Z = falltime * 60; //Give them an initial Z. Do they have shadows?
  76.                 }
  77.                 q[3] = 0; //Mark that we are done exploding.
  78.             }
  79.            
  80.             //Now that the volcane has exploded,
  81.             q[4] = 0; //Clear this counter for use.
  82.            
  83.             //Find all fireballs made by this script, and track them
  84.             for ( q[0] = Screen->NumEWeapons(); q[0] > 0; q[0]-- ) {
  85.                 e[8] = Screen->LoadEWeapon(q[0]);
  86.                 if ( e[8]->Misc[15] != q[2] ) { continue; } //Ignore weapons without the same UID as we created with this ffc.
  87.                
  88.                 q[4]++; //Track how many fireballs remain.
  89.                 q[5] = 0.0050; q[6] = -0.0050;
  90.                 e[8]->Angle += Choose(q[5], q[6]); // Vary the angle a bit.
  91.                
  92.                 //If it is still falling, let it fall.
  93.                 if ( e[8]->Z > 0 ) { e[8]->Z--; } //Decrement its Z
  94.                
  95.                 //if it hits the ground, make it explode.
  96.                 if ( e[8]->Z <= 0 ) {
  97.                     e[8]->ID = EW_BOMBBLAST;
  98.                 }
  99.             }
  100.            
  101.             //If we have set to explode again...
  102.             if ( timer[2] > 0 ) {
  103.                 if ( timer[2] > 1 ) { timer[2]--; } //Decrement the delay timer until it strikes 1.  
  104.                 if ( timer[2] <= 1 ) {  //When it strikes '1':
  105.                     if ( q[4] <= 0 ) { //If no fireballs remain from the last burst.
  106.                     ///new explosion
  107.                         //Reset the original timer, and start fresh.
  108.                         timer[0] = Abs(erupt_time + Rand(-80,80)); timer[1] = Rand(30,90); //A slightly randomised eruption rate.
  109.                     }
  110.                     //If fireballs remain, we will continue to check every frame as the timer will not continue to decrement.
  111.                 }
  112.             }
  113.            
  114.             //if ( time_return <= 0 && q[4] == 0 ) Quit(); //Do we want to exit?
  115.             Waitframe();
  116.         }
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement