GetFactionWeakestMember

From NWN Lexicon
Jump to navigationJump to search



GetFactionWeakestMember(object, int)

Get the weakest member in a faction (party).

object GetFactionWeakestMember(
    object oFactionMember = OBJECT_SELF,
    int bMustBeVisible = TRUE
);

Parameters

oFactionMember

The object whose faction you wish to examine. (Default: OBJECT_SELF)

bMustBeVisible

Should the returned object be visible to the calling object? (Default: TRUE)


Description

Returns the weakest member of oFactionMember's faction. If bMustBeVisible is set to TRUE (default) only consider members who can be seen by the caller of the function.

Returns OBJECT_INVALID if oFactionMember's faction is invalid.



Remarks

This should return the lowest hit dice monster in the faction.

This will work exactly the same was as using GetFirst/NextFactionMemeber() and using GetHitDice(), to find the lowest, only is much easier to code and probably better on performance.

Try to never use this on an NPC faction unless bMustBeVisible is TRUE, because NPC factions usually have dozens of NPC's, and thus may cause a lot of high CPU usage with faction calls such as this.


Version

1.62

Example

// Get the weakest PC and attack them. For all it matters, this
// could be the On Heartbeat script of a NPC.

void main()
{
    // Get nearest PC
    object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);

    // Get weakest
    object oWeakest = GetFactionWeakestMember(oFactionMember, TRUE);

    // Attack them
    if(GetIsObjectValid(oWeakest))
    {
        ClearAllActions();
        ActionAttack(oWeakest);
    }
}

See Also

functions: 

GetFactionStrongestMember



 author: John Shuell, editor: Jasperre, additional contributor(s): Jasperre