ZoriaRPG

Spawn Weapon on Weapon Death v0.2

Mar 19th, 2019
138
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Spawn A Weapon on the Death of Another Weapon
  2. //'Replace on Death'
  3. //By ZoriaRPG
  4. //19th March, 2019
  5.  
  6. //v0.1 : Initial
  7. //v0.2 : Fixed compile. Fixed weapon orientations.
  8.  
  9.  
  10. lweapon script ReplaceOnDeath
  11. {
  12.     void run(int newWeaponType, int requireItem, int requireCounter, int CounterAmount, bool flipOnDeath, bool newDirOnDeath, int newDir, int newScript) //could be flags here
  13.     {
  14.        
  15.         itemdata bomb; bool found; bool super; int x; int y; int pow;
  16.         if ( requireItem > 0 )
  17.         {
  18.             bomb = Game->LoadItemData(Link->ItemA);
  19.             if ( bomb->ID == requireItem ) found = true;
  20.             if ( !found )
  21.             {
  22.                 bomb = Game->LoadItemData(Link->ItemB);
  23.                 if ( bomb->Family == IC_BOMB ) { found = true; }
  24.             }
  25.             if ( !found ) Quit(); //quit if bombs not in a slot
  26.         }
  27.        
  28.         pow = bomb->Power;
  29.         if ( requireCounter )
  30.         {
  31.             if ( Game->Counter[requireCounter] < CounterAmount ) Quit(); //quit if not enough bombs
  32.                 else Game->Counter[requireCounter] -=CounterAmount;
  33.         }
  34.        
  35.        
  36.         while(this->isValid())
  37.         {
  38.             x = this->X; y = this->Y;
  39.            
  40.             if ( this->DeadState != WDS_ALIVE ) //When the arrow itself dies, make an explosion.
  41.             {
  42.                 lweapon boom = Screen->CreateLWeapon(newWeaponType);
  43.                 boom->Damage = pow;
  44.                 boom->X = x;
  45.                 boom->Y = y;
  46.                 boom->Step = this->Step;
  47.                 boom->Dir = this->Dir;
  48.                 if ( flipOnDeath ) { boom->Dir = reversedirection(this->Dir); boom->Flip = AdjustFlip(this); } //ReflectWeapon(boom, this->Angular);
  49.                 else if ( newDirOnDeath ) { boom->Dir = newDir; boom->Flip = AdjustFlip(this); }
  50.                 boom->Damage = this->Damage; //need a new damage attribute; reduce param count to accomplish this
  51.                 if ( Abs(newScript) < 511 ) boom->Script = newScript;
  52.                 Quit(); //Spawn only one weapon.
  53.             }
  54.            
  55.             Waitframe();
  56.         }
  57.        
  58.     }
  59.     //Returns the reverse f any of the eight cardinal directions.
  60.     int reversedirection(int dir)
  61.     {
  62.         switch(dir)
  63.         {
  64.             case DIR_UP: return DIR_DOWN; break;
  65.             case DIR_DOWN: return DIR_UP; break;
  66.             case DIR_LEFT: return DIR_RIGHT; break;
  67.             case DIR_RIGHT: return DIR_LEFT; break;
  68.         }
  69.         //if ( dir == DIR_LEFT) return DIR_RIGHT;
  70.         //if ( dir == DIR_DOWN) return DIR_UP;
  71.         //if ( dir == DIR_UP) return DIR_DOWN;
  72.         //if ( dir == DIR_RIGHT) return DIR_LEFT;
  73.         ///if ( dir == DIR_LEFTUP) return DIR_RIGHTDOWN;
  74.         //if ( dir == DIR_RIGHTDOWN) return DIR_LEFTUP;
  75.         //if ( dir == DIR_LEFTDOWN) return DIR_RIGHTUP;
  76.         //if ( dir == DIR_RIGHTUP) return DIR_LEFTDOWN;
  77.     }
  78.     /*
  79.     int FlipRev(lweapon l){
  80.         if ( l->Dir == DIR_DOWN || l->Dir == DIR_UP && !l->Flip ) return 2;
  81.         if ( l->Dir == DIR_DOWN || l->Dir == DIR_UP && l->Flip ) return 0;
  82.         if ( l->Dir == DIR_LEFT || l->Dir == DIR_RIGHT && !l->Flip ) return 1;
  83.         if ( l->Dir == DIR_LEFT || l->Dir == DIR_RIGHT && l->Flip ) return 0;
  84.         return -1;
  85.     }
  86.     */
  87.     int AdjustFlip(lweapon l)
  88.     {
  89.         switch(l->Dir)
  90.         {
  91.             case DIR_DOWN: return 0; break;
  92.             case DIR_UP: return 2; break;
  93.             case DIR_LEFT: return 4; break;
  94.             case DIR_RIGHT: return 7; break;
  95.         }
  96.     }
  97.     lweapon ReflectWeapon(lweapon l, bool angular)
  98.     {
  99.         l->Dir = reversedirection(l->Dir);
  100.         //l->Flip = FlipRev(l);
  101.         l->Angular = angular;
  102.         if ( angular )
  103.         {
  104.             if (l->Angle >= 180 ) l->Angle -= 180;
  105.             else l->Angle += 180;
  106.         }
  107.     }
  108. }
RAW Paste Data