/////////////////////////// // RPG-esque HP Display // // v0.3 // // 18th August, 2020 // // For ZC 2.55 Alpha 80+ // // By: ZoriaRPG // /////////////////////////// namespace hphealth { enum colourtype { cNONE, cWHITE, cGREY, cBLUE, cRED = 0xE1 }; const int OLDHP_INDX = 19; const int OLDHP_DIFF = 20; const int SPAWN_CLK = 21; const int DRAW_CLK = 22; const int INITIALISED = 23; const int SPAWNCLKDUR = 60; const int HPCLOCKDUR = 40; const int DMG_COLOUR = cRED; const int DMG_OUTLINE = cWHITE; const int HEAL_OUTLINE = cWHITE; const int HEAL_COLOUR = cBLUE; const int DRAW_LAYER = 6; const int XOFS = -4; const int YOFS = -4; global script test { void run() { while(1) { for ( int q = Screen->NumNPCs(); q > 0; --q ) { npc n = Screen->LoadNPC(q); init_enemy_hp(n); do_npc_hp_clock(n); update_npc_hp(n); draw_npc_hp_change(n); } init_hero_hp(); do_hero_hp_clock(); update_hero_hp(); draw_hero_hp_change(); Waitdraw(); Waitframe(); } } } void do_npc_hp_clock(npc n) { ++n->Misc[SPAWN_CLK]; } void init_enemy_hp(npc n) { unless ( n->Misc[INITIALISED] ) { n->Misc[OLDHP_INDX] = n->HP; n->Misc[INITIALISED] = 1; } } void update_npc_hp(npc n) { if ( n->Family == NPCT_LANMOLA ) { if ( n->HitBy[2] ) { printf("Lanmola hit.\n"); } } else { if ( n->Misc[DRAW_CLK] == 0 && (n->HitBy[2] || n->Family == NPCT_MOLDORM || n->Family == NPCT_GLEEOK) && n->HP != n->Misc[OLDHP_INDX] ) { if ( (n->Family == NPCT_GLEEOK && n->Core) || !n->Family == NPCT_GLEEOK ) { n->Misc[OLDHP_DIFF] = n->HP - n->Misc[OLDHP_INDX]; n->Misc[DRAW_CLK] = HPCLOCKDUR; } } } } void draw_npc_hp_change(npc n) { if ( n->Misc[SPAWN_CLK] < SPAWNCLKDUR ) return; if ( --n->Misc[DRAW_CLK] > 0 && n->Misc[OLDHP_DIFF] ) { int buffer[8]; int buffer2[8]; itoa(buffer,n->Misc[OLDHP_DIFF]); if ( n->Misc[OLDHP_DIFF] > 0 ) { buffer2[0] = '+'; } strcat(buffer2, buffer); Screen->DrawString ( DRAW_LAYER, n->X + XOFS, n->Y + YOFS, FONT_Z3SMALL, ((n->Misc[OLDHP_DIFF]<0) ? DMG_COLOUR : HEAL_COLOUR), -1, 0, buffer2, 128, SHD_OUTLINED8, ((n->Misc[OLDHP_DIFF]<0) ? DMG_OUTLINE : HEAL_OUTLINE) ); } else { n->Misc[DRAW_CLK] = 0; n->Misc[OLDHP_INDX] = n->HP; } } void do_hero_hp_clock() { ++Hero->Misc[SPAWN_CLK]; } void init_hero_hp() { unless ( Hero->Misc[INITIALISED] ) { Hero->Misc[OLDHP_INDX] = Hero->HP; Hero->Misc[INITIALISED] = 1; } } void update_hero_hp() { if ( Hero->Misc[DRAW_CLK] == 0 && Hero->HP != Hero->Misc[OLDHP_INDX] ) { Hero->Misc[OLDHP_DIFF] = Hero->HP - Hero->Misc[OLDHP_INDX]; Hero->Misc[DRAW_CLK] = HPCLOCKDUR; } } void draw_hero_hp_change() { if ( --Hero->Misc[DRAW_CLK] > 0 && Hero->Misc[OLDHP_DIFF] ) { int buffer[8]; int buffer2[8]; itoa(buffer,Hero->Misc[OLDHP_DIFF]); if ( Hero->Misc[OLDHP_DIFF] > 0 ) { buffer2[0] = '+'; } strcat(buffer2, buffer); Screen->DrawString ( DRAW_LAYER, Hero->X + XOFS, Hero->Y + YOFS, FONT_Z3SMALL, ((Hero->Misc[OLDHP_DIFF]<0) ? DMG_COLOUR : HEAL_COLOUR), -1, 0, buffer2, 128, SHD_OUTLINED8, ((Hero->Misc[OLDHP_DIFF]<0) ? DMG_OUTLINE : HEAL_OUTLINE) ); } else { Hero->Misc[DRAW_CLK] = 0; Hero->Misc[OLDHP_INDX] = Hero->HP; } } }