The problem is - the XP award happens just fine - but the gold award only happens for the first PC. What I want is for the gold calcualtion and award to run for each member of the PC's faction
#include "ginc_companion"
#include "ginc_debug"
int ch_GetTotalGoldOnTarget(object oTarget)
{
int nGoldCoins = GetGold(oTarget);
int nItemValue;
object oItem = GetFirstItemInInventory(oTarget);
//Get Value of items in inventory
while(GetIsObjectValid(oItem))
{
nItemValue = nItemValue + GetGoldPieceValue(oItem);
oItem = GetNextItemInInventory(oTarget);
}
//Get Value of equiped items
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_ARMS, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_ARROWS, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_BELT, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_BOLTS, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_BOOTS, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_BULLETS, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_CHEST, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_CLOAK, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_HEAD, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_LEFTRING, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_NECK, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oTarget));
nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(INVENTORY_SLOT_RIGHTRING, oTarget));
//Add the two and return value
nGoldCoins = nGoldCoins + nItemValue;
return nGoldCoins;
}
void main()
{
object oEnter = GetEnteringObject();
PrettyDebug("nx2_enter_levelup: " + GetName(oEnter) + " entered " + GetName(GetArea(oEnter)));
if ( !GetIsRosterMember(oEnter) || GetTag(oEnter) != "" || GetLocalInt(oEnter, "nx2_bEnterXPGranted"))
{
PrettyDebug("nx2_enter_levelup: " + GetName(oEnter) + " is either not a roster member, or is a cohort" );
return;
}
object oPC = GetFirstPC();
while ( GetIsObjectValid(oPC) && oPC == oEnter )
{
oPC = GetNextPC();
}
int nXP = GetXP(oEnter);
int nPCXP = GetXP(oPC);
int nMinXP = 21000;
// If Minimum XP is greater than PC XP, set it to 90% of the PC's XP
if (nMinXP > nPCXP && GetIsObjectValid(oPC) )
{
nMinXP = FloatToInt(0.9 * IntToFloat(nPCXP));
PrettyDebug("nx2_enter_levelup: nMin XP changed to 90% of PC's XP --> " + IntToString(nMinXP) + " XP");
}
// Set XP if less than the Min XP
if ( nXP < nMinXP )
{
PrettyDebug("nx2_enter_levelup: Setting XP of " + GetName(oEnter) + " to " + IntToString(nMinXP));
SetXP(oEnter, nMinXP);
// Set a local variable on the character so they won't get this XP again.
SetLocalInt(oEnter, "nx2_bEnterXPGranted", 1);
}
else
PrettyDebug("nx2_enter_levelup: " + GetName(oEnter) + " has " + IntToString(nXP) + " XP which is not greater than the Minimum " + IntToString(nMinXP) + " XP");
/*if (!GetLocalInt(oEnter, "nx2_bEnterXPGranted") && nXP < 21000 && GetFactionEqual(oPC, oEnter)
{
SetXP(oEnter, nMinXP);
}*/
int nGold = 24000;
int nCurrent;
if (GetTotalLevels(oPC, FALSE) > 9)
{
SetGlobalInt("bBalance", 0);
}
object oFM = GetFirstFactionMember(oPC);
while (GetIsObjectValid(oFM))
{
if (GetLocalInt(oFM, "wyGPGranted") == FALSE)
{
nCurrent = ch_GetTotalGoldOnTarget(oFM);
nGold = nGold - nCurrent;
if (nGold < 0) nGold = 0;
GiveGoldToCreature(oFM, nGold);
nGold = nGold + 24000;
SetLocalInt(oFM, "wyGPGranted", TRUE);
}
oFM = GetNextFactionMember(oPC);
}
}





Retour en haut






