Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Hate Spell, v0.2; 5th August, 2019; ZoriaRPG
- //Spell Item to increase weapon power of a specific itemclass while the item is active.
- //D0: A sound to play as an error...
- //D1: The item class to use. Defaults to IC_SWORD.
- //D2: Damage Multiplier
- //Item Editor Fields
- // Cost Counter: The counter to check.
- // Cost: The cost to apply per revolution.
- // Timer: The number of frames to wait before checking the cost.
- item script hatespell
- {
- bool isRunning = false; //script-global
- //Did I build item script spam prevention into the engine, so that a player can't cause an item already
- //running a script to restart the script with a second use of that item while the first
- //instance is still running?
- void run(int errSfx, int affectedItemClass, float power_multiplier)
- {
- int f;
- bool quit_by_button_press;
- affectedItemClass = ( affectedItemClass > 0 ) affectedItemClass : IC_SWORD;
- power_multiplier = ( power_multiplier > 0 ) power_multiplier : 1.5000;
- int tempitmpower[256];
- if ( isRunning ) //need to kill it early, don't run twice
- {
- Audio->PlaySound(this->UseSound); //Play the use sound again, when deactivating.
- for ( int q = 0; q < 256; ++q )
- {
- itemdata theItem = Game->LoadItemData(q);
- if ( theItem->Class == affectedItemClass )
- {
- if ( tempitmpower[q] )
- {
- theItem->Power = tempitmpower[q]-1;
- }
- }
- }
- isRunning = false;
- Quit();
- }
- if ( Game->Counter[this->CostCounter] < this->Cost )
- {
- Audio->PlaySound(errSfx); Quit(); //If we can't pay the cost, quit.
- }
- else
- {
- isRunning = true; //mark as active so that we can't spam it.
- }
- for ( int q = 0; q < 256; ++q )
- {
- itemdata theItem = Game->LoadItemData(q);
- if ( theItem->Class == affectedItemClass )
- {
- tempitmpower[q] = theItem->Power+1;
- theItem->Power *= power_multiplier;
- }
- }
- while(1)
- {
- ++f;
- if ( f < 0 ) f = 1; //fix underflows
- if ( (!(f%this->CostTimer)) ) //every n frames, apply the cost
- {
- if((Game->Counter[this->CostCounter] -= this->Cost) > 0)
- {
- Waitframe();
- }
- else break;
- }
- if (( Hero->PressA && Hero->ItemA == this->ID ) ||( Hero->PressB && Hero->ItemB == this->ID ) || quit_by_button_press )
- {
- break; ///Using the item again, ends its effect.
- }
- Waitframe();
- }
- Audio->PlaySound(this->UseSound); //Play the use sound again, when deactivating.
- //Restore original item Power values, as the effect has ended.
- for ( int q = 0; q < 256; ++q )
- {
- itemdata theItem = Game->LoadItemData(q);
- if ( theItem->Class == affectedItemClass )
- {
- if ( tempitmpower[q] )
- {
- theItem->Power = tempitmpower[q]-1;
- }
- }
- }
- Quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement