Beastamon Posted February 24, 2008 Share Posted February 24, 2008 [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. Link to comment Share on other sites More sharing options...
Stream Posted February 24, 2008 Share Posted February 24, 2008 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("[b]NPC1_TAG[/b]"); object oNPC2 = GetObjectByTag("[b]NPC2_TAG[/b]"); 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(),"[b]DIALOG_FILE[/b]")); 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 Link to comment Share on other sites More sharing options...
Beastamon Posted February 25, 2008 Author Share Posted February 25, 2008 Sorry to be a bother but it doesn't seem to be working, any advice? Link to comment Share on other sites More sharing options...
Stream Posted February 25, 2008 Share Posted February 25, 2008 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.