/////////////////////////////////////////////////////////////
// NPC ACTIVITIES 5.0 - Dynamic Script Wrapper
// For the NPC Event:OnSpawn
//-----------------------------------------------------------
// By Deva Bryson Winblood  - 01/2003
/////////////////////////////////////////////////////////////
// If you use this wrapper you should NEVER need to change it
// again.  If you read the documentation that came with NPC
// ACTIVITIES 5.0 it explains how to change this script at any
// moment and as many times as you like from within the game
// while it is running.  This makes this system dynamic rather
// than static.
//////////////////////////////////////////////////////////////

#include "npcactivitiesh"

string fnPhraseMaker()
{ // phrase maker
  string sRet="";
  string sAdd;
  int nL=0;
  int nR;
  while(nL<4)
  {
    nR=d20();
    sAdd="";
    if (nR==1) sAdd="IA";
    else if (nR==2) sAdd="AZAG";
    else if (nR==3) sAdd="OKAK";
    else if (nR==4) sAdd="ROS";
    else if (nR==5) sAdd="LIL";
    else if (nR==6) sAdd="ARN";
    else if (nR==7) sAdd="ZOM";
    else if (nR==8) sAdd="PAZ";
    else if (nR==9) sAdd="LIT";
    else if (nR==10) sAdd="MAZ";
    else if (nR==11) sAdd="DEO";
    else if (nR==12) sAdd="ZID";
    else if (nR==13) sAdd="ZIP";
    else if (nR==14) sAdd="VAL";
    else if (nR==15) sAdd="ARS";
    else if (nR==16) sAdd="AIQ";
    else if (nR==17) sAdd="'";
    else if (nR==18) sAdd="ZAX";
    else if (nR==19) sAdd="TOR";
    else if (nR==20) sAdd="IX";
    sRet=sRet+sAdd;
    nL++;
  }
  return sRet;
} // fnPhraseMaker()

void main()
{
    string  sScriptToUse=GetLocalString(OBJECT_SELF,"sCRSPSpawn");
    string sPost="POST_"+GetTag(OBJECT_SELF);
    object oPost=GetNearestObjectByTag(sPost);
    string sByTag=GetTag(OBJECT_SELF)+"_SPAWNC";
    string sByRes=GetResRef(OBJECT_SELF)+"_SPAWNR";
    object oMod=GetModule();
    object oSpecial=GetNearestObjectByTag(sByTag);
    SetLocalString(oMod,"sTamrilPhrase1",fnPhraseMaker());
    SetLocalString(oMod,"sTamrilPhrase2",fnPhraseMaker());
    SetLocalString(oMod,"sTamrilPhrase3",fnPhraseMaker());
    SetCustomToken(90003,GetLocalString(oMod,"sTamrilPhrase1"));
    SetCustomToken(90004,GetLocalString(oMod,"sTamrilPhrase2"));
    SetCustomToken(90005,GetLocalString(oMod,"sTamrilPhrase3"));
    if (oPost==OBJECT_INVALID) oPost=GetObjectByTag(sPost);
    if (oSpecial==OBJECT_INVALID) oSpecial=GetObjectByTag(sByTag);
    if (oSpecial==OBJECT_INVALID) oSpecial=GetNearestObjectByTag(sByRes);
    if (oSpecial==OBJECT_INVALID) oSpecial=GetObjectByTag(sByRes);
    if (GetStringLength(sScriptToUse)<2&&oSpecial!=OBJECT_INVALID) sScriptToUse=GetName(oSpecial);
    if (GetStringLength(sScriptToUse)>1)
    { // has a specified script
      ExecuteScript(sScriptToUse,OBJECT_SELF);
    } // has a specified script
    else if (oPost!=OBJECT_INVALID)
    { // run the npc activities scripts
      ExecuteScript("gennpc_spawn",OBJECT_SELF);
    } // run the npc activities scripts
    else
    { // run the Bioware default - non henchman
      ExecuteScript("nw_c2_default9",OBJECT_SELF);
    } // run the Bioware default - non henchman
    SetListening(OBJECT_SELF,TRUE);
    SetListenPattern(OBJECT_SELF,GetLocalString(oMod,"sTamrilPhrase1"),112670);
    SetListenPattern(OBJECT_SELF,GetLocalString(oMod,"sTamrilPhrase3"),112671);
}