BioWare Atari
BioWare Info BioWare Games Support Forums Visit the BioWare Store
Neverwinter Nights Home
Neverwinter Nights Home

Factions, Shouts and Attacking My Enemy

Intended Audience: For Builders
By David Gaider

[Printer Friendly / Syntax Highlight]

Just what is a faction?
A faction is one of three things: a party of player characters & their associates, a single player character who is not a member of a party & his associates or a group of NPC's or single NPC's that have been assigned to a set default relationship to other factions.

This is not to be mistaken with an 'organization', like a guild of thieves or a city's garrison. Players do not 'join' factions, and any organization could conceivably comprise of a number of factions.

What do factions do, then?
Just what they are supposed to do: set the default stance of the NPC towards other factions. The generic AI takes a stance of 'Friendly' or 'Hostile' and has the NPC react accordingly in its scripts. An NPC will maintain that default stance until and unless it is told to do otherwise.

What is probably most important to understand about factions, however, is that there is a difference between how the faction feels and how the individual NPC feels. If an individual NPC within a faction is attacked, he will go hostile and defend himself. He will remain hostile until told to do otherwise. The other members of his faction not present, however, will not necessarily go hostile along with him. This difference of standing towards someone is considered reputation, which is different from that someone's reputation with the faction. The NWScript commands, unfortunately, refer to both types of reputation in the same manner, so distinguishing between them can be tricky.

To better explain the difference, consider this:

A party of PC's is inside a tavern. The rogue in the party decides to attack a nearby peasant (who is a member of the Commoner faction). Upon being attacked, that peasant goes hostile to the rogue... and issues a shout to any nearby NPC's who are friendly to his faction to likewise go hostile to the rogue. The rest of the party hasn't done anything, yet, so nobody is hostile towards them.
If the rest of the party gets involved in the fight, the witnessing NPC's will likewise go hostile towards them. Let's say the entire party flees the tavern immediately and escapes their pursuers... those individuals who turned hostile towards the rogue (or other interfering party members) will remain hostile until told otherwise. Other members of the Commoner faction, however, will react normally.

The only way this wouldn't happen is when a faction has its 'Global Effect' box checked (this can be found in the Faction Editor). This eliminates individuals within a faction maintaining seperate relations... if you attack one and it goes hostile, all members of the faction go hostile. Any change to a single member's relationship affects the entire faction. (There are instances in module design where this is desireable... but be aware of it, especially due to the fact that new factions are global in effect by default.)

What does the standard AI do with factions?
To better understand why something is or isn't happening, here's a rundown on how factions affect the standard AI:

  • in the OnPerception event (which, remember, fires only when the target first comes into perception range or if the perception type changes), if the NPC perceives a hostile and is not already in combat it issues the "NW_I_WAS_ATTACKED" shout (see below) and attacks.
  • if the creature is attacked and it is not already in combat, it issues the "NW_I_WAS_ATTACKED" and "NW_ATTACK_ MY_TARGET" shouts and attacks its attacker.
  • if the creature is killed it automatically issues a "NW_ATTACK_MY_TARGET" and "NW_I_AM_DEAD" shout.

And what do these shouts do? For one thing, they are simply spoken words that the creature has been told to speak, the same as any PC typing words with their chat system. These shouts, however, are 'silent'... players don't hear them or see the floating text, but NPC's do, and the generic AI in the OnSpawn script tells them to listen for them and react. Shouts are not heard through walls or beyond doors, and do have a limited range.

  • the "NW_ATTACK_ MY_TARGET" shout only has an effect on those NPC's who have uncommented the line 'SetSpawnInCondition (NW_FLAG_SHOUT_ ATTACK_MY_TARGET);' in their OnSpawn script. If heard by an ally (one who's faction is friendly to the shouter), it sets the faction relationship to the shouter's attacker to hostile (if not already so), stops what it's doing and attacks any enemy within sight.
  • the "NW_I_WAS_ATTACKED" shout can be heard by anyone. If the listener is an ally of the shouter and is neither currently in combat nor has less than 10 Commoner levels, it will attack the attacker of the shouter.
  • the "NW_I_AM_DEAD" shout can also be heard by anyone. It's effect is the same as the 'I was attacked' shout above.

