From NWN Lexicon
Jump to navigationJump to search
Red bug icon.png Warning: This function has a known bug and may not work as expected in some situations. See Known Bugs for details.


Get the average number (between 0 and 100 inclusive) of the all objects within the object's faction that represents the Good/Evil alignment

int GetFactionAverageGoodEvilAlignment(
    object oFactionMember



The creature or object whose faction average you wish to examine.


This will search the module for all members of the object's faction and average out their Good/Evil alignment. The return value is an alignment constant (e.g. ALIGNMENT_EVIL) not a number on the 0-100 scale. Party members are included for player characters. -1 is returned if the object is invalid.

Known Bugs

While this works for factions with a single member (identical to GetAlignmentGoodEvil), if there are multiple members to a faction then ALIGNMENT_EVIL is returned if all members are evil and ALIGNMENT_GOOD if at least one member is neutral or good.




// Check the faction alignment of the PC's party, using a trigger.
// It will make some NPC's go hostile if they are considered to be
// evil on average.

// Of course, it is kinda OOC knowledge. This function is more likely
// to be used in other ways.

void main()
    // Get the entering object
    object oPC = GetEnteringObject();
    string sLocal = "DO_ONCE" + ObjectToString(OBJECT_SELF);

    // Only do this once, only affects PC's
    if(GetLocalInt(oPC, sLocal) || !GetIsPC(oPC)) return;

    // Set to not do it again
    SetLocgalInt(oPC, sLocal, TRUE);

    // Check alignment - must be very evil!
    if(GetFactionAverageGoodEvilAlignment(oPC) == ALIGNMENT_EVIL)
        // Get the town guard onto them
        object oGuard = GetNearestObjectByTag("TOWN_GUARD");

        // Attack!
        AdjustReputation(oPC, oGuard, -100);

        // Do an attack
        AssignCommand(oGuard, ActionAttack(oPC));

See Also



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