PDA

View Full Version : [K2] scripting an NPC into the game...


darthriddick
04-01-2007, 11:05 PM
hi y'all, i need to add an NPC into the game, and just stand there until i'm ready to talk to him.
i tryed using the add NPC script darth333 has in her add a npc in less than 10 steps tutorial, but this NPC is spawned during a fight, and that seems to mess up the script, as he will walk up to me but does not have any dialog options....

thanks!
~DR (the person that asks more questions than any other modder on the forums. XD)

stoffe
04-01-2007, 11:30 PM
hi y'all, i need to add an NPC into the game, and just stand there until i'm ready to talk to him.
i tryed using the add NPC script darth333 has in her add a npc in less than 10 steps tutorial, but this NPC is spawned during a fight, and that seems to mess up the script, as he will walk up to me but does not have any dialog options....


If you just want the NPC to stand there doing nothing in particular a simple script like this should work:

void main() {
vector vPos = Vector(0.0, 0.0, 0.0);
CreateObject(OBJECT_TYPE_CREATURE, "UTCFile", Location(vPos, 0.0));
}


Change the part in yellow to the X, Y and Z coordinates where the NPC should be spawned. Change the part in green to the name of the UTC file (without the .utc extension) containing the template for the NPC to spawn.

In the UTC template make sure you set the faction to Neutral (5) if you don't want the NPC to get involved in any nearby fights.

darthriddick
04-02-2007, 02:48 AM
ok, thanks stoffe, that part works now, but i need to have the NPC attack if a certain dialog path is chosen, and i'm not sure how exactly to do that...
anyway you (or someone else of course ^_^) could post a script for that as well?
thanks again
~DR

Pavlos
04-02-2007, 04:51 AM
ok, thanks stoffe, that part works now, but i need to have the NPC attack if a certain dialog path is chosen, and i'm not sure how exactly to do that...
anyway you (or someone else of course ^_^) could post a script for that as well?
thanks again
~DR

You could create a script like this

// a_playerattack.nss
/*
A script to cause NPC X to attack the player
*/
// 02/04/07

void main()
{

object oNPC = GetObjectByTag("MyNPCTag");
ChangeToStandardFaction(oNPC, STANDARD_FACTION_HOSTILE_1);

}

Or, if you are firing this from a dialogue node a_atkonend.nss (a generic script) can be used.

stoffe
04-02-2007, 07:36 AM
Depending on what situation the script is used in you may need to kick start the NPC's combat AI to get them in combat mode, making them attack and not just stand there hostile waiting to be attacked, if their OnPerception script does not fire to register that there are enemies nearby. You could do that by adding this line to Pavlos' script:


// a_playerattack.nss
/*
A script to cause NPC X to attack the player
*/
// 02/04/07

void main()
{

object oNPC = GetObjectByTag("MyNPCTag");
ChangeToStandardFaction(oNPC, STANDARD_FACTION_HOSTILE_1);
DelayCommand(0.5, ExecuteScript("k_ai_master", oNPC, 1003));
}

darthriddick
04-02-2007, 10:51 AM
YES! thanks guys!
it works perfectly.

Edit: Aww smeg.
there IS ONE mor thing actually. (course with me there always is. ^_^)

what i need now is after the npc hhas spawned, and after i have started talking to him, there will be a certain line that allows him to become a party member instead of dieing.
or at least that's what i was hoping it would do...
i tried using the add&replace NPC code used in darth333's tutorial, but i ran up against another problem.....(figures.) XD

anyway, my problem is that the listings are not the same in TSL as they are in K1
(for instance t3m4 is not listed as faction ID (7)

here is the code i was trying to use is this one here.

void main()
{
RemoveAvailableNPC(7);
AddAvailableNPCByTemplate(7, "p_nadd");
DelayCommand(1.5,ShowPartySelectionGUI());
}

(and the list)
BASTILA = 0
CANDEROUS= 1
CARTH = 2
HK_47 = 3
JOLEE= 4
JUHANI= 5
MISSION= 6
T3_M4 = 7
ZAALBAR = 8

I know i found the same list for TSL but i can't remember where, and i looked all over the forums, so if someone could post that, it'd be a great help.

DarthStoney
04-02-2007, 02:37 PM
here is the list for k2.

NPC numbers, as specified in NPC.2da

0 Atton
1 BaoDur
2 Mand
3 g0t0
4 Handmaiden
5 hk47
6 Kreia
7 Mira
8 T3m4
9 VisasMarr
10 Hanharr
11 Disciple