How do i make my npc's attack?
If a creature starts out as hostile and spots a PC, its OnPerception event will fire and it will immediately attack. No problem there. The situation arises fairly often, however, where you will have a NPC who was neutral to the PC when the OnPerception event fired and will become hostile through the course of a dialogue or scripting.

To turn a single NPC hostile to the PC and make him attack, you must first identify the target. In dialogue, this is easy:

object oTarget = GetPCSpeaker();

Outside of dialogue, in a normal script, it can vary:

object oTarget = GetNearestCreature (CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
// this targets the nearest player character to the caller of the script

object oTarget = GetLastPerceived();
// this is the last perceived object, only to be used inside the OnPerception event

The above are two possibilities. Regardless, once you've identified your target, you can call the rest of the commands as normal. For the following scripts, we'll assume that we're starting combat off of dialogue (by placing the script in the 'Actions Taken' section of the dialogue line where we want combat to start).

First, do I want the attacker to turn the whole faction hostile? To do so, I use this:

NWScript:

And that's it (this is also the "nw_d1_attonend" generic script). Should I just want the attacker to go hostile (and no-one else):

NWScript:

But suppose I have other friends nearby who I want to make part of the combat, as well? Even if I use AdjustReputation to make their faction hostile, they still won't attack. Why? Look at the cases under the generic AI... I wasn't attacked first and am already in combat, so I won't issue those shouts. We've all already perceived the PC, and he wasn't an enemy then. And I'm not dead... so my pals will sit there until attacked or until I'm dead.
I've got two choices. Either send them the command via AssignCommand like this:

NWScript:

Or like this:

NWScript:

There are also other variations to do the above... those are really just examples. Another easy way to start a group fight is to make sure all the combatants have the 'SetSpawnInCondition (NW_FLAG_SHOUT_ ATTACK_MY_TARGET);' line uncommented in their OnSpawn script. Then, when you start the attack, you can just do this:

NWScript:

You won't see the string displayed, but any allies within hearing range who can see the target will run to the attack.

Now how do i make my npc's neutral again?
If you want to make an NPC non-hostile once it's been in combat with the PC (usually if the PC has died or for plot reasons), you have to make sure two things have happened: one, that the faction's attitude towards the player is non-hostile (either neutral or friendly). Two, if the faction doesn't have 'Global Effect' checked, you have to clear the the NPC's personal feelings towards the PC.

The 'standard' factions in the game (Commoner, Defender, etc) are the only ones that can do both of these in one single command. This is done through the SetStandardFaction command, and an example of this is in the default death script ("nw_o0_death"), which re-sets all standard factions to neutrality on a player's death. (NOTE: Several people that have reported that the Defender faction is not re-set when this command is used, but can be re-set if treated as a custom faction below.)

For custom factions, you need two commands: AdjustReputation to change the faction's relationship with the target and ClearPersonalReputation to change an NPC's feelings. In both cases, you must single out a target that is a member of a faction (which may be difficult if you have many members with seperate tags or that may be dead)... custom factions aren't identified by name, you can only say 'the faction that so-and-so belongs to'. And if you want to clear the a PC's personal reputation with an entire custom faction, you have to cycle through it.

Here's an example script that will adjust a faction towards neutral and cycle through it, restoring every member to a normal relationship with the PC. This faction does not have its 'Global Effect' checked, obviously, and has members with the same tag "GOBLIN01". The PC has died and this script is within his OnDeath event:

NWScript:

Fun with shouts

A couple of things to try out or use, with regards to shouts.

First one: I always hate the fact that an NPC may hear the "NW_ATTACK_ MY_TARGET" shout... but they won't do anything if they can't see the shouter or the target. They go hostile, but won't attack until the enemy comes into sight. Here's a way I've successfully used to make out-of-sight listeners come to investigate the shout.

Step 1 - First thing that must be done is that all members of the faction who will respond to the shout and also investigate a shout from nearby must have their OnSpawn script set up accordingly. Go into their OnSpawn script and uncomment the following lines:
'SetSpawnInCondition (NW_FLAG_SHOUT_ ATTACK_MY_TARGET);'
'SetSpawnInCondition (NW_FLAG_ ON_DIALOGUE_EVENT);'
Then re-save the script under a different name.

Step 2 - Remember that a creature will only shout 'attack my target' if he is attacked first or killed. If you want him to shout it, himself, you'll have to put it into a script. There is one supplied in the examples above that has the creature go hostile and make the shout off of dialogue.

Step 3 - Put the following script into each creature's OnUserDefined event:

NWScript:

Second one: Here's an interesting exercise that demonstrates how to make your own shout. In this example, I want to have a dialogue that issues a shout and causes all who hear it to perform the 'worship' animation (they think the PC is the 'one foretold').

Step 1 - Let's set up the dialogue of the NPC who is going to issue the shout. Let's make it very simple... one line of dialogue which says "It is the One Foretold!!" and then the following script attached to the 'Actions Taken' area of that line:

NWScript:

Step 2 - we have to set up the other NPC's in the area to listen to the shout. This involves uncommenting the line 'SetSpawnInCondition (NW_FLAG_ ON_DIALOGUE_EVENT);' in their OnSpawn script as well as adding the following line anywhere:

SetListenPattern (OBJECT_SELF, "BOWDOWN", 100);

This makes the string 'BOWDOWN' equal to the number 100 (picked at random) and recognizeable should the NPC be listening (using the command SetListening (OBJECT_SELF, TRUE)... which is issues in the OnSpawn's SetListeningPatterns command, anyway).

Step 3 - now we just have to tell the NPC's what to do when they hear that command. Any spoken string sets off their OnDialogue event... so the following script can be placed into their OnUserDefined event:

NWScript:

This obviously isn't everything there is to know about factions and shouts, but hopefully the information is of use to some.

 

 

BioWare Store
Neverwinter Nights 2 Forums
Hide/Show

English
Deutsch
Français
Español
Italiano

Hide/Show

View Latest Screenshots 

View Latest Screenshots
Hide/Show

Multiplayer Games at Neverwinter Connections

Today
Schedule a Game...



Current time is: (set time)
Sat, 21 November 2009 11:17PM

Hide/Show

Buy Premium Modules

Top NWN: HotU Modules:
1. Good vs Evil III
2. More...

Top NWN: SoU Modules:
1. Good vs Evil III
2. More...

Top CEP Modules:
1. The Lord of Terror The Diablo Campa...
2. More...

Top Modules - NWVault:
1. Hall of Fame
2. More...

Total Modules: 4423

Hide/Show

5,047,980 BioWare Users:
  71 Logged In
  3 Hidden
  266 Guests

1492 Playing Online
  100% NWN
  100% NWN: SoU
  101% NWN: HotU

447 Registered Guilds

8,768,383 posts in forums

Newest Forum Topics:
1. Inferno armor available at Amaz... (Mass Effect 2 General Discussion (No Spoilers Allowed))

2. Will ME2 feature "ME1" or "DAO" ... (Mass Effect 2 General Discussion (No Spoilers Allowed))

3. conversation node spawning an it... (NWN2: Builders - NWN2 Scripting)

4. Stupid MAKO!! (Mass Effect 1 General Discussion (No spoilers allowed))

5. An Idea Realized and Marquee Abi... (Mass Effect 2 General Discussion (No Spoilers Allowed))