Advertisement
ZoriaRPG

Spawn Weapon on Weapon Death

Mar 19th, 2019
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. //Bomb Arrow Script for 2.55
  2. //v0.2
  3. //By ZoriaRPG
  4. //19th March, 2019
  5.  
  6. //v0.1 : Initial
  7. //v0.2 : Fix comppile, and fix how we check if the arrow is dead to create the explosion.
  8. //     : We cannot run the explosion after while(this->isValid()), because the script runs out of scope if the
  9. //     : sprite is no longer on the screen. Thus, we check its deadstate, while it is valid.
  10.  
  11. lweapon script ReplaceOnDeath
  12. {
  13.     void run(int newWeaponType, int requireItem, int requireCounter, int CounterAmount, bool flipOnDeath, bool newDirOnDeath, int newDir, int newScript) //could be flags here
  14.     {
  15.        
  16.         itemdata bomb; bool found; bool super; int x; int y; int pow;
  17.         if ( requireItem > 0 )
  18.         {
  19.             bomb = Game->LoadItemData(Link->ItemA);
  20.             if ( bomb->ID == requireItem ) found = true;
  21.             if ( !found )
  22.             {
  23.                 bomb = Game->LoadItemData(Link->ItemB);
  24.                 if ( bomb->Family == IC_BOMB ) { found = true; }
  25.             }
  26.             if ( !found ) Quit(); //quit if bombs not in a slot
  27.         }
  28.        
  29.         pow = bomb->Power;
  30.         if ( requireCounter )
  31.         {
  32.             if ( !Game->Counter[requireCounter] < CounterAmount ) Quit(); //quit if not enough bombs
  33.                 else Game->Counter[requireCounter] -=CounterAmount;
  34.         }
  35.        
  36.        
  37.         while(this->isValid())
  38.         {
  39.             x = this->X; y = this->Y;
  40.            
  41.             if ( this->DeadState != WDS_ALIVE ) //When the arrow itself dies, make an explosion.
  42.             {
  43.                 lweapon boom = Screen->CreateLWeapon(newWeaponType);
  44.                 boom->Damage = pow;
  45.                 boom->X = x;
  46.                 boom->Y = y;
  47.                 if ( flipOnDeath ) ReflectWeapon(boom, this->Angular);
  48.                 else if ( newDirOnDeath ) { boom->Dir = newDir; boom->Flip = FlipRev(boom); }
  49.                
  50.                 if ( Abs(newScript) < 511 ) boom->Script = newScript;
  51.             }
  52.            
  53.             Waitframe();
  54.         }
  55.        
  56.     }
  57.    
  58.     int FlipRev(lweapon l){
  59.         if ( l->Dir == DIR_DOWN || l->Dir == DIR_UP && !l->Flip ) return 2;
  60.         if ( l->Dir == DIR_DOWN || l->Dir == DIR_UP && l->Flip ) return 0;
  61.         if ( l->Dir == DIR_LEFT || l->Dir == DIR_RIGHT && !l->Flip ) return 1;
  62.         if ( l->Dir == DIR_LEFT || l->Dir == DIR_RIGHT && l->Flip ) return 0;
  63.         return -1;
  64.     }
  65.     lweapon ReflectWeapon(lweapon l, bool angular)
  66.     {
  67.         l->Dir = DirRev(l->Dir);
  68.         l->Flip = FlipRev(l);
  69.         l->Angular = angular;
  70.         if ( angular )
  71.         {
  72.             if (l->Angle >= 180 ) l->Angle -= 180;
  73.             else l->Angle += 180;
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement