Advertisement
ZoriaRPG

HP Change Display, v0.3

Aug 18th, 2020
1,537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.65 KB | None | 0 0
  1.  ///////////////////////////
  2. // RPG-esque HP Display  //
  3. // v0.3                  //
  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.         if ( n->Family == NPCT_LANMOLA )
  71.         {
  72.             if ( n->HitBy[2] )
  73.             {
  74.                 printf("Lanmola hit.\n");
  75.             }
  76.            
  77.            
  78.            
  79.         }
  80.         else
  81.         {
  82.             if ( n->Misc[DRAW_CLK] == 0 && (n->HitBy[2] || n->Family == NPCT_MOLDORM || n->Family == NPCT_GLEEOK) && n->HP != n->Misc[OLDHP_INDX] )
  83.             {
  84.                 if ( (n->Family == NPCT_GLEEOK && n->Core) || !n->Family == NPCT_GLEEOK )
  85.                 {
  86.                     n->Misc[OLDHP_DIFF] = n->HP - n->Misc[OLDHP_INDX];
  87.                     n->Misc[DRAW_CLK] = HPCLOCKDUR;
  88.                 }
  89.             }
  90.         }
  91.        
  92.     }
  93.  
  94.     void draw_npc_hp_change(npc n)
  95.     {
  96.         if (  n->Misc[SPAWN_CLK] < SPAWNCLKDUR ) return;
  97.         if ( --n->Misc[DRAW_CLK] > 0 && n->Misc[OLDHP_DIFF] )
  98.         {
  99.             int buffer[8];
  100.             int buffer2[8];
  101.             itoa(buffer,n->Misc[OLDHP_DIFF]);
  102.             if ( n->Misc[OLDHP_DIFF] > 0 )
  103.             {
  104.                 buffer2[0] = '+';
  105.             }
  106.             strcat(buffer2, buffer);
  107.            
  108.             Screen->DrawString
  109.             (
  110.                 DRAW_LAYER,
  111.                 n->X + XOFS,
  112.                 n->Y + YOFS,
  113.                 FONT_Z3SMALL,
  114.                 ((n->Misc[OLDHP_DIFF]<0) ? DMG_COLOUR : HEAL_COLOUR),
  115.                 -1,
  116.                 0,
  117.                 buffer2,
  118.                 128,
  119.                 SHD_OUTLINED8,
  120.                 ((n->Misc[OLDHP_DIFF]<0) ? DMG_OUTLINE : HEAL_OUTLINE)
  121.             );
  122.                
  123.            
  124.         }
  125.         else
  126.         {
  127.             n->Misc[DRAW_CLK] = 0;
  128.             n->Misc[OLDHP_INDX] = n->HP;
  129.         }
  130.     }
  131.     void do_hero_hp_clock()
  132.     {
  133.         ++Hero->Misc[SPAWN_CLK];
  134.     }
  135.  
  136.     void init_hero_hp()
  137.     {
  138.         unless ( Hero->Misc[INITIALISED] )
  139.         {
  140.             Hero->Misc[OLDHP_INDX] = Hero->HP;
  141.             Hero->Misc[INITIALISED] = 1;
  142.         }
  143.     }
  144.     void update_hero_hp()
  145.     {
  146.        
  147.         if ( Hero->Misc[DRAW_CLK] == 0 && Hero->HP != Hero->Misc[OLDHP_INDX] )
  148.         {
  149.             Hero->Misc[OLDHP_DIFF] = Hero->HP - Hero->Misc[OLDHP_INDX];
  150.             Hero->Misc[DRAW_CLK] = HPCLOCKDUR;
  151.         }
  152.     }
  153.  
  154.  
  155.  
  156.     void draw_hero_hp_change()
  157.     {
  158.         if ( --Hero->Misc[DRAW_CLK] > 0 && Hero->Misc[OLDHP_DIFF] )
  159.         {
  160.            
  161.             int buffer[8];
  162.             int buffer2[8];
  163.            
  164.             itoa(buffer,Hero->Misc[OLDHP_DIFF]);
  165.             if ( Hero->Misc[OLDHP_DIFF] > 0 )
  166.             {
  167.                 buffer2[0] = '+';
  168.             }
  169.             strcat(buffer2, buffer);
  170.            
  171.             Screen->DrawString
  172.             (
  173.                 DRAW_LAYER,
  174.                 Hero->X + XOFS,
  175.                 Hero->Y + YOFS,
  176.                 FONT_Z3SMALL,
  177.                 ((Hero->Misc[OLDHP_DIFF]<0) ? DMG_COLOUR : HEAL_COLOUR),
  178.                 -1,
  179.                 0,
  180.                 buffer2,
  181.                 128,
  182.                 SHD_OUTLINED8,
  183.                 ((Hero->Misc[OLDHP_DIFF]<0) ? DMG_OUTLINE : HEAL_OUTLINE)
  184.             );
  185.         }
  186.         else
  187.         {
  188.             Hero->Misc[DRAW_CLK] = 0;
  189.             Hero->Misc[OLDHP_INDX] = Hero->HP;
  190.         }
  191.     }
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement