Advertisement
ZoriaRPG

HP Change Display, v0.5

Aug 18th, 2020
1,527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.28 KB | None | 0 0
  1. ///////////////////////////
  2. // RPG-esque HP Display  //
  3. // v0.5                  //
  4. // 18th August, 2020     //
  5. // For ZC 2.55 Alpha 80+ //
  6. // By: ZoriaRPG          //
  7. ///////////////////////////
  8.  
  9. namespace hphealth
  10. {
  11.     enum colourtype { cNONE, cWHITE, cGREY, cBLUE, cRED = 0xE1 };
  12.    
  13.     const int OLDHP_INDX = 19;
  14.     const int OLDHP_DIFF = 20;
  15.     const int SPAWN_CLK = 21;
  16.     const int DRAW_CLK = 22;
  17.     const int INITIALISED = 23;
  18.     const int SPAWNCLKDUR = 60;
  19.     const int HPCLOCKDUR = 40;
  20.  
  21.     const int DMG_COLOUR = cRED;
  22.     const int DMG_OUTLINE = cWHITE;
  23.     const int HEAL_OUTLINE = cWHITE;
  24.     const int HEAL_COLOUR = cBLUE;
  25.  
  26.     const int DRAW_LAYER = 6;
  27.     const int XOFS = -4;
  28.     const int YOFS = -4;
  29.  
  30.     global script test
  31.     {
  32.         void run()
  33.         {
  34.             while(1)
  35.             {
  36.                 for ( int q = Screen->NumNPCs(); q > 0; --q )
  37.                 {
  38.                     npc n = Screen->LoadNPC(q);
  39.                     init_enemy_hp(n);
  40.                     do_npc_hp_clock(n);
  41.                     update_npc_hp(n);
  42.                     draw_npc_hp_change(n);
  43.                 }
  44.                 init_hero_hp();
  45.                 do_hero_hp_clock();
  46.                 update_hero_hp();
  47.                 draw_hero_hp_change();
  48.                 Waitdraw();
  49.                 Waitframe();
  50.             }
  51.         }
  52.     }
  53.  
  54.  
  55.     void do_npc_hp_clock(npc n)
  56.     {
  57.         ++n->Misc[SPAWN_CLK];
  58.     }
  59.  
  60.     void init_enemy_hp(npc n)
  61.     {
  62.         unless ( n->Misc[INITIALISED] )
  63.         {
  64.             n->Misc[OLDHP_INDX] = n->HP;
  65.             n->Misc[INITIALISED] = 1;
  66.         }
  67.     }
  68.     void update_npc_hp(npc n)
  69.     {
  70.        
  71.         {
  72.             if ( n->Family != NPCT_GLEEOK && n->Misc[DRAW_CLK] == 0 && (n->HitBy[2] || n->Family == NPCT_MOLDORM ) && n->HP != n->Misc[OLDHP_INDX] )
  73.             {
  74.                
  75.                 n->Misc[OLDHP_DIFF] = n->HP - n->Misc[OLDHP_INDX];
  76.                 n->Misc[DRAW_CLK] = HPCLOCKDUR;
  77.                
  78.             }
  79.             else if ( (n->Family == NPCT_GLEEOK && n->Core) && n->HP != n->Misc[OLDHP_INDX] && n->Misc[DRAW_CLK] == 0 )
  80.             {
  81.                 n->Misc[OLDHP_DIFF] = n->HP - n->Misc[OLDHP_INDX];
  82.                 n->Misc[DRAW_CLK] = HPCLOCKDUR;
  83.             }
  84.  
  85.             else if ( n->Family == NPCT_LANMOLA && n->HP != n->Misc[OLDHP_INDX] && n->Misc[DRAW_CLK] == 0 )
  86.             {
  87.                 npcdata nd = Game->LoadNPCData(n->ID);
  88.                 int orighp = (nd->HP -1) * -1;
  89.                 //printf("hp: %d\n", orighp);
  90.                 int tmpdif = n->HP - n->Misc[OLDHP_INDX];
  91.                 if ( tmpdif == orighp && n->Misc[SPAWN_CLK] < 60 )
  92.                 {
  93.                     n->Misc[OLDHP_INDX] = n->HP;
  94.                     return;
  95.                 }
  96.                 else
  97.                 {
  98.                     n->Misc[OLDHP_DIFF] = n->HP - n->Misc[OLDHP_INDX];
  99.                     n->Misc[DRAW_CLK] = HPCLOCKDUR;
  100.                 }
  101.             }
  102.         }
  103.        
  104.     }
  105.  
  106.     void draw_npc_hp_change(npc n)
  107.     {
  108.         if (  n->Misc[SPAWN_CLK] < SPAWNCLKDUR ) return;
  109.         if ( n->Family == NPCT_LANMOLA && n->Misc[OLDHP_DIFF] > 0 ) return; //Lanmolas juggle HP so don't show imbalances being offset.
  110.         if ( --n->Misc[DRAW_CLK] > 0 && n->Misc[OLDHP_DIFF] )
  111.         {
  112.             int buffer[8];
  113.             int buffer2[8];
  114.             itoa(buffer,n->Misc[OLDHP_DIFF]);
  115.             if ( n->Misc[OLDHP_DIFF] > 0 )
  116.             {
  117.                 buffer2[0] = '+';
  118.             }
  119.             strcat(buffer2, buffer);
  120.            
  121.             Screen->DrawString
  122.             (
  123.                 DRAW_LAYER,
  124.                 n->X + XOFS,
  125.                 n->Y + YOFS,
  126.                 FONT_Z3SMALL,
  127.                 ((n->Misc[OLDHP_DIFF]<0) ? DMG_COLOUR : HEAL_COLOUR),
  128.                 -1,
  129.                 0,
  130.                 buffer2,
  131.                 128,
  132.                 SHD_OUTLINED8,
  133.                 ((n->Misc[OLDHP_DIFF]<0) ? DMG_OUTLINE : HEAL_OUTLINE)
  134.             );
  135.                
  136.            
  137.         }
  138.         else
  139.         {
  140.             n->Misc[DRAW_CLK] = 0;
  141.             n->Misc[OLDHP_INDX] = n->HP;
  142.         }
  143.     }
  144.     void do_hero_hp_clock()
  145.     {
  146.         ++Hero->Misc[SPAWN_CLK];
  147.     }
  148.  
  149.     void init_hero_hp()
  150.     {
  151.         unless ( Hero->Misc[INITIALISED] )
  152.         {
  153.             Hero->Misc[OLDHP_INDX] = Hero->HP;
  154.             Hero->Misc[INITIALISED] = 1;
  155.         }
  156.     }
  157.     void update_hero_hp()
  158.     {
  159.        
  160.         if ( Hero->Misc[DRAW_CLK] == 0 && Hero->HP != Hero->Misc[OLDHP_INDX] )
  161.         {
  162.             Hero->Misc[OLDHP_DIFF] = Hero->HP - Hero->Misc[OLDHP_INDX];
  163.             Hero->Misc[DRAW_CLK] = HPCLOCKDUR;
  164.         }
  165.     }
  166.  
  167.  
  168.  
  169.     void draw_hero_hp_change()
  170.     {
  171.         if ( --Hero->Misc[DRAW_CLK] > 0 && Hero->Misc[OLDHP_DIFF] )
  172.         {
  173.            
  174.             int buffer[8];
  175.             int buffer2[8];
  176.            
  177.             itoa(buffer,Hero->Misc[OLDHP_DIFF]);
  178.             if ( Hero->Misc[OLDHP_DIFF] > 0 )
  179.             {
  180.                 buffer2[0] = '+';
  181.             }
  182.             strcat(buffer2, buffer);
  183.            
  184.             Screen->DrawString
  185.             (
  186.                 DRAW_LAYER,
  187.                 Hero->X + XOFS,
  188.                 Hero->Y + YOFS,
  189.                 FONT_Z3SMALL,
  190.                 ((Hero->Misc[OLDHP_DIFF]<0) ? DMG_COLOUR : HEAL_COLOUR),
  191.                 -1,
  192.                 0,
  193.                 buffer2,
  194.                 128,
  195.                 SHD_OUTLINED8,
  196.                 ((Hero->Misc[OLDHP_DIFF]<0) ? DMG_OUTLINE : HEAL_OUTLINE)
  197.             );
  198.         }
  199.         else
  200.         {
  201.             Hero->Misc[DRAW_CLK] = 0;
  202.             Hero->Misc[OLDHP_INDX] = Hero->HP;
  203.         }
  204.     }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement