PDA

View Full Version : Scripts for NPC action. TSL


darthriddick
12-16-2007, 09:59 PM
EDIT: i swear no one looks at the (need help) threads anymore... whatever happened to common decency?
(sorry i'm just grumpy.)
EDIT#2: STOFFE RULES!!! ^_^

Hi, i'm working on a small storyline mod, and i am having some trouble with a certain NPC spawning, and then exiting, and destroying itself.
anyway, i need a script that can do this:

Check to see if item blahblah is the PC's inventory.
If it is in the inventory, spawn NPC.
If it is not, do nothing.
Once the PC has spoken with the NPC,
Remove item blahblah from inventory,
make NPC exit and destroy itself, and add an entry to the Journal.

any ideas?

~DR

stoffe
12-17-2007, 07:42 AM
EDIT: i swear no one looks at the (need help) threads anymore... whatever happened to common decency?
(sorry i'm just grumpy.)

People do have lives outside answering questions on internet forums you know. Expecting a reply within a few hours may be overly optimistic. :) Informing people that they suck because they don't answer quickly enough won't exactly encourage people to take time to help you at all. Patience is a virtue. :)



Hi, i'm working on a small storyline mod, and i am having some trouble with a certain NPC spawning, and then exiting, and destroying itself.
anyway, i need a script that can do this:

Check to see if item blahblah is the PC's inventory.
If it is in the inventory, spawn NPC.
If it is not, do nothing.
Once the PC has spoken with the NPC,
Remove item blahblah from inventory,
make NPC exit and destroy itself, and add an entry to the Journal.


That sounds like two different scripts, one that does the NPC spawning, and one that runs from the end of that NPC's dialog file making them leave.

The spawn script:

object ST_Spawn(string sResRef, float x, float y, float fFace) {
return CreateObject(OBJECT_TYPE_CREATURE, sResRef, Location(Vector(x, y, 0.0), fFace));
}


void main() {
object oPC = GetFirstPC();

if (GetIsObjectValid( GetItemPossessedBy(oPC, "blahblah") ) && !GetLocalBoolean(OBJECT_SELF, 40)) {
ST_Spawn("NpcToSpawn", 1.0, 2.0, 90.0);
SetLocalBoolean(OBJECT_SELF, 40, TRUE);
}
}


Change blahblah to the tag of the item to look for.
Change NpcToSpawn to the name of the UTC file with the NPCs template (without the .utc extension).
Change 1.0, 2.0 to the X, Y coordinates of where in the area to spawn the NPC.
Change 90.0 to the angle the NPC should be facing when spawned (0-360 degrees).


The exit script:

void ST_Exit(object oActor = OBJECT_SELF) {
object oExit = GetWaypointByTag("SW_EXIT");

AssignCommand(oActor, ActionForceMoveToObject(oExit));
AssignCommand(oActor, ActionDoCommand(SetCommandable(TRUE)));
AssignCommand(oActor, ActionDoCommand(DestroyObject(oActor)));
AssignCommand(oActor, SetCommandable(FALSE) );
}

void main() {
object oPC = GetFirstPC();

DestroyObject( GetObjectByTag("blahblah") );
AddJournalQuestEntry("JournalTag", 20);
ST_Exit( GetObjectByTag("NpcTag") );
}


Change blahblah to the tag of the item to remove.
Change JournalTag to the tag/name of the journal entry to set.
Change 20 to the quest stage to set the journal entry to.
Change NpcTag to the tag of the NPC to leave the area.

darthriddick
12-17-2007, 04:27 PM
Awesome. thanks stoffe. (i shall improve my patience master.) ^_^