Made in a few hours. Definitely improveable and not too customizable at the moment.
Download:
https://pastebin.com/TmBbVz3G
Demo:
https://www.youtube.com/watch?v=3yZSJNPa7u8
2:25
How to use:
Load the library and it works by default!
Syke! Nothing is preset. You have to register the HP yourself at the moment.
In the future I want it to work with the health variable in NPC config, but that's for basegame.
Customization options:
lhp.iFrames: Unified amount of invulnerability frames across all IDs (25 by default)
lhp.setHarmtypeDamage(Harmtype, value): Sets damage multiplier for specific harm types.
lhp.setHarmtypeSound(Harmtype, value): Sets sound effect for harm types. By default, onNPCHarm cancelling also cancels the SFX, so this adds that back in.
lhp.setNPCDamage(NPCID, value): Sets damage which a specific NPC does when it's determined to be the NPC causing the damage. Stuff like fireballs, hammers, etc...
lhp.setHP(NPCID, value): Sets HP for a specific ID of NPC.
lhp.drawHPBar(npc) draws the HP bar and can be overridden in user code
lhp.registerCallback(npcID, func) lets you register an onHarm callback for a given NPC ID.
The onHarm overload is as follows:
harmFunction(npc, harmReason, culprit, currentHP, damage)
if the harm function returns something, it must be a number. This number will override the damage dealt to the NPC. If nothing is returned, damage is not altered. Return 0 to cancel any damage being dealt.
The HP bar will empty before "vanilla hp" is touched, so it can be considered to be something more akin to armour.
Have fun!