Aller au contenu

Photo

Giving individuals gold


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
WyrinDnjargo

WyrinDnjargo
  • Members
  • 136 messages
I'm trying to set it so that whena PC enters a specific starting area, they a are given a certain amount of gold such that the value of their gold  plus carried items is 24000. I'm using the script below, which also gives them XP

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);
 } 
}



#2
Guest_ElfinMad_*

Guest_ElfinMad_*
  • Guests

WyrinDnjargo wrote...

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();
 }
}


It's probably the oPC==oEnter boolean in your while statement. Did you mean oPC != oEnter?
Also this whole part is a little messy. Could you just use GetFirstEnteringPC() instead and not worry about the while loop and checking if you actually have a player?

#3
WyrinDnjargo

WyrinDnjargo
  • Members
  • 136 messages
Actually, that part is cribbed from the SoZ entry area on the ship where you add new party members and they get levelled up

I cycle through faction members after that tho... :(

#4
Guest_ElfinMad_*

Guest_ElfinMad_*
  • Guests
As I read it, if oPC == oEnter then the while loop will continue and cause oPC to be the nextPC. If you only have a single player then oPC will become object_invalid and then any passing of oPC to other functions will have no effect, like when you cycle through oPC's faction at the bottom of your script for the gold.

#5
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Also, when you change the value of a variable and then later try to use that new variable value in the same script, you need to re-get the variable value, otherwise it will keep returning the original value. So for example, in your while loop, you need to do something like:

 //Get Value of items in inventory
 while(GetIsObjectValid(oItem))
 {
  nItemValue = nItemValue + GetGoldPieceValue(oItem);
  SetLocalInt(oTarget, "ItemValue", nItemValue); // This will set the new value on oTarget
  oItem = GetNextItemInInventory(oTarget);
 }

For your section just after that of: //Get Value of equiped items
You need to reget the int value here. Also, that whole section can be reduced to a for() loop:

//Get Value of equiped items
nItemValue = GetLocalInt(oTarget, "ItemValue");
nInt;
for(nInt = 0; nInt < 18; nInt ++)
    {
     nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(nInt, oTarget));
     }

Also, you keep adding nItemValue to GetGoldPieceValue() but I don't see where you have assigned nItemValue a value in itself. No problem really, it will just keep adding 0 (zero) to the Gold Piece Value.

Have not looked at the entire script line by line, so there may be something else going on here.

Modifié par _Knightmare_, 26 août 2010 - 11:03 .


#6
Guest_ElfinMad_*

Guest_ElfinMad_*
  • Guests

_Knightmare_ wrote...

Also, when you change the value of a variable and then later try to use that new variable value in the same script, you need to re-get the variable value, otherwise it will keep returning the original value. So for example, in your while loop, you need to do something like:

 //Get Value of items in inventory
 while(GetIsObjectValid(oItem))
 {
  nItemValue = nItemValue + GetGoldPieceValue(oItem);
  SetLocalInt(oTarget, "ItemValue", nItemValue); // This will set the new value on oTarget
  oItem = GetNextItemInInventory(oTarget);
 }

For your section just after that of: //Get Value of equiped items
You need to reget the int value here. Also, that whole section can be reduced to a for() loop:

//Get Value of equiped items
nItemValue = GetLocalInt(oTarget, "ItemValue");
nInt;
for(nInt = 0; nInt < 18; nInt ++)
    {
     nItemValue = nItemValue + GetGoldPieceValue(GetItemInSlot(nInt, oTarget));
     }

Also, you keep adding nItemValue to GetGoldPieceValue() but I don't see where you have assigned nItemValue a value in itself. No problem really, it will just keep adding 0 (zero) to the Gold Piece Value.

Have not looked at the entire script line by line, so there may be something else going on here.

*Casts Eagle's Splendor. Spell failed*
This is not true. The nItemValue in this script is a cumulative addition of the gold value of the items. This variable's value can be altered and used anywhere in the scope of the script and does not need to be stored and recalled on a game object. Though the for loop for the inventory slots is very nice, I'll use that thanks.
*Casts Expeditious Retreat. Success*
Posted Image

#7
_Knightmare_

_Knightmare_
  • Members
  • 643 messages

ElfinMad wrote...

*Casts Eagle's Splendor. Spell failed*
This is not true. The nItemValue in this script is a cumulative addition of the gold value of the items. This variable's value can be altered and used anywhere in the scope of the script and does not need to be stored and recalled on a game object. Though the for loop for the inventory slots is very nice, I'll use that thanks.
*Casts Expeditious Retreat. Success*
Posted Image


I thought he had tried using the same variable in different scopes, especially at the end when he added it all together. I may have been wrong, as I said above, just scanned the script posted.

#8
WyrinDnjargo

WyrinDnjargo
  • Members
  • 136 messages
thanks for the pointers guys. Everythign works fine for the first PC, and XP is awarded to subsequent entering PCs, but it's just the extra gold that's the problem and looping through the party to give them all the same gold level (I'm wondering if the issue of pooled party gold versus personal PC items is messing things up)... I'll play with some of the formatting