Page 1 of 1

Attacking NPC triggers encounter?

Posted: Fri Apr 27, 2007 1:04 am
by szabot
Can that be done, and if so, how?

What I have in mind is this: a PC is talking to an NPC; the conversation turns hostile; when the NPC turns hostile to the PC, this triggers an encounter, with a spawn point nearby. In other words, if you attack the NPC, or get him upset enough to attack you, a bunch of creatures spawn nearby to support him.

How do I do that? (And, I need details: *doesn't know scripting*)

Thanks. :)

Posted: Fri Apr 27, 2007 2:11 am
by Xiaou
I know its possible and has been possible since the game came out. As to how its done..I dunno.

Posted: Fri Apr 27, 2007 2:32 am
by Alexandru Stanicu
try playing with the conversation calling a script that spawns the critters. :)

Posted: Fri Apr 27, 2007 2:55 am
by szabot
Alexandru Stanicu wrote:try playing with the conversation calling a script that spawns the critters. :)
Ok, that's a good start, thanks. :)

I can have the NPC take an action when the PC says something, and that action can be to attack, which also fires an attack script.

Now the trick is to add to the script so it will summon creatures. That's the part I really have no idea about. :P

The generic "attack" script is:
#include "nw_i0_generic"

void main()
{

// Set the faction to hate the player, then attack the player
AdjustReputation(GetPCSpeaker(), OBJECT_SELF, -100);
DetermineCombatRound(GetPCSpeaker());
}
What do I add to summon critters?

However...hrm...I would also want the creatures to be summoned if a PC attacks the NPC without speaking to it first. Hm.

Posted: Fri Apr 27, 2007 3:06 am
by Alexandru Stanicu

Code: Select all

void main()
{

object oPC = GetPCSpeaker();

object oTarget;
object oSpawn;
location lTarget;
oTarget = oPC;

lTarget = GetLocation(oTarget);

oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "nw_skeleton", lTarget);

oTarget = oSpawn;

SetIsTemporaryEnemy(oPC, oTarget);

AssignCommand(oTarget, ActionAttack(oPC));

AssignCommand(oTarget, DetermineCombatRound(oPC));

}

That snippet above will spawn a skeleton (bioware standard skele) next to the PC ad nthen it will attack.

A little tweaking and you should be good...you can also spawn them at a WP instead of next to the PC, and you cna add a visual effect if needed/wanted.

(creature must be specified by resref.)

As far as attacking when the NPC is attacked, just write the script and add it to the correct event (IIRC its something like on_attacked)

Posted: Fri Apr 27, 2007 3:16 am
by szabot
Ooooh, that's awesome, and it worked, too. :)

Could this part:
oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "nw_skeleton", lTarget);
...be changed to trigger an encounter instead (so that it will summon multiple creatures, and they'll depend on the level of the PC)?

Hm, also: the NPC and summoned creature are attacking one another. Possibly because the NPC is commoner faction? Any way around that?

Posted: Fri Apr 27, 2007 10:53 am
by Alexandru Stanicu
You can play with it firing trigger.

As for the NPC and the spawn attacking each other, try ahving the script change the NPC's faction to hostile. :)

Posted: Fri Apr 27, 2007 1:02 pm
by Deider
Unless it's been changed in an update, the CreateObject function can't create triggers. This was a thorn in the side of folks who wanted to make their own custom encounter systems for many years. And in your case, you really don't want a trigger anyway, because for a trigger to be activated a PC has to step over it, and he can't step over a trigger if he's talking to an NPC, now can he? Better to use Alex's method, just substitute the skeleton for a function that calls a bunch of creatures to beat up on the PC.

Oh yeah, take this post with a grain of salt, because I'm drunker than Tigg's mom after she's gotten a new ass tattoo.

Posted: Fri Apr 27, 2007 1:55 pm
by Papainhell
Create a normal spawn and set it to false, then when the conversation goes hostile set the spawn to true, then delay and reset back to false for reset.

Posted: Fri Apr 27, 2007 2:00 pm
by Nob
OnUserDefined.

Posted: Fri Apr 27, 2007 4:02 pm
by szabot
Thanks, all. I really need details, though. Basically, I need someone to write the script for me, because I do not know how to write them (is there a resource somewhere for learning how to do that?). All I can give in return is a heap of thanks and credit in the comments for the script. :)

