Advertisement
ZoriaRPG

HP Change Display, v0.6

Aug 19th, 2020
2,394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.97 KB | None | 0 0
  1. ///////////////////////////
  2. // RPG-esque HP Display  //
  3. // v0.6                  //
  4. // 19th August, 2020     //
  5. // For ZC 2.55 Alpha 80+ //
  6. // By: ZoriaRPG          //
  7. ///////////////////////////
  8.  
  9. namespace hphealth
  10. {
  11.     const int TEMPLIFESPAN_SPRITE = 1;
  12.     enum colourtype { cNONE, cWHITE, cGREY, cBLUE, cRED = 0x81 };
  13.    
  14.     const int OLDHP_INDX = 19;
  15.     const int OLDHP_DIFF = 20;
  16.     const int SPAWN_CLK = 21;
  17.     const int DRAW_CLK = 22;
  18.     const int INITIALISED = 23;
  19.     const int SPAWNCLKDUR = 60;
  20.     const int HPCLOCKDUR = 40;
  21.     const int CREATEDSPR = 24;
  22.  
  23.     const int DMG_COLOUR = cRED;
  24.     const int DMG_OUTLINE = cWHITE;
  25.     const int HEAL_OUTLINE = cWHITE;
  26.     const int HEAL_COLOUR = cBLUE;
  27.  
  28.     const int DRAW_LAYER = 6;
  29.     const int XOFS = -4;
  30.     const int YOFS = -4;
  31.     const int DUMMY_SPRITE_ID = 255;
  32.     const int DUMMY_SPRITE_OTILE = 214240;
  33.     const int DUMMY_SPRITE_FRAMES = 1;
  34.     const int DUMMY_SPRITE_SPD = 16;
  35.     const int DUMMY_AMOUNT = 30;
  36.    
  37.     void init_dummy_sprite()
  38.     {
  39.         spritedata sd = Game->LoadSpriteData(DUMMY_SPRITE_ID);
  40.         sd->Tile = DUMMY_SPRITE_OTILE;
  41.         sd->Frames = DUMMY_SPRITE_FRAMES;
  42.         sd->Speed = DUMMY_SPRITE_SPD;
  43.     }
  44.        
  45.        
  46.  
  47.     global script test
  48.     {
  49.         void run()
  50.         {
  51.             init_dummy_sprite();
  52.             while(1)
  53.             {
  54.                 for ( int q = Screen->NumNPCs(); q > 0; --q )
  55.                 {
  56.                     npc n = Screen->LoadNPC(q);
  57.                     init_enemy_hp(n);
  58.                     do_npc_hp_clock(n);
  59.                     update_npc_hp(n);
  60.                     draw_npc_hp_change(n);
  61.                 }
  62.                 //draw_floating_damage();
  63.                 init_hero_hp();
  64.                 do_hero_hp_clock();
  65.                 update_hero_hp();
  66.                 draw_hero_hp_change();
  67.                 Waitdraw();
  68.                 Waitframe();
  69.             }
  70.         }
  71.     }
  72.  
  73.  
  74.     void do_npc_hp_clock(npc n)
  75.     {
  76.         ++n->Misc[SPAWN_CLK];
  77.     }
  78.  
  79.     void init_enemy_hp(npc n)
  80.     {
  81.         unless ( n->Misc[INITIALISED] )
  82.         {
  83.             n->Misc[OLDHP_INDX] = n->HP;
  84.             n->Misc[INITIALISED] = 1;
  85.         }
  86.     }
  87.     void update_npc_hp(npc n)
  88.     {
  89.        
  90.         {
  91.             if ( n->Family != NPCT_GLEEOK && n->Misc[DRAW_CLK] == 0 && (n->HitBy[2] || n->Family == NPCT_MOLDORM ) && n->HP != n->Misc[OLDHP_INDX] )
  92.             {
  93.                
  94.                 n->Misc[OLDHP_DIFF] = n->HP - n->Misc[OLDHP_INDX];
  95.                 n->Misc[DRAW_CLK] = HPCLOCKDUR;
  96.                
  97.             }
  98.             else if ( (n->Family == NPCT_GLEEOK && n->Core) && n->HP != n->Misc[OLDHP_INDX] && n->Misc[DRAW_CLK] == 0 )
  99.             {
  100.                 n->Misc[OLDHP_DIFF] = n->HP - n->Misc[OLDHP_INDX];
  101.                 n->Misc[DRAW_CLK] = HPCLOCKDUR;
  102.             }
  103.  
  104.             else if ( n->Family == NPCT_LANMOLA && n->HP != n->Misc[OLDHP_INDX] && n->Misc[DRAW_CLK] == 0 )
  105.             {
  106.                 npcdata nd = Game->LoadNPCData(n->ID);
  107.                 int orighp = (nd->HP -1) * -1;
  108.                 //printf("hp: %d\n", orighp);
  109.                 int tmpdif = n->HP - n->Misc[OLDHP_INDX];
  110.                 if ( tmpdif == orighp && n->Misc[SPAWN_CLK] < 60 )
  111.                 {
  112.                     n->Misc[OLDHP_INDX] = n->HP;
  113.                     return;
  114.                 }
  115.                 else
  116.                 {
  117.                     n->Misc[OLDHP_DIFF] = n->HP - n->Misc[OLDHP_INDX];
  118.                     n->Misc[DRAW_CLK] = HPCLOCKDUR;
  119.                 }
  120.             }
  121.         }
  122.        
  123.     }
  124.    
  125.     /*void draw_floating_damage()
  126.     {
  127.         for ( int q = Screen->NumLWeapons(); q > 0; --q )
  128.         {
  129.             lweapon t = Screen->LoadLWeapon(q);
  130.             if ( t->ID == LW_SPARKLE && t->Misc[IS_DUMMMY_SPR] )
  131.             {
  132.                 t->Script = Game->GetLWeaponScript("damagedisplay");
  133.             }
  134.         }
  135.     }*/
  136.    
  137.     lweapon script damagedisplay
  138.     {
  139.         void run()
  140.         {
  141.             //printf("Starting damagedisplay\n");
  142.             int buffer[8];
  143.             int buffer2[8];
  144.             itoa(buffer,this->Misc[DUMMY_AMOUNT]);
  145.             if ( this->Misc[DUMMY_AMOUNT] > 0 )
  146.             {
  147.                 buffer2[0] = '+';
  148.             }
  149.             strcat(buffer2, buffer);
  150.             while(1)
  151.             {
  152.                 //printf("Drawing damagedisplay\n");
  153.                 Screen->DrawString
  154.                 (
  155.                     DRAW_LAYER,
  156.                     this->X,
  157.                     this->Y,
  158.                     FONT_Z3SMALL,
  159.                     ((this->Misc[DUMMY_AMOUNT]<0) ? DMG_COLOUR : HEAL_COLOUR),
  160.                     -1,
  161.                     0,
  162.                     buffer2,
  163.                     128,
  164.                     SHD_OUTLINED8,
  165.                     ((this->Misc[DUMMY_AMOUNT]<0) ? DMG_OUTLINE : HEAL_OUTLINE)
  166.                 );
  167.                 Waitframe();
  168.             }
  169.         }
  170.     }
  171.  
  172.     void draw_npc_hp_change(npc n)
  173.     {
  174.         if (  n->Misc[SPAWN_CLK] < SPAWNCLKDUR ) return;
  175.         if ( n->Family == NPCT_LANMOLA && n->Misc[OLDHP_DIFF] > 0 ) return; //Lanmolas juggle HP so don't show imbalances being offset.
  176.         if ( --n->Misc[DRAW_CLK] > 0 && n->Misc[OLDHP_DIFF] )
  177.         {
  178.             /*int buffer[8];
  179.             int buffer2[8];
  180.             itoa(buffer,n->Misc[OLDHP_DIFF]);
  181.             if ( n->Misc[OLDHP_DIFF] > 0 )
  182.             {
  183.                 buffer2[0] = '+';
  184.             }
  185.             strcat(buffer2, buffer);
  186.             */
  187.             if ( TEMPLIFESPAN_SPRITE )
  188.             {
  189.                 int tmpx, tmpy;
  190.                 unless ( n->Misc[CREATEDSPR] )
  191.                 {
  192.                     npc prnt = Screen->LoadNPCByUID(n->ParentUID);
  193.                     if (n->Family == NPCT_MOLDORM || n->Family == NPCT_LANMOLA )
  194.                     {
  195.                         //find the core
  196.                         //npc prnt = Screen->LoadNPCByUID(n->ParentUID);
  197.                         tmpx = prnt->X;
  198.                         tmpy = prnt->Y;
  199.                     }
  200.                     else if ( n->Family == NPCT_GLEEOK )
  201.                     {
  202.                         tmpx = prnt->X-12;
  203.                         tmpy = prnt->Y-4;
  204.                     }
  205.                     else
  206.                     {
  207.                         tmpx = n->X;
  208.                         tmpy = n->Y;
  209.                     }
  210.                    
  211.                     printf("Creating dummy sprite.\n");
  212.                     lweapon dummy = Screen->CreateLWeapon(LW_SPARKLE);
  213.                     dummy->X = tmpx + XOFS;
  214.                     dummy->Y = tmpy + YOFS;
  215.                     dummy->UseSprite(DUMMY_SPRITE_ID);
  216.                     dummy->HitYOffset = -32768;
  217.                     dummy->Misc[DUMMY_AMOUNT] = n->Misc[OLDHP_DIFF];
  218.                     dummy->Script = Game->GetLWeaponScript("damagedisplay");
  219.                     printf("Game->GetLWeaponScript(damagedisplay) is: %d\n", dummy->Script);
  220.                     n->Misc[CREATEDSPR] = 1;
  221.                 }
  222.             }
  223.             else
  224.             {
  225.                 int buffer[8];
  226.                 int buffer2[8];
  227.                 itoa(buffer,n->Misc[OLDHP_DIFF]);
  228.                 if ( n->Misc[OLDHP_DIFF] > 0 )
  229.                 {
  230.                     buffer2[0] = '+';
  231.                 }
  232.                 strcat(buffer2, buffer);
  233.                 Screen->DrawString
  234.                 (
  235.                     DRAW_LAYER,
  236.                     n->X + XOFS,
  237.                     n->Y + YOFS,
  238.                     FONT_Z3SMALL,
  239.                     ((n->Misc[OLDHP_DIFF]<0) ? DMG_COLOUR : HEAL_COLOUR),
  240.                     -1,
  241.                     0,
  242.                     buffer2,
  243.                     128,
  244.                     SHD_OUTLINED8,
  245.                     ((n->Misc[OLDHP_DIFF]<0) ? DMG_OUTLINE : HEAL_OUTLINE)
  246.                 );
  247.             }
  248.                
  249.            
  250.         }
  251.         else
  252.         {
  253.             n->Misc[DRAW_CLK] = 0;
  254.             n->Misc[OLDHP_INDX] = n->HP;
  255.             n->Misc[CREATEDSPR] = 0;
  256.         }
  257.     }
  258.     void do_hero_hp_clock()
  259.     {
  260.         ++Hero->Misc[SPAWN_CLK];
  261.     }
  262.  
  263.     void init_hero_hp()
  264.     {
  265.         unless ( Hero->Misc[INITIALISED] )
  266.         {
  267.             Hero->Misc[OLDHP_INDX] = Hero->HP;
  268.             Hero->Misc[INITIALISED] = 1;
  269.         }
  270.     }
  271.     void update_hero_hp()
  272.     {
  273.        
  274.         if ( Hero->Misc[DRAW_CLK] == 0 && Hero->HP != Hero->Misc[OLDHP_INDX] )
  275.         {
  276.             Hero->Misc[OLDHP_DIFF] = Hero->HP - Hero->Misc[OLDHP_INDX];
  277.             Hero->Misc[DRAW_CLK] = HPCLOCKDUR;
  278.         }
  279.     }
  280.  
  281.  
  282.  
  283.     void draw_hero_hp_change()
  284.     {
  285.         if ( --Hero->Misc[DRAW_CLK] > 0 && Hero->Misc[OLDHP_DIFF] )
  286.         {
  287.            
  288.             int buffer[8];
  289.             int buffer2[8];
  290.            
  291.             itoa(buffer,Hero->Misc[OLDHP_DIFF]);
  292.             if ( Hero->Misc[OLDHP_DIFF] > 0 )
  293.             {
  294.                 buffer2[0] = '+';
  295.             }
  296.             strcat(buffer2, buffer);
  297.            
  298.             Screen->DrawString
  299.             (
  300.                 DRAW_LAYER,
  301.                 Hero->X + XOFS,
  302.                 Hero->Y + YOFS,
  303.                 FONT_Z3SMALL,
  304.                 ((Hero->Misc[OLDHP_DIFF]<0) ? DMG_COLOUR : HEAL_COLOUR),
  305.                 -1,
  306.                 0,
  307.                 buffer2,
  308.                 128,
  309.                 SHD_OUTLINED8,
  310.                 ((Hero->Misc[OLDHP_DIFF]<0) ? DMG_OUTLINE : HEAL_OUTLINE)
  311.             );
  312.         }
  313.         else
  314.         {
  315.             Hero->Misc[DRAW_CLK] = 0;
  316.             Hero->Misc[OLDHP_INDX] = Hero->HP;
  317.         }
  318.     }
  319. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement