NWScript:
void ApplyPercentPenalty(object oDead,
float flPenaltyXP,
float flPenaltyGold)
{
flPenaltyXP = flPenaltyXP < 0.0 ? 0.0 : flPenaltyXP;
flPenaltyXP = flPenaltyXP > 1.0 ? 1.0 : flPenaltyXP;
flPenaltyGold =
flPenaltyGold < 0.0 ? 0.0 : flPenaltyGold;
flPenaltyGold =
flPenaltyGold > 1.0 ? 1.0 : flPenaltyGold;
int nCurrentXP = GetXP(oDead);
int nCharacterLevel = GetHitDice(oDead);
int nLostXP = FloatToInt(flPenaltyXP*nCurrentXP);
int nNewXP = nCurrentXP - nLostXP;
int nLowerBoundXP = ((nCharacterLevel *
(nCharacterLevel-1)) /
2 * 1000);
nNewXP =
nNewXP < nLowerBoundXP ? nLowerBoundXP : nNewXP;
SetXP(oDead, nNewXP);
AssignCommand(oDead,
TakeGoldFromCreature(FloatToInt(
flPenaltyGold * GetGold(oDead)),
oDead, TRUE));
}