Advertisement
ZoriaRPG

Hate Spell Item (Bane Weapon) v0.2

Sep 5th, 2019
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.73 KB | None | 0 0
  1. //Hate Spell, v0.2; 5th August, 2019; ZoriaRPG
  2. //Spell Item to increase weapon power of a specific itemclass while the item is active.
  3. //D0: A sound to play as an error...
  4. //D1: The item class to use. Defaults to IC_SWORD.
  5. //D2: Damage Multiplier
  6.  
  7. //Item Editor Fields
  8. // Cost Counter: The counter to check.
  9. // Cost: The cost to apply per revolution.
  10. // Timer: The number of frames to wait before checking the cost.
  11.  
  12. item script hatespell
  13. {  
  14.     bool isRunning = false; //script-global
  15.     //Did I build item script spam prevention into the engine, so that a player can't cause an item already
  16.     //running a script to restart the script with a second use of that item while the first
  17.     //instance is still running?
  18.     void run(int errSfx, int affectedItemClass, float power_multiplier)
  19.     {
  20.         int f;
  21.         bool quit_by_button_press;
  22.         affectedItemClass = ( affectedItemClass > 0 ) affectedItemClass : IC_SWORD;
  23.         power_multiplier = ( power_multiplier > 0 ) power_multiplier : 1.5000;
  24.         int tempitmpower[256];
  25.        
  26.         if ( isRunning ) //need to kill it early, don't run twice
  27.         {
  28.             Audio->PlaySound(this->UseSound); //Play the use sound again, when deactivating.
  29.             for ( int q = 0; q < 256; ++q )
  30.             {
  31.                 itemdata theItem = Game->LoadItemData(q);
  32.                 if ( theItem->Class == affectedItemClass )
  33.                 {
  34.                     if ( tempitmpower[q] )
  35.                     {
  36.                         theItem->Power = tempitmpower[q]-1;
  37.                     }
  38.                 }
  39.             }  
  40.             isRunning = false;
  41.             Quit();
  42.         }
  43.        
  44.         if ( Game->Counter[this->CostCounter] < this->Cost )
  45.         {
  46.             Audio->PlaySound(errSfx); Quit(); //If we can't pay the cost, quit.
  47.         }
  48.         else
  49.         {
  50.             isRunning = true; //mark as active so that we can't spam it.
  51.         }
  52.        
  53.         for ( int q = 0; q < 256; ++q )
  54.         {
  55.             itemdata theItem = Game->LoadItemData(q);
  56.             if ( theItem->Class == affectedItemClass )
  57.             {
  58.                 tempitmpower[q] = theItem->Power+1;
  59.                 theItem->Power *= power_multiplier;
  60.             }
  61.         }
  62.         while(1)
  63.         {
  64.             ++f;
  65.             if ( f < 0 ) f = 1; //fix underflows
  66.             if ( (!(f%this->CostTimer)) ) //every n frames, apply the cost
  67.             {
  68.                 if((Game->Counter[this->CostCounter] -= this->Cost) > 0)
  69.                 {
  70.                     Waitframe();
  71.                 }
  72.                 else break;
  73.             }
  74.             if (( Hero->PressA && Hero->ItemA == this->ID ) ||( Hero->PressB && Hero->ItemB == this->ID ) || quit_by_button_press )
  75.             {
  76.                 break; ///Using the item again, ends its effect.
  77.             }
  78.             Waitframe();
  79.         }
  80.        
  81.         Audio->PlaySound(this->UseSound); //Play the use sound again, when deactivating.
  82.         //Restore original item Power values, as the effect has ended.
  83.         for ( int q = 0; q < 256; ++q )
  84.         {
  85.             itemdata theItem = Game->LoadItemData(q);
  86.             if ( theItem->Class == affectedItemClass )
  87.             {
  88.                 if ( tempitmpower[q] )
  89.                 {
  90.                     theItem->Power = tempitmpower[q]-1;
  91.                 }
  92.             }
  93.         }  
  94.         Quit();
  95.     }
  96.        
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement