Skip to content

GetIsFriend(), Not restricted to player party members?

One thing I really enjoyed from NWN2 Mask of the Betrayer, was the little XP you would get reworded for unlocking things. I made a little script to do that, then tried to make it multiplayer friendly, so your whole party gets XP, if they're close enough.
My main party determining logic hangs on GetIsFriend(). I changed the game to Hard Core Rules and I stopped getting XP when others in my party unlock things.

Do I have to use GetFirst/NextFactionMember instead?

Comments

  • MelkiorMelkior Member Posts: 204
    Yes, what you're looking for is GetFirstFactionMember / GetNextFactionMember in order to reward a player party in multi-player.

    Don't forget that you also need to account for summons, familiars, companion animals and other types of NPC associates, either by deliberately excluding them or deliberately including them.

    Incidentally, if you have a module where a summon can also summon, you need to account for that. GetMaster only returns the next-up-the-line creature, not the Player Character.

    Here's a short function I came up with called GetTrueMaster which takes care of finding the true master (NPC or PC) in a chain of summons:
    object GetTrueMaster(object oSummon=OBJECT_SELF)
    {
      if(GetObjectType(oSummon)!=OBJECT_TYPE_CREATURE) return OBJECT_INVALID;
      object oMaster=GetMaster(oSummon);
      while(oMaster!=GetMaster(oMaster))
        oMaster=GetMaster(oMaster);
      return oMaster;
    }
    
    If this function is called from within a script running on the associate, the associate does not need to be specified in the function call.
    This is not intended to work on anything other than a creature which is why the "if" condition is there and comes first.
    Using GetMaster on the ultimate master in a chain will return itself, so the "while" will keep looping until it finds that condition and then will return the true master.
  • ProlericProleric Member Posts: 1,316
    GetFirstFactionMember / GetNextFactionMember is indeed the right function.

    It returns all faction members including summons etc, which you can screen using GetAssociateType() or GetIsPC().

    Horses are regarded as henchmen, but can be detected using HorseGetIsAMount().
  • ForSeriousForSerious Member Posts: 466
    Thanks guys. I guess I've got a few things to rewrite now.
  • ForSeriousForSerious Member Posts: 466
    Oh man, Proleric, I wish it was that easy. The Lexicon says you cannot do both in the same loop. You have to pick all the NPCs or all the PCs.
  • MelkiorMelkior Member Posts: 204
    ForSerious wrote: »
    Oh man, Proleric, I wish it was that easy. The Lexicon says you cannot do both in the same loop. You have to pick all the NPCs or all the PCs.

    My reading of the lexicon says that you can either filter out all of the NPCs in the party or not filter them out. There is some incorrect text further down in the description of GetFirstFactionMember which says that you can only get one or the other, but the text under Parameters is correct that the filter either restricts the selection to only PCs or allows all members of the party, including NPCs, to be selected.

    Selecting only PCs is the default since this would normally be what you want in a function intended to (for example) reward PCs with experience.
  • ForSeriousForSerious Member Posts: 466
    Thank goodness! I ran a little test and sure enough, that statement in the Lexicon is incorrect.
    Melkior, you have been most helpful!
Sign In or Register to comment.