ZoriaRPG

InvFrames.zh (NPC iFrames)

Mar 11th, 2018
97
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //////////////////////////////////
  2. /// Enemy Invincibility Frames ///
  3. //////////////////////////////////
  4.  
  5. //Settings for Enemy Invincibility Frames
  6. const int ENEMY_INVINCIBILITY_FRAMES_DURATION = 180;
  7. const int INVINCIBLE_ENEMIES_PHANTOM = 1; //Setting to enable or disable phantoming injured enemies.
  8. const int STORE_ORIGINAL_ENEMY_PALETTE = 1; //Setting to enable storing original enemy palette or cset.
  9.  
  10. //You may enable *ONE* of these two rules, to match your quest rule settings.
  11. //! If one is enabled, the other MUST be disabled.
  12. const int ENEMIES_FLICKER_WHEN_HIT = 0; //Use the OriginalSprite, and store it instead of CSet or BPal
  13. const int ENEMIES_FLASH_WHEN_HIT = 0; //Use the CSet or BPal to make an enemy flash, when hit.
  14.  
  15. //Values For Enemy Invincibility Frames
  16.  
  17. //n->Misc Indices
  18. const int ENEM_HP_LAST = 1; //n->Mics[] holds last enemy HP. Adjusted when damaged.
  19. const int ENEM_INV_FRAMES = 2; //n->Misc[] holds the present nth frame of invincibility as a countdown timer.
  20. const int ENEM_ORIG_PAL = 3; //original CSet or Palette, or OriginalSprite
  21.  
  22. const int ENEM_BLANK_TILE = 65260; //Set to a tile at the head of a FULL PAGE of BLANK tiles.
  23. //const int ENEM_FLASH_TIMER = 4;
  24.  
  25. //Framecount for each enemy flash or flicker.
  26. const int ENEM_FLASH_1 = 180; //Will change on frame 180
  27. const int ENEM_FLASH_2 = 150; //...frame 150
  28. const int ENEM_FLASH_3 = 120;
  29. const int ENEM_FLASH_4 = 90;
  30. const int ENEM_FLASH_5 = 60;
  31. const int ENEM_FLASH_6 = 30; //...frame 30
  32.  
  33. //Cset or BPal to use when flashing
  34. const int ENEM_BPAL_FLASH = 6;
  35. const int ENEM_CSET_FLASH = 6;
  36.  
  37.  
  38. //Run before Waitdraw, and before EnemyInvincibilityFrames()
  39. void InitEnemyLastHP(){
  40.     for ( int q = 1; q <= Screen->NumNPCs(); q++ ) {
  41.         npc n = Screen->LoadNPC(q);
  42.         if (!n->Misc[ENEM_HP_LAST] && n->HP > 0) {
  43.             n->Misc[ENEM_HP_LAST] = n->HP;
  44.             if ( STORE_ORIGINAL_ENEMY_PALETTE && !n->Misc[ENEM_ORIG_PAL] ) {
  45.                 if ( n->CSet == 14 ) n->Misc[ENEM_ORIG_PAL] = n->BossPal;
  46.                 else n->Misc[ENEM_ORIG_PAL] = n->CSet;
  47.             }
  48.             if ( ENEMIES_FLICKER_WHEN_HIT && !n->Misc[ENEM_ORIG_PAL] ) {
  49.                 n->Misc[ENEM_ORIG_PAL] = n->OriginalTile;
  50.             }
  51.         }
  52.     }
  53. }
  54.  
  55. void _InitEnemyLastHP(){
  56.     for ( int q = 1; q <= Screen->NumNPCs(); q++ ) {
  57.         npc n = Screen->LoadNPC(q);
  58.         if (!n->Misc[ENEM_HP_LAST] && n->HP > 0) n->Misc[ENEM_HP_LAST] = n->HP;
  59.     }
  60. }
  61.  
  62. //Run before Waitdraw and before any collision/damage functions that need to read these values.
  63. void _EnemyInvincibilityFrames(){
  64.     for ( int q = 1; q <= Screen->NumNPCs(); q++ ) {
  65.         npc n = Screen->LoadNPC(q);
  66.         if ( n->Misc[ENEM_HP_LAST] > n->HP ) {
  67.             n->Misc[ENEM_HP_LAST] = n->HP;
  68.             n->Misc[ENEM_INV_FRAMES] = ENEMY_INVINCIBILITY_FRAMES_DURATION;
  69.         }
  70.         if ( n->Misc[ENEM_INV_FRAMES] > 0 ) n->Misc[ENEM_INV_FRAMES]--;
  71.         if ( n->Misc[ENEM_INV_FRAMES] < 0 ) n->Misc[ENEM_INV_FRAMES] = 0;
  72.     }
  73. }
  74.  
  75. //Run after InitEnemyLastHP, before Waitdraw and before any collision/damage functions that need to read these values.
  76. void EnemyInvincibilityFrames(){
  77.     for ( int q = 1; q <= Screen->NumNPCs(); q++ ) {
  78.         npc n = Screen->LoadNPC(q);
  79.         if ( n->Misc[ENEM_HP_LAST] > n->HP ) {
  80.             n->Misc[ENEM_HP_LAST] = n->HP;
  81.             n->Misc[ENEM_INV_FRAMES] = ENEMY_INVINCIBILITY_FRAMES_DURATION;
  82.         }
  83.         if ( n->Misc[ENEM_INV_FRAMES] > 0 ) n->Misc[ENEM_INV_FRAMES]--;
  84.         if ( n->Misc[ENEM_INV_FRAMES] < 0 ) n->Misc[ENEM_INV_FRAMES] = 0;
  85.        
  86.         if ( INVINCIBLE_ENEMIES_PHANTOM ) {
  87.             if ( EnemyInvincible(n) && n->DrawStyle != DS_PHANTOM ) n->DrawStyle = DS_PHANTOM;
  88.             if ( !EnemyInvincible(n) && n->DrawStyle == DS_PHANTOM
  89.                 && !GetNPCMiscFlag(n,NPCM_TRANSLUCENT) && !GetNPCMiscFlag(n,NPCM_FLICKERING)
  90.                 && !GetNPCMiscFlag(n,NPCM_FLASHING) ) n->DrawStyle = DS_NORMAL;
  91.  
  92.         }
  93.     }
  94. }
  95.  
  96.  
  97.  
  98. //Run IMMEDIATELY AFTER EnemyInvincibilityFrames() if you have flashing, or flickering settings enabled.
  99. void FlashEnemyWhenHit(npc n) {
  100.     if ( ENEMIES_FLASH_WHEN_HIT && n->Misc[ENEM_INV_FRAMES] > 0 ) {
  101.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_1 ) {
  102.             if ( n->CSet == 14 ) n->BossPal = ENEM_BPAL_FLASH;
  103.             else n->CSet = ENEM_CSET_FLASH;
  104.         }
  105.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_2 ) {
  106.             if ( n->CSet == 14 ) n->BossPal = n->Misc[ENEM_ORIG_PAL];
  107.             else n->CSet = n->Misc[ENEM_ORIG_PAL];
  108.         }
  109.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_3 ) {
  110.             if ( n->CSet == 14 ) n->BossPal = ENEM_BPAL_FLASH;
  111.             else n->CSet = ENEM_CSET_FLASH;
  112.         }
  113.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_4 ) {
  114.             if ( n->CSet == 14 ) n->BossPal = n->Misc[ENEM_ORIG_PAL];
  115.             else n->CSet = n->Misc[ENEM_ORIG_PAL];
  116.         }
  117.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_5 ) {
  118.             if ( n->CSet == 14 ) n->BossPal = ENEM_BPAL_FLASH;
  119.             else n->CSet = ENEM_CSET_FLASH;
  120.         }
  121.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_6 ) {
  122.             if ( n->CSet == 14 ) n->BossPal = n->Misc[ENEM_ORIG_PAL];
  123.             else n->CSet = n->Misc[ENEM_ORIG_PAL];
  124.         }
  125.     }
  126.     if ( ENEMIES_FLICKER_WHEN_HIT && n->Misc[ENEM_INV_FRAMES] > 0 ) {
  127.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_1 ) {
  128.             n->OriginalTile = ENEM_BLANK_TILE;
  129.         }
  130.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_2 ) {
  131.             n->OriginalTIle = n->Misc[ENEM_ORIG_PAL];
  132.         }
  133.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_3 ) {
  134.             n->OriginalTile = ENEM_BLANK_TILE;
  135.         }
  136.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_4 ) {
  137.             n->OriginalTIle = n->Misc[ENEM_ORIG_PAL];
  138.         }
  139.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_5 ) {
  140.             n->OriginalTile = ENEM_BLANK_TILE;
  141.         }
  142.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_6 ) {
  143.             n->OriginalTIle = n->Misc[ENEM_ORIG_PAL];
  144.         }
  145.     }
  146. }
  147.  
  148. //Returns if an enemy is invincible.
  149. int EnemyInvincible(npc n){
  150.     return n->Misc[ENEM_INV_FRAMES];
  151. }
  152.  
  153. //Immediately sets, or resets enemy invincibility to on.
  154. void SetEnemyInvincible(npc n) {
  155.     n->Misc[ENEM_INV_FRAMES] = ENEMY_INVINCIBILITY_FRAMES_DURATION;
  156. }
  157.  
  158. //Immediately disables mock enemy invincibility.
  159. void SetEnemyNotInvincible(npc n) {
  160.     n->Misc[ENEM_INV_FRAMES] = 0;
  161. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×