Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

NPC Scripting help

Page: 1 of 1
 Beastamon
02-24-2008, 1:21 PM
#1
[K1]I am learning how to mod and scripting is very...confusing I was wondering how do you get a spawned NPC to walk up to another NPC and start a conversation when the PC is nearby.I tried to look in the scripting forum but got lost. :xp:
 Stream
02-24-2008, 3:53 PM
#2
Attach this script to the OnHeartbeat field of one of the NPC's, it will check to see if the player is within 5 metres of one of the NPC's, if he/she is then the NPC will walk to the other and then after 3 seconds start the conversation. It will also run the game standard heartbeat script for the NPC so it won't act different.

void main() {

object oNPC1 = GetObjectByTag("NPC1_TAG");
object oNPC2 = GetObjectByTag("NPC2_TAG");
object oPC = GetFirstPC();

ExecuteScript("k_def_heartbt01", OBJECT_SELF, 1002);

if ((GetDistanceBetween(oNPC, oPC) <= 5.0))
{

int bRun=FALSE;

AssignCommand(oNPC1, ClearAllActions());
AssignCommand(oNPC1, ClearAllActions());
AssignCommand(oNPC1, ActionMoveToObject(oNPC2, bRun, 15.0f));
DelayCommand(3.0, ActionStartConversation(GetFirstPC(),"DIALOG_FILE"));

ExecuteScript("k_def_heartbt01", OBJECT_SELF, 1002);
}
else {

ExecuteScript("k_def_heartbt01", OBJECT_SELF, 1002);
}
}

If the dialog is to be between both of the NPC's and not with the PC don't forget to set the Speaker & Listener fields in Dialog Editor to the corresponding NPC if not the dialog will look stupid.

--Stream
 Beastamon
02-24-2008, 8:54 PM
#3
Sorry to be a bother but it doesn't seem to be working, any advice?
 Stream
02-25-2008, 3:08 AM
#4
My bad, I put oNPC instead of oNPC1. This one will work;

void main() {

object oNPC1 = GetObjectByTag("NPC1_TAG");
object oNPC2 = GetObjectByTag("NPC2_TAG");
object oPC = GetFirstPC();

ExecuteScript("k_def_heartbt01", OBJECT_SELF, 1002);

if ((GetDistanceBetween(oNPC1, oPC) <= 5.0))
{

int bRun=FALSE;

AssignCommand(oNPC1, ClearAllActions());
AssignCommand(oNPC1, ClearAllActions());
AssignCommand(oNPC1, ActionMoveToObject(oNPC2, bRun, 15.0f));
DelayCommand(3.0, ActionStartConversation(GetFirstPC(),"DIALOG_FILE"));

ExecuteScript("k_def_heartbt01", OBJECT_SELF, 1002);
}
else {

ExecuteScript("k_def_heartbt01", OBJECT_SELF, 1002);
}
}

--Stream
Page: 1 of 1