Jump to content

Home

NPC Scripting help


Beastamon

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...