LoD_PRC8/_module/nss/prc_pwondeath.nss
Jaysyn904 94990edc60 Initial Upload
Initial Upload
2023-09-21 21:20:34 -04:00

281 lines
9.6 KiB
Plaintext

//:://////////////////////////////////////////////////
//:: NW_C2_DEFAULT7
/*
Default OnDeath event handler for NPCs.
*/
//:://////////////////////////////////////////////////
//:: Modified by: SoulFlame
//:: Modified On: 01/18/2005
//:://////////////////////////////////////////////////
// Optional variable on killed creature that defines the gp reward
// given to each player in the party, in the same area.
const string GP_REWARD = "gpreward";
// New variable for # of lvls span b4 powerlvling
const int LOD_PWRLVL_SPAN = 5;
void C_RewardPC(object oVictum, object oKiller);
void GiveLowyGold(object oPC);
void GiveGoldToArea(object oPC, int nGold, int bBoss = FALSE);
int GetNumberOfPlayersInAreaAndParty(object oPC);
void main()
{
object oPlayer = GetLastKiller();
object oAttPC = GetLastDamager();
object AttWeapon = GetLastWeaponUsed(oAttPC);
if (GetLastKiller() != OBJECT_SELF)
{
if (GetIsPC(oPlayer))
{
C_RewardPC(OBJECT_SELF,oPlayer);
GiveLowyGold(oPlayer);
}
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectResurrection(), OBJECT_SELF);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectDamage((GetCurrentHitPoints(OBJECT_SELF))+1), OBJECT_SELF);
return;
}
}
void C_RewardPC(object oVictum, object oKiller)
{
//Divide the xp slider under mod properties by 10 and put it in below
//ie under mod properties = 17, make it 1.7 below
float XPSlider = 1.8;
int iGroupNumbers = 0, iTotalPartyLevel = 0, iAVpLvL = 0, iPLvL = 0, iPartyXP;
int iHighLvL=0,iLowLvL=40,iMemberLvL;
float fXPGive, fMonsterCR = GetChallengeRating(oVictum);
string sDAfetch, strXP;
object oPartyMember = GetFirstFactionMember(oKiller, TRUE);
// ELVIN:
// If no members are in the faction then return (prevents a divide by zero error
// further into the script).
// This may happen if the a DM is possessing a creature and kills another creature, as
// the GetIsPC function call would return TRUE - but number in the faction would be zero.
if (oPartyMember == OBJECT_INVALID)
return;
while (GetIsObjectValid(oPartyMember))
{
if ((GetDistanceBetween(oVictum, oPartyMember) < 50.0) && (GetArea(oKiller) == GetArea(oPartyMember)))
{
if (GetIsDead(oPartyMember) == FALSE)
{
int iPpXP = GetXP(oPartyMember);
iMemberLvL = GetHitDice(oPartyMember);
int iPplevel;
switch (iMemberLvL)
{
case 40 : iPplevel= 5000000; break;
case 39 : iPplevel= 780000; break;
case 38 : iPplevel= 741000; break;
case 37 : iPplevel= 703000; break;
case 36 : iPplevel= 666000; break;
case 35 : iPplevel= 630000; break;
case 34 : iPplevel= 595000; break;
case 33 : iPplevel= 561000; break;
case 32 : iPplevel= 528000; break;
case 31 : iPplevel= 496000; break;
case 30 : iPplevel= 465000; break;
case 29 : iPplevel= 435000; break;
case 28 : iPplevel= 406000; break;
case 27 : iPplevel= 378000; break;
case 26 : iPplevel= 351000; break;
case 25 : iPplevel= 325000; break;
case 24 : iPplevel= 300000; break;
case 23 : iPplevel= 276000; break;
case 22 : iPplevel= 253000; break;
case 21 : iPplevel= 231000; break;
case 20 : iPplevel= 210000; break;
case 19 : iPplevel= 190000; break;
case 18 : iPplevel= 171000; break;
case 17 : iPplevel= 153000; break;
case 16 : iPplevel= 136000; break;
case 15 : iPplevel= 120000; break;
case 14 : iPplevel= 105000; break;
case 13 : iPplevel= 91000; break;
case 12 : iPplevel= 78000; break;
case 11 : iPplevel= 66000; break;
case 10 : iPplevel= 55000; break;
case 9 : iPplevel= 45000; break;
case 8 : iPplevel= 36000; break;
case 7 : iPplevel= 28000; break;
case 6 : iPplevel= 21000; break;
case 5 : iPplevel= 15000; break;
case 4 : iPplevel= 10000; break;
case 3 : iPplevel= 6000; break;
case 2 : iPplevel= 3000; break;
case 1 : iPplevel= 1000; break;
}
if(iPpXP > iPplevel)
SetLocalInt(oPartyMember, "PPHoarding", 1);
if (iMemberLvL > iHighLvL) {iHighLvL = iMemberLvL;}
if (iMemberLvL < iLowLvL) {iLowLvL = iMemberLvL;}
iGroupNumbers++;
iTotalPartyLevel += iMemberLvL;
}
}
oPartyMember = GetNextFactionMember(oKiller, TRUE);
}
// Powerleveling variable set
if (iHighLvL - iLowLvL > LOD_PWRLVL_SPAN)
iPLvL = 1;
// Make sure the group number is not zero. Prevents divide by zero error.
if (iGroupNumbers == 0)
return;
iAVpLvL = (iTotalPartyLevel / iGroupNumbers);
if (fMonsterCR > 40.0)
fMonsterCR = 40.0;
if ((iAVpLvL - FloatToInt(fMonsterCR)) < -4)
fMonsterCR = IntToFloat((iAVpLvL + 4));
sDAfetch = "C" + IntToString(FloatToInt(fMonsterCR));
strXP = Get2DAString("xptable",sDAfetch,(iAVpLvL - 1));
fXPGive = StringToFloat(strXP);
fXPGive *= XPSlider;
iPartyXP = FloatToInt(fXPGive);
oPartyMember = GetFirstFactionMember(oKiller, TRUE);
while (GetIsObjectValid(oPartyMember))
{
if ((GetDistanceBetween(oVictum, oPartyMember) < 50.0) && (GetArea(oKiller) == GetArea(oPartyMember)))
{
if ((GetIsDead(oPartyMember)) == FALSE)
{
if (iPLvL != 1)
{
int iMaxXp;
if (GetLocalInt(OBJECT_SELF, GP_REWARD) > 0) { iMaxXp = 2000; }
else { iMaxXp = 600; }
if (GetLocalInt(oPartyMember, "PPHoarding") != 1)
{
/********************************************************/
// ELVINS TEMPORARY FIX
// Stop xp gain going over MAX_XP_REWARD.
/********************************************************/
iPartyXP = iPartyXP > iMaxXp ? iMaxXp : iPartyXP;
GiveXPToCreature(oPartyMember, iPartyXP);
}
else
{
SendMessageToPC(oPartyMember, "Hoarding detected, no xp awarded");
SetLocalInt(oPartyMember, "PPHoarding", 0);
}
}
else
{
SendMessageToPC(oPartyMember, "Powerleveling detected, no xp awarded");
}
}
}
oPartyMember = GetNextFactionMember(oKiller, TRUE);
}
}
void GiveLowyGold(object oPC)
{
// Get fixed GP reward from creature, if special gpreward variable
// has beed defined.
int nFixedGPReward = GetLocalInt(OBJECT_SELF, GP_REWARD);
float fCR = GetChallengeRating(OBJECT_SELF);
int iAmount;
int bBoss = FALSE;
// If a fixed GP reward is to be given, then set gp amount to this.
if (nFixedGPReward > 0)
{
iAmount = nFixedGPReward;
bBoss = TRUE;
}
// Else, calculate GP reward from cr of creature.
else
{
if (fCR > 100.0) return;
int ifCR = FloatToInt(fCR);
if ((ifCR >= 76) && (ifCR <= 100)) iAmount = 3500;
else if ((ifCR >= 61) && (ifCR <= 75)) iAmount = 3000;
else if ((ifCR >= 40) && (ifCR <= 60)) iAmount = 2500;
else if ((ifCR >= 35) && (ifCR <= 39)) iAmount = 2300;
else if ((ifCR >= 31) && (ifCR <= 34)) iAmount = 2000;
else if ((ifCR >= 29) && (ifCR <= 30)) iAmount = 1800;
else if ((ifCR >= 25) && (ifCR <= 28)) iAmount = 1600;
else if ((ifCR >= 21) && (ifCR <= 24)) iAmount = 1400;
else if ((ifCR >= 18) && (ifCR <= 20)) iAmount = 1200;
else if ((ifCR >= 15) && (ifCR <= 17)) iAmount = 1000;
else if (ifCR == 14) iAmount = 900;
else if (ifCR == 13) iAmount = 800;
else if (ifCR == 12) iAmount = 700;
else if (ifCR == 11) iAmount = 600;
else if ((ifCR >= 9) && (ifCR <= 10)) iAmount = 500;
else if ((ifCR >= 7) && (ifCR <= 8)) iAmount = 400;
else if (ifCR == 6) iAmount = 300;
else if (ifCR == 5) iAmount = 250;
else if (ifCR == 4) iAmount = 220;
else if (ifCR == 3) iAmount = 200;
else if (ifCR == 2) iAmount = 180;
else if (ifCR == 1) iAmount = 160;
else iAmount = 100;
}
GiveGoldToArea(oPC, iAmount, bBoss);
return;
}
void GiveGoldToArea(object oPC, int nGold, int bIsBoss)
{
object oArea = GetArea(oPC);
float fGold = IntToFloat(nGold);
int nPCCount;
if(bIsBoss)
{
nPCCount = GetNumberOfPlayersInAreaAndParty(oPC);
int nPercentage = 100 - ((nPCCount - 1) * 5);
nPercentage = nPercentage < 50 ? 50 : nPercentage;
nGold = FloatToInt(nGold * (nPercentage/100.0f));
}
object oPartyMem = GetFirstFactionMember(oPC, TRUE);
while (GetIsObjectValid(oPartyMem))
{
if (GetArea(oPartyMem) == oArea && GetDistanceBetween(oPC,oPartyMem) <= 20.0f)
GiveGoldToCreature(oPartyMem, nGold);
oPartyMem = GetNextFactionMember(oPC, TRUE);
}
}
int GetNumberOfPlayersInAreaAndParty(object oPC)
{
int nCount;
object oArea = GetArea(oPC);
object oPartyMem = GetFirstFactionMember(oPC, TRUE);
while (GetIsObjectValid(oPartyMem))
{
if (GetArea(oPartyMem) == oArea && GetDistanceBetween(oPC,oPartyMem) <= 20.0f)
nCount++;
oPartyMem = GetNextFactionMember(oPC, TRUE);
}
return nCount;
}