[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:
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
Sorry to be a bother but it doesn't seem to be working, any advice?
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