So far, using what Alex posted, except: changed the skele out for an ooze, but I still want many oozes; added back in the AdjustReputation line, because with Alex's code, the NPC didn't turn hostile.

So:

Code: Select all

void main()
{

object oPC = GetPCSpeaker();

object oTarget;
object oSpawn;
location lTarget;
oTarget = oPC;

lTarget = GetLocation(oTarget);

oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "pud_blk_eld", lTarget);

oTarget = oSpawn;

SetIsTemporaryEnemy(oPC, oTarget);

AdjustReputation(GetPCSpeaker(), OBJECT_SELF, -100);

AssignCommand(oTarget, ActionAttack(oPC));

AssignCommand(oTarget, DetermineCombatRound(oPC));

}
Alexandru Stanicu wrote:As for the NPC and the spawn attacking each other, try ahving the script change the NPC's faction to hostile. :)
The code does make the NPC hostile, but does that mean his ~faction~ becomes hostile, too? If so, why would he and the ooze attack one another? If not, what line do I need to add to change his faction?
Deider wrote:Better to use Alex's method, just substitute the skeleton for a function that calls a bunch of creatures to beat up on the PC.
How do I make it summon a bunch of creatures rather than just one?
Papainhell wrote:Create a normal spawn and set it to false, then when the conversation goes hostile set the spawn to true, then delay and reset back to false for reset.
That's all Greek to me. :P

Thanks again. ;)

Posted: Fri Apr 27, 2007 4:14 pm
by Kinarr
Sounds like a good opportunity for you to learn how to script. ;)

This is a little outdated, but still the best resource for learning how to script, and you'll always refer back to it:
http://nwnlexicon.avlis.org/lexicon/

Get the downloadable version here:
http://nwvault.ign.com/View.php?view=Ot ... ail&id=298

Posted: Fri Apr 27, 2007 4:18 pm
by Tigg
Deider wrote:Oh yeah, take this post with a grain of salt, because I'm drunker than Tigg's mom after she's gotten a new ass tattoo.
OK liephus, I'll take it with a grain of salt, heh. Hopefully I'm immune to mom jokes by now. ;)

Posted: Thu Jun 07, 2007 5:36 pm
by szabot
Thanks for all who have helped so far. I've got it to the below:

Code: Select all

#include "nw_i0_generic"

void main()
{

object oPC = GetPCSpeaker();

object oTarget;
object oSpawn;
location lTarget;
oTarget = oPC;

lTarget = GetLocation(oTarget);

oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "pud_blk_eld", lTarget);

oTarget = oSpawn;

oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "ZEP_BLACKPUDDL", lTarget);

oTarget = oSpawn;

oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "ZEP_BLACKPUDDL", lTarget);

oTarget = oSpawn;

ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_HOSTILE);

SetIsTemporaryEnemy(oPC, oTarget);

AssignCommand(oTarget, ActionAttack(oPC));

AssignCommand(oTarget, DetermineCombatRound(oPC));

}
It summons the creatures, turns the NPC to hostile (so he is the same faction as the summoned creatures), but he usually just stands there instead of attacking the PC (although sometimes he will start attacking). Any idea what's going on with him not always attacking right away?

Thanks!

Posted: Thu Jun 07, 2007 5:41 pm
by PsiOmega
Try to add the line "AssignCommand(oTarget, ClearAllActions());" without the quotes before the other two AssignCommand lines.

That should sort it out.

Posted: Thu Jun 07, 2007 5:59 pm
by szabot
That worked, thanks! :good:

Posted: Thu Jun 07, 2007 6:12 pm
by girlysprite
Also lookfor Lilcas script generator in the nwnvault. great help for both simple and complex scripting.

Posted: Sun Sep 16, 2007 1:28 am
by badjabadjabadja
..translation from Girlysprite's post

look for Lilac Soul's script generator

//end translation

((sorries GS.. couldn't resist :P ))

This tool lets you create scripts even if you can't script at all!

:D