Advertisement
ZoriaRPG

NPC Steal Items on Collision

Dec 30th, 2019
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. npc script stealitems
  2. {
  3.     void run(int min, int max, int counterA, int counterB, int counterC, int counterD, int sfx)
  4.     {
  5.         min = ( min > -1 ) ? min : 0;
  6.         max = ( max > 0 ) ? max : 1;
  7.         int num = Rand(min,max);
  8.         int counters[4] = { counterA, counterB, counterC, counterD };
  9.         int sel = counters[Rand(4)];
  10.         while(1)
  11.         {
  12.             if ( sel ) //don't affect counter 0 (life)
  13.             {
  14.                 if ( Collision(this) && (Hero->HitDir > -1) )
  15.                 {
  16.                     Audio->PlaySound(sfx);
  17.                     //Don't roll over.
  18.                     if ( (Game->Counter[sel] - num) >= 0 ) Game->Counter[sel] -= num;
  19.                     else
  20.                     {
  21.                         Game->Counter[sel] = ( num > 0 ) ? 0 : Game->Counter[sel];
  22.                     }
  23.                     while(Hero->HitDir > -1) { Waitframe(); } //Don't steal again unless Link is hit again.
  24.                 }
  25.             }
  26.             num = Rand(min,max);
  27.             sel = counters[Rand(4)];
  28.             Waitframe();
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement