Advertisement
ZoriaRPG

HP Change Display, v0.2

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