The enemy is in a custom faction with 50-neutrality towards players.
Area settings are Full PvP
Campaign is Players can attack Neutrals = True
How do you cast a spell at them? Inflict wounds, for example.
If you click spell then try to target, you can’t. Cursor is greyed out “Talk” icon.
first, a preliminary question : is this for NWN1, NWN1:EE, or NWN2 ?
[ @moderators : perhaps move this thread to the appropriate category depending on OP’s answer ? ]
bah… I thought I was posting in NWN2 > scripting
Can I move it, or someone else has to do that?
But it is NWN 2
This refers to the standard faction of NEUTRALS, and not “neutral” with respect to the PCs.
Also, you may want to turn the campaign option to FALSE, as it will affect every potential standard NEUTRAL faction creature if you turn your PCs to an “enemy” of such neutrals.
Better to have a “faction pig” (i.e. a creature with a dedicated faction setting towards players and others), which can be referred to to switch between “hostile” or this original faction.
But, to answer your question in brief… You need to…
Keep a unique faction that is (at first) friendly to players, which you can then turn to the standard HOSTILE faction or one of your own design that is hostile to PCs. When a creature is an “enemy” of another, that is when you can cast spells against it.
I use a loop to affect all creatures that I need to turn hostile when the time comes. The real trick is being able to distinguish between affected creatures and how they may also respond to one another if within the same area as the PC… who may have their own relationship with each faction. It gets complicated quite quickly.
The water starts getting deeper with factions.
Thank you Lance. That’s essentially what I did, but tell me what you think.
I made a herbivore faction, I set it 50 neutral against all other factions. I didn’t want the rabbits or deer to attack the player, or be attacked by hostile monsters.
However, I wanted player to be able to attack it, if desired, in order to get meat and hides.
I created the pig and gave him the herbivore faction.
If player right-clicks the wildlife, player can Attack. This is one of the standard options. This works, player can attack and kill.
Then I wanted it so that the animal could potentially run away rather than fight. I updated the On Attack, as below:
#include "x0_i0_position"
void main()
{
location lFlee = GetRandomLocation(GetArea(OBJECT_SELF));
object oHerbPig = GetObjectByTag("factionpig_herbivore");
int nRnd6 = d6();
//SendMessageToPC(GetLastAttacker(),IntToString(nRnd6) + " - I'm attacked!");
if (nRnd6 >3)
{
ChangeToStandardFaction(OBJECT_SELF,STANDARD_FACTION_HOSTILE);
}
else
{
ChangeFaction(OBJECT_SELF, oHerbPig);
ClearAllActions(TRUE);
AssignCommand(OBJECT_SELF,ActionForceMoveToLocation(lFlee,TRUE));
}
}
This script works as intended in my testing. The deer will half the time run away randomly, and half the time, turn around, lower the horns and fight.
But, the part that still eludes me, why I cannot cast a spell at the deer when she’s in “herbivore” faction and just milling around the woods.
PC cannot click spell and target the deer, cannot right-click the deer and cast spells while deer is still in Herbivore faction.
I understood it to mean that if other person/animal’s faction is between 11 and 89, that this would let PC attack. Is this not correct?
I am assuming 1-10 is hostile and 90-100 is friendly.
This is because any spells that are labelled “Hostile” in the 2da files cannot target a creature that is non-hostile to the heroes. i.e. A spell that has “Hostile” intentions cannot target any creature unless it is an enemy to the heroes.
I think this may be incorrect, but it’s been a while since I tested this in my own module.
Basically, if you enable “can target neutrals”, in the campaign editor, then I believe you may be able to target the standard NEUTRAL faction creatures, but still not any creature that happens to be “neutral” to the party at faction comparison time. This is also why I avoid using this campaign switch.
The only way I have been able to do what you are trying to do, is to either switch the creature (or creatures involved via a loop) from their current faction (even if it is “neutral” to the PCs) to a “hostile” setting (even if not using the standard HOSTILE faction).
As I also warn above, then further reactions may occur if a creature with your new faction has variations with other factions, which in turn can impact situations with the PC. This is my approach…
A) Try to keep an area with no more than three potential “faction” types.
B) If wanting a faction to switch between friendly/hostile, then either switch from a"faction pig" faction that you have designed to be neutral to the PCs to another “faction pig” that is hostile to the PCs.
C) If a third group is nearby, be sure that this third group can remain “neutral” to both sides or is goes awry very quickly - I try to avoid potential third groups.
This is all with the campaign editor “can attack neutrals” as FALSE. Otherwise, it complicates matters further.
Bottom line: Faction from friendly to hostile (to allow spell casting) can be done, but that deliberate attempt by the PC on the otherwise friendly target requires a manual switch to allow this to happen.
I have a few examples of faction setups in my module, The Scroll, (which if you wanted to see how I set it up) also includes PCs turning “guards” hostile either by encounter, or deliberately by the player with a switch. The PCs can also switch nearby friendly villagers “hostile” to them via the same switch, while maintaining neutral/friendly with nearby others. (Just in case they wanted to attack someone, like your trying to do.)
See image where I employ such a possibility …
IDEA: I suppose you may be able to do something like use a “stone” to target a location on the ground near a creature, which then turns it hostile … Then PCs will be able to target their spells at it. i.e. Bypass the XML approach by employing a “throw stone” near to it to antagonise it. Or even “blow a horn” that affects all creatures within its range (turning them “hostile”).
Lance, thank you for the well-thought-out, detailed reply, I appreciate it.