Faction Futility! (Resolved)

Hi All,

I have a village of “COMMONERS” and a script that turns them to another faction (my own) that is hostile to the PCs.

Yet, after turning them to the new faction and becoming hostile to the PCs, when scripted to attack, they simply run away! The cowards! :wink:

Now, I recall reading somewhere about the commoner faction, and so I allocated my own “MYCOMMONER” faction and did the same thing - and they still ran away. Nearby NPCs with different factions (DEFENDER and MERCHANT) did NOT run away, and attacked as expected.

All NPCs had been turned and asked to attack by the same script. The problem is that some did so (the brave ones) and the others simply ran away.

What am I missing here?

I even tried adjusting reputation and double checked the faction table.

EDIT: As another test, I converted all the villagers to MERCHANT (same as the merchants) and they still acted differently to the “natural” merchants.

EDIT: Also, there is a “companion” NPC who is also “COMMONER” faction, but DOES respond correctly. The whole thing is most strange and appears to have a life of its own.

Thanks in advance, Lance.

it sorta sounds like they have a SpecialBehavior set (usually by a spawn script)

have a look at ‘x0_i0_behavior’

// Special Behaviors master int
const string VAR_BEHAVIOR_MASTER = "NW_BEHAVIOR_MASTER";

// Special Behavior flags
const int NW_FLAG_BEHAVIOR_SPECIAL   = 0x1;
const int NW_FLAG_BEHAVIOR_CARNIVORE = 0x2; // will always attack regardless of faction
const int NW_FLAG_BEHAVIOR_OMNIVORE  = 0x4; // will only attack if approached
const int NW_FLAG_BEHAVIOR_HERBIVORE = 0x8; // will never attack, will always flee.

what those behaviors really do is determined by the core AI scripts …

poke around a bit, i guess

hint: There’s usually a different function call between HenchDetermineCombatRound() and HenchDetermineSpecialBehavior() [or the nwn1 equivalents] in their OnHeartbeat, OnAttacked, OnPerception etc scripts. The former call attacks, the second may attack

1 Like

Hi KevL,

Yes, I saw those, and commented them out … but (you know what), I think I may have tested on a reload of a game after they had already spawned! Doh!

I’ll head back that way and take another look. Thanks for pointing it out to me again.

I’ll post back if further testing resolves what I am trying to do around this.

Cheers, Lance.

EDIT: Ah, no this is what I found there. I had already ensured it does not fire unless I say so … I will, however, possibly try commenting out the entire spawn script and restarting them.

EDIT 2: Edited script to hopefully make more sense. :slight_smile:

////////////////////////////////////////////////////////////////////////////////////////
	// OWN GENERIC SYSTEM : SET "SPECIALBEHAVIOUR" TO 1 FOR HERBIVORE OR 2 FOR OMNIVORE
	////////////////////////////////////////////////////////////////////////////////////////
	
	if (GetLocalInt(OBJECT_SELF, "SPECIALBEHAVIOUR") != 0)
	{
		SetBehaviorState(NW_FLAG_BEHAVIOR_SPECIAL);
		if (GetLocalInt(OBJECT_SELF, "SPECIALBEHAVIOUR") == 1)
		{SetBehaviorState(NW_FLAG_BEHAVIOR_HERBIVORE);}
		else {SetBehaviorState(NW_FLAG_BEHAVIOR_OMNIVORE);}	                               
	}

that block doesn’t really make sense, Lance. It says that if the code gets inside the block, the first case within the block is always true. Ie, that code can only set HERBIVORE true …

not that this is really the issue … so

 
you could quickly check (or change) the behavior states of creatures with a console script

// 'checkbehavior'
/*
    Console script.
    Checks or clears behavior states on all creatures in the current area.
    bClear - "0" to print only. "1" to clear behavior states on all creatures.
*/

void main(int bClear)
{
    if (!bClear)
    {
        object o = GetFirstObjectInArea();
        while (GetIsObjectValid(o))
        {
            if (GetObjectType(o) == OBJECT_TYPE_CREATURE)
                SendMessageToPC(GetFirstPC(FALSE), GetName(o) + " beh= " +
                                    IntToString(GetLocalInt(o, "NW_BEHAVIOR_MASTER")));

            o = GetNextObjectInArea();
        }
    }
    else
    {
        object o = GetFirstObjectInArea();
        while (GetIsObjectValid(o))
        {
            if (GetObjectType(o) == OBJECT_TYPE_CREATURE)
                DeleteLocalInt(o, "NW_BEHAVIOR_MASTER");

            o = GetNextObjectInArea();
        }
    }
}

Iirc anything with the class of Commoner or whatever the non class class is called is set to run away in case of hostility.

1 Like

i recall that too but can’t remember where. I remember something about if there’s a level 10+ commoner nearby, the other commoners will band together with it and attack

It’s confusing because there’s commoner faction and commoner class …

Hi All,

@KevL I agree that that code makes no sense to me too. I never had the main var set anywhere anyway, and so nothing was being set … That was my main thrust. :wink: I will be sorting that bit out a little later.

You are both recalling the points I remember reading somewhere too. I just cannot recall if there was anything more about turning that off as well. However, it is strange that a potential companion running “mostly” the same scripts when not owned, and also commoner faction did fight back!

It’s late here now, so I will look at this more tomorrow … and that script.

Edit: KevL… Can you remind me how to employ a console script? Something to do with #runscript naneofscript … Is it that you have not named it that is confusing me . … :grin:

Must sleep now though. :zzz:

Thanks for helping me.
Lance

hey Lance,

scriptname above : “checkbehavior.nss” (takes an int parameter)

from the chatbox –
##debugmode 1
##rs checkbehavior(0)
##debugmode 0

or from the console (apostrophe opens the console)
`
debugmode 1
rs checkbehavior(0)
debugmode 0
`

pass in “1” instead of “0” to delete the NW_BEHAVIOR_MASTER variable from creatures in the current area.

note: “rs” is shorthand for “RunScript”

1 Like

Hi All,

OK … I read posts with fresh eyes and a slightly clearer mind and am going to try changing the class from commoner to something else, as that is something that I have not done yet … and is something that as we discussed, rings a bell for me.

@KevL: Thanks for the reminder on how to employ that script … And it is good to know that it can be run directly from the CHAT window … That, I did not know. :slight_smile:

Success … Changing the class to humanoid makes the villagers fight back! Thank you all for helping me and reminding me what made the difference. Thanks Kamal!

Cheers, Lance.

Hi Again,

I ran that script from the chat window (great to know) and noticed the results … my next obvious question is … when is that variable that we are checking “NW_BEHAVIOR_MASTER” ever set … Is that one of the creatures spawn/AI setting somewhere? I am guessing it is, but just wanted confirmation. :slight_smile:

EDIT: OK, I found it … It’s been a while since I looked at this area … spawn scripts!

EDIT 2: I changed that “TRUE” to “1” in the script above, so hopefully that will make sense and work now. :slight_smile:

Thanks, Lance.

1 Like