@Tarot_Redhand
Thanks for tidying @silentfaction00 script. 
Also, I’ll take a stab at answering the questions, but I guess @silentfaction00 will correct me if I’m wrong …
A small number of questions (by TR) -
- Is sTagOverride built into NwN 2 (I only build with NwN EE)? I ask because that variable is not declared in your code.
The sTagOverride is declared in the void main section. It’s a conversation action script where you can define and pass variables.
- Is there any reason why your switch statement doesn’t have a default term? It would be useful to have one for catching any errors that might crop up in the value carried by iType.
Agreed. Although my guess is one of these values has to pass for a damage type - although there is also a DAMAGE_TYPE_ALL (0)
- Final question and this is just checking and not an error in your code. Near the end of your function you have this … Just double checking that you know that the three variables you declare there wouldn’t be visible anywhere else in your function. As they are not used anywhere else this question is moot anyway.
I don’t think they are going to be used anywhere else, as the script ends thereafter and are used by then.
@silentfaction00
// GetPercentageHPLoss REQUIRES THIS INCLUDE LIBRARY
#include “ginc_behavior”
So, all you needed to do to have your script compile was to add it at the start like I have below …
// Damage types:
// 1 bludgeoning, 2 piercing, 4 slashing,
// 8 magical, 16 acid, 32 cold,
// 64 divine, 128 electrical, 256 fire,
// 512 negative, 1024 positive, 2048 sonic
//
// Use sTagOverride to target others, otherwise
// applies damage to PC Speaker
// GetPercentageHPLoss REQUIRES THIS INCLUDE LIBRARY
#include "ginc_behavior"
void main(int iAmount, int iType, string sTagOverride)
{
int iDamagePower = DAMAGE_POWER_ENERGY;
object oPC = GetPCSpeaker();
int iVFX;
string sSound;
string sSoundNo = IntToString(Random(2) + 1);
int PercHPS = GetPercentageHPLoss(OBJECT_SELF);
int iCurrentHP = GetCurrentHitPoints(oPC);
effect eAmount = EffectDamage(iAmount, iType, iDamagePower, FALSE);
int iDamagedHP = GetCurrentHitPoints(oPC);
if (iAmount < 1 || iType < 1)
return;
if (iType < 8)
iDamagePower = DAMAGE_POWER_NORMAL;
if (sTagOverride != "")
oPC = GetNearestObjectByTag(sTagOverride, OBJECT_SELF);
switch (iType)
{
case 1:
iVFX = 460;
sSound = "cb_ht_fleshleth";
break;
case 2:
iVFX = 109;
sSound = "cb_ht_daggrleth";
break;
case 4:
iVFX = 109;
sSound = "cb_ht_bladeleth";
break;
case 8:
iVFX = 76;
break;
case 16:
iVFX = 44;
break;
case 32:
iVFX = 63;
break;
case 64:
iVFX = 98;
break;
case 128:
iVFX = 74;
break;
case 256:
iVFX = 61;
break;
case 512:
iVFX = 81;
break;
case 1024:
iVFX = 584;
break;
case 2048:
iVFX = 588;
break;
}
if(PercHPS > 0)
SpeakString("SOUL >>> " + IntToString(PercHPS) + "%", TALKVOLUME_SHOUT);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eAmount, oPC);
if (iType <= 4 && iCurrentHP == iDamagedHP)
iVFX = 118;// change physical VFX if damage resisted
effect eVFX = EffectVisualEffect(iVFX);
if (iType > 4)// Do energy hit VFX
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oPC);
else// Do physical hit VFX
{
float fZ = GetCreatureSize(oPC) * 0.3;
vector vLoc = GetPosition(oPC) + Vector(0.0, 0.0, fZ);
location lLoc = Location(GetArea(oPC), vLoc, GetFacing(oPC));
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVFX, lLoc);
}
if (iCurrentHP == iDamagedHP && sSound != "")
sSound = "cb_pa_bld0";// Physical damage resisted
if (sSound != "")// If physical damage, play sound
AssignCommand(oPC, PlaySound(sSound+sSoundNo));
if (oPC == GetPCSpeaker() && iDamagedHP > 0 && iCurrentHP != iDamagedHP)
PlayCustomAnimation(oPC, "damage01", 0, 1.0);// Flinch if damage taken
}
LASTLY: I have NOT looked at the script any closer, so there may be other changes you need to consider, but do what you can first with it, and ask later if you need more help. 