Aller au contenu

Photo

Scripting Finess: efficient object reference in updating the journal entries of PCs (resolved)


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

#1
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
So I used to just use GetFirstPC() to update the local integer that tracks the journal entries, but now I know that is not ideal.  I was thinking about setting up a loop to update the local integer for all members of the faction.

The script is a tag-based on acquire event, so I was just going to set the local int on all the members of the acquirer's faction. 

Is there a better way?

Modifié par M. Rieder, 13 juin 2011 - 11:58 .


#2
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
also, how would I reference the creature that is acquiring the object? Do I use:

GetModuleItemAcquiredBy()?

If so, does that mean the item has to be a module item and not a campaign item?

#3
Guest_Chaos Wielder_*

Guest_Chaos Wielder_*
  • Guests
It can be either a campaign item or a module item.

GetFirstPC isn't ideal if you want your mod to be multiplayer compatible. If it doesn't matter then go ahead and use it. It doesn't cause an undue burden on the system and it's not worth worrying about.

#4
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
I want to make my module open to MP even if it is not specifically intended as such. Thanks for the info, I like to keep all my items campaign as much as possible.


Sadly my script isn't working..
It only updates the journal of the member who picks up the object, not the other members, as it should.

Here it is:



void main()
{
object oMember;
FloatingTextStringOnCreature("worked",GetFirstPC());
object oAcquire = GetModuleItemAcquiredBy();
FloatingTextStringOnCreature("I am oAcquire",oAcquire);
object oSelf = GetObjectByTag("205_note_from_dark_seeker");
int nEntryValue = 40;
int nAlwaysFire = 0;
string sTag = "recent_events";
int nRunOnce = GetLocalInt(oSelf,"nRunOnce");
SetLocalInt(oAcquire,"NW_JOURNAL_ENTRY"+sTag,nEntryValue);
GiveXPToCreature(oAcquire,25);
if (nRunOnce==0)
{
oMember = GetFirstFactionMember(oAcquire,FALSE);
while (GetIsObjectValid(oMember))
{
FloatingTextStringOnCreature(GetTag(oMember),GetFirstPC());
SetLocalInt(oMember,"NW_JOURNAL_ENTRY"+sTag,nEntryValue);
GiveXPToCreature(oMember,25);
oMember = GetNextFactionMember(oAcquire,FALSE);
}
}


nRunOnce=1;
SetLocalInt(oSelf,"nRunOnce",nRunOnce);
}

#5
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages

M. Rieder wrote...
The script is a tag-based on acquire event, so I was just going to set the local int on all the members of the acquirer's faction.  


( please note that i know nothing about journals, so am giving just general info and hoping it helps. )

Refer to Referencing Objects in Scripts

By referring to that you can see on acquire uses the following events. GetFirstPC() would not work right in MP, but this also is going to fire on NPC's so a GetIsPC() might be in order. Looking at other scripts for a specific event is also a good idea, as each generally has it's own way of doing things.
object oPC = GetModuleItemAcquiredBy();
object oItem = GetModuleItemAcquired();

Example of GetIsPC
if (GetIsPC(oKiller) || GetIsPC(GetMaster(oKiller)) )
{
	// do stuff
}

You probably would need to do some testing of whatever you are doing, but whenever this specific event fires, it's because the object referenced by GetModuleItemAcquiredBy() got a new item. This is technically what is going on, and by doing it with this function instead of GetFirstPC() i suspect you will face fewer bugs. Technically it probably will just work in SP just because there are no other objects, but that assumption also generalizes things and you might not even notice when this is actually causing a problem in SP since it usually just works. ( An awful lot of real issues rpgplayer1 fixed i could easily classify in this category. )

You might have to iterate the members of the faction to set an int on all members of the party like you describe, even though i am not sure why you are doing that to begin with. This is something which is only needed in MP really.

Example as follows for splitting gold among members of a party, with iterators in the first function. I have a script command which lets a player send a specific amount of gold which gets split amoung all members of their party. First it counts them, in the second it gives gold and sends a message to each member. Hopefully that makes that clear. ( the true parameter limits this to actual PC's and skipping henchmen )
void CSLPartySplitDelayed(object oPC, int nSplitGold)
{
   int nCount = 0;
   object oParty = GetFirstFactionMember(oPC, TRUE);
   while (GetIsObjectValid(oParty)) {
      nCount++;
      oParty = GetNextFactionMember(oPC, TRUE);
   }
   int nShare = nSplitGold / nCount;
   oParty = GetFirstFactionMember(oPC, TRUE);
   while (GetIsObjectValid(oParty)) {
      GiveGoldToCreature(oParty, nShare);
      if (oPC==oParty) SendMessageToPC(oParty, "You split " + IntToString(nSplitGold) + " gold amoung " + IntToString(nCount) + CSLAddS(" party member", nCount) + ". Your share was " + IntToString(nShare) + ".");
      else SendMessageToPC(oParty, GetFirstName(oPC) + " has split party gold. Your share was " + IntToString(nShare) + ".");
      oParty = GetNextFactionMember(oPC, TRUE);
   }
}

void CSLPartySplit(object oPC, int nSplitGold)
{
   if (nSplitGold<100) {
      SendMessageToPC(oPC, "You must specify how much gold to split with your Party (100 gold minimum).");
      return;
   }
   int nGold = GetGold(oPC);
   if (nSplitGold > nGold) {
      SendMessageToPC(oPC, "You do not have that much gold to split with your Party.");
      return;
   }
   TakeGoldFromCreature(nSplitGold, oPC); // PC LOSES ALL THE GOLD, GETS SOME BACK IN DELAY
   DelayCommand(0.5f, CSLPartySplitDelayed(oPC, nSplitGold));
}

Modifié par painofdungeoneternal, 13 juin 2011 - 10:05 .


#6
Shallina

Shallina
  • Members
  • 1 012 messages
there is an option to update the journal to all party member in the ga_journal or ga_journal_entry script.

update journal of the one picking up the the item with that ga_journal script.

#7
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
so just looking at that script ( he's not doing this in a conversation node ) it looks like AddJournalQuestEntry has a parameter for doing this without having to loop thru the members of the party.

void main(string sCategoryTag, int nEntryID, int bAllPartyMembers, int bAllPlayers, int bAllowOverrideHigher)
{
	object oPC = (GetPCSpeaker()==OBJECT_INVALID?OBJECT_SELF:GetPCSpeaker());
	AddJournalQuestEntry(sCategoryTag, nEntryID, oPC, bAllPartyMembers, bAllPlayers, bAllowOverrideHigher);
}



#8
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Hey Pain, thanks for the info.

Shallina, good idea. I'll try that.

#9
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
I opened up the script that Shallina suggested and found that, much to my embarrassment, there is a specific function for this. It is called:

AddJournalQuestEntry(). It is a system function and does not require and include#.

Thanks again for the help.