// Team monitor - this makes sure there is always a leader
// if one does not exist then it will try to promote a sub-leader
// This also adjusts reputations based on leaders friend, enemy settings
// It also insures units of team not hostile on a sub_leader basis
//////////////////////
#include "header_sounds"
//////////////////////
// PROTOTYPES
//////////////////////
string fnRemParsed(string sO, string sP);
void fnSetFactionToFriendly(object oPC,string sID);
string fnParsePeriod(string sIn);
void fnAnnounce(string sMsg="",int nOption=0);
void fnTeamSelect(object oPC);
string fnGetTeamID(int nC);
void fnRecordInventory(object oPC);
void fnPartyCheck();
void fnMultiTeamCheck(object oPC);

//////////////////////////////////////////////////////////// MAIN
void main()
{
   object oMod=GetModule();
   object oPC;
   string sID;
   object oLead;
   string sInfo;
   int nC=1;
   object oH;
   int nNum;
   int nRep;
   object oMyTeam;
   float fDist;
   SetLocalInt(oMod,"nMonitorOn",TRUE);
   sID=fnGetTeamID(nC);
   while(sID!="NA")
   { // process team
     oLead=GetLocalObject(oMod,"oTeamLead"+sID);
     if (GetIsPC(oLead)==TRUE&&GetLocalInt(oLead,"bPermaDead")!=TRUE)
     { // record resources
       nNum=GetGold(oLead);
       SetLocalInt(oMod,"nGoldStore"+sID,nNum);
       nNum=GetLocalInt(oLead,"nManaStore");
       SetLocalInt(oMod,"nManaStore"+sID,nNum);
       nNum=GetLocalInt(oLead,"nSoulStore");
       SetLocalInt(oMod,"nSoulStore"+sID,nNum);
       // make sure have tools
       if (GetItemPossessedBy(oLead,"RTSCreation_Tool")==OBJECT_INVALID)
       { // create command tool
         oH=CreateItemOnObject("rtscreation_tool",oLead);
       } // create command tool
       if (GetItemPossessedBy(oLead,"RTSUnit_Creation")==OBJECT_INVALID)
       { // create command tool
         oH=CreateItemOnObject("rtsunit_creation",oLead);
       } // create command too
       if (GetItemPossessedBy(oLead,"rts_it_teamwand")==OBJECT_INVALID)
       { // create team wand
         oH=CreateItemOnObject("rts_it_teamwand",oLead);
       } // create team wand
     } // record resources
     else if (GetIsPC(oLead)&&GetLocalInt(oLead,"bPermaDead"))
     { // dead
       oLead=OBJECT_INVALID;
       DeleteLocalObject(oMod,"oTeamLead"+sID);
     } // dead
     if (GetItemPossessedBy(oLead,"rts_it_vote")==OBJECT_INVALID)
       { // voting tool
         oH=CreateItemOnObject("rts_it_vote",oLead);
       } // voting tool
     if ((oLead==OBJECT_INVALID||GetIsPC(oLead)==FALSE)&&(!GetIsPossessedFamiliar(GetAssociate(ASSOCIATE_TYPE_FAMILIAR,oLead))))
     { // look for PC to promote to leader
       nNum=FALSE;
       oPC=GetFirstPC();
       while(oPC!=OBJECT_INVALID&&nNum==FALSE)
       { // look for promotion
         if (GetLocalString(oPC,"sTeamID")==sID&&GetLocalInt(oPC,"bPermaDead")!=TRUE) nNum=TRUE;
         if (nNum==FALSE) oPC=GetNextPC();
       } // look for promotion
       if (nNum==TRUE)
       { // promote oPC to leader
         fnTeamSelect(oPC);
         oLead=oPC;
       } // promote oPC to leader
     } // look for PC to promote to leader
    /// check reputations
    /* oPC=GetFirstPC();
     while(oPC!=OBJECT_INVALID&&GetLocalString(oPC,"sTeamID")==GetLocalString(oLead,"sTeamID"))
     { // adjust reputation
       oH=GetFirstPC();
       while(oH!=OBJECT_INVALID)
       { // set enemies & friends
         if (GetIsFriend(oH,oLead)==TRUE||GetIsNeutral(oH,oLead)==TRUE||GetLocalString(oPC,"sTeamID")==GetLocalString(oH,"sTeamID")||oH==oLead)
         { // friend
           if (oPC!=oH&&GetIsFriend(oH,oPC)==FALSE)
           { // not yourself
             SetPCLike(oPC,oH);
             SendMessageToPC(oPC,"Had to make you like '"+GetName(oH)+".'");
           } // not yourself
         } // friend
         else
         { // enemy
           if (oH!=oPC&&GetIsEnemy(oH,oPC)==FALSE)
           { // not yourself
             SetPCDislike(oPC,oH);
             SendMessageToPC(oPC,"Had to make you dislike '"+GetName(oH)+".'");
           } // not yourself
         } // enemy
         oH=GetNextPC();
       } // set enemies & friends
       fnSetFactionToFriendly(oPC,sID);
       oPC=GetNextPC();
     } // adjust reputation   */
     // end of that team
     nC++;
     sID=fnGetTeamID(nC);
   } // process team
   /// Record Player Information
   oPC=GetFirstPC();
   while(oPC!=OBJECT_INVALID)
   { // !OI
     if (GetIsDM(oPC)==FALSE)
     { // not DM
     nRep=1;
     sID=GetLocalString(oPC,"sTeamID");
     oMyTeam=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oPC,nRep,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_ENEMY);
     fDist=GetDistanceBetween(oMyTeam,oPC);
     while(oMyTeam!=OBJECT_INVALID&&fDist<30.0)
     { // adjust rep if same team
       if (sID!=""&&sID==GetLocalString(oMyTeam,"sTeamID"))
       {
        if (fDist<10.0) AssignCommand(oMyTeam,ClearAllActions(TRUE));
        ClearPersonalReputation(oPC,oMyTeam);
        AdjustReputation(oPC,oMyTeam,100);
        SetIsTemporaryFriend(oPC,oMyTeam);
        SetIsTemporaryFriend(oMyTeam,oPC);
        if (GetAbilityScore(oMyTeam,ABILITY_INTELLIGENCE)>7)
          AssignCommand(oMyTeam,SpeakString("You are forgiven "+GetName(oPC)+"."));
       }
       nRep++;
      oMyTeam=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oPC,nRep,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_ENEMY);
      fDist=GetDistanceBetween(oMyTeam,oPC);
     } // adjust rep if same team
     sInfo=GetName(oPC)+GetPCPlayerName(oPC);
     SetLocalInt(oMod,sInfo,GetXP(oPC));
     SetLocalObject(oMod,sInfo+"loc",GetArea(oPC));
     fnRecordInventory(oPC);
     DelayCommand(2.0,fnMultiTeamCheck(oPC));
     } // not DM
     oPC=GetNextPC();
   } // !OI
   DelayCommand(6.0,fnPartyCheck()); // make sure opposing teams not part of a party
   DelayCommand(24.0,ExecuteScript("team_monitor",OBJECT_SELF));
}
///////////////////////////////////////////////////////////////// MAIN


///////////////////////
// FUNCTIONS
///////////////////////
void fnMultiTeamCheck(object oPC)
{ // make sure not liked by more than one team
  string sID=GetLocalString(oPC,"sTeamID");
  object oMod=GetModule();
  string sIDO;
  object oWP;
  object oTemp;
  object oCloak=GetItemInSlot(INVENTORY_SLOT_CLOAK,oPC);
  string sCTag=GetTag(oCloak);
  int bInfiltrate=FALSE;
  int nC=1;
  if (sCTag=="rts_it_op6"||sCTag=="rts_it_op7"||sCTag=="rts_it_op8"||sCTag=="rts_it_op9")
  { // wearing infiltrator cloak
    sCTag=GetStringRight(sCTag,1);
    if (sCTag=="6") sCTag="UNC";
    else if (sCTag=="7") sCTag="UND";
    else if (sCTag=="8") sCTag="SPID";
    else if (sCTag=="9") sCTag="DWF";
    bInfiltrate=TRUE;
  } // wearing infiltrator cloak
  sIDO="SPID";
  while(nC<5)
  {
    if (sID!=sIDO)
    { // check
     if (!bInfiltrate||(bInfiltrate&&sCTag!=sIDO))
     { // not infiltrating
      if (GetLocalObject(oMod,"oTeamLead"+sIDO)==oPC)
      {
        SendMessageToPC(oPC,"You were set as leader to "+sIDO+" team as well.  This has been fixed.");
        DeleteLocalObject(oMod,"oTeamLead"+sIDO);
      }
      oWP=GetWaypointByTag(sIDO+"_RESOURCES");
      oTemp=CreateObject(OBJECT_TYPE_CREATURE,sIDO+"0",GetLocation(oWP));
      if (GetIsEnemy(oPC,oTemp)==FALSE)
      { // set as enemy
        AdjustReputation(oPC,oTemp,0);
        SendMessageToPC(oPC,"Fixed reputation with "+sIDO+" team so, they are enemies.");
      } // set as enemy
      DestroyObject(oTemp);
     }// not infiltrating
    } // check
    // next
    nC++;
    if (nC==2) sIDO="DWF";
    else if (nC==3) sIDO="UNC";
    else if (nC==4) sIDO=="UND";
    else { sIDO="NA"; }
  }
} // fnMultiTeamCheck()

void fnPartyCheck()
{ // don't allow people to join into parties when on opposing teams
  object oPC=GetFirstPC();
  object oPartyMemb;
  string sID;
  object oMod=GetModule();
  while(oPC!=OBJECT_INVALID)
  { // !OI
    if (GetIsDM(oPC)==FALSE)
    { // not DM
    sID=GetLocalString(oPC,"sTeamID");
    if (GetLocalObject(oMod,"oTeamLead"+sID)==oPC)
    { // this is the leader
      oPartyMemb=GetFirstFactionMember(oPC);
      while(oPartyMemb!=OBJECT_INVALID)
      { // !OI
        if (GetLocalString(oPartyMemb,"sTeamID")!=sID)
        { // kick off party
          RemoveFromParty(oPartyMemb); // opposing teams not allowed to be party
        } // kick off party
        oPartyMemb=GetNextFactionMember(oPC);
      } // !OI
    } // this is the leader
    } // not DM
    oPC=GetNextPC();
  } // !OI
} // fnPartyCheck

void fnTeamSelect(object oPC)
{ // select team
    string sID=GetLocalString(oPC,"sTeamID");
    object oMod=GetModule();
    object oLead=GetLocalObject(oMod,"oTeamLead"+sID);
    int nC;
    object oH;
    string sS;
    string sTeamName;
    object oItem;
    object oWP=GetWaypointByTag(sID+"_START");
    int nMana=GetLocalInt(oMod,"nManaStore"+sID);
    int nSouls=GetLocalInt(oMod,"nSoulStore"+sID);
    int nStartSouls=GetLocalInt(oMod,"nStartSoul"+sID);
    int nGold=GetLocalInt(oMod,"nGoldStore"+sID);
    string sResources;
    string sParse;
    int nTeamN=1;
    if (sID=="UND") nTeamN=4;
    if (sID=="DWF") nTeamN=2;
    if (sID=="UNC") nTeamN=3;
    if (sID=="SPID") sTeamName="Spider Cultists.";
    else if (sID=="DWF") sTeamName="Dwarves.";
    else if (sID=="UND") sTeamName="Undead.";
    else if (sID=="UNC") sTeamName="Unclean.";
    if (oLead==OBJECT_INVALID||GetIsPC(oLead)!=TRUE)
    { // no leader - assume leadership
      sS=GetName(oPC)+" has assumed leadership of the "+sTeamName;
      if (GetItemPossessedBy(oPC,"RTSUnit_Creation")==OBJECT_INVALID)
      oItem=CreateItemOnObject("rtsunit_creation",oPC);
      if (GetItemPossessedBy(oPC,"RTSCreation_Tool")==OBJECT_INVALID)
      oItem=CreateItemOnObject("rtscreation_tool",oPC);
      if (GetItemPossessedBy(oPC,"rts_it_teamwand")==OBJECT_INVALID)
      { // create team wand
        oItem=CreateItemOnObject("rts_it_teamwand",oPC);
      } // create team wand
      fnAnnounce(sS);
      SetLocalObject(oMod,"oTeamLead"+sID,oPC);
      if (oLead!=OBJECT_INVALID)
      { // there was an NPC leader
        if (nStartSouls!=0)
        { // stored resources
          SetLocalInt(oPC,"nManaStore",nMana);
          SetLocalInt(oPC,"nSoulStore",nSouls);
          SetLocalInt(oPC,"nStartSoul",nStartSouls);
          GiveGoldToCreature(oPC,nGold);
        } // stored resources
        else
        { // parse resources
          oItem=GetObjectByTag(sID+"_RESOURCES");
          if (oItem!=OBJECT_INVALID)
          { // !OI
            sResources=GetName(oItem);
            sParse=fnParsePeriod(sResources);
            sResources=fnRemParsed(sResources,sParse);
            SendMessageToPC(oPC,"You have "+sParse+" mana at your disposal.");
            SetLocalInt(oPC,"nManaStore",StringToInt(sParse));
            SetLocalInt(oMod,"nManaStore"+sID,StringToInt(sParse));
            sParse=fnParsePeriod(sResources);
            sResources=fnRemParsed(sResources,sParse);
            GiveGoldToCreature(oPC,StringToInt(sParse));
            SetLocalInt(oMod,"nGoldStore"+sID,StringToInt(sParse));
            SendMessageToPC(oPC,"You have "+sResources+" souls at your disposal.");
            SetLocalInt(oPC,"nStartSoul",StringToInt(sResources));
            SetLocalInt(oPC,"nSoulStore",StringToInt(sResources));
            SetLocalInt(oMod,"nSoulStore"+sID,StringToInt(sResources));
            SetLocalInt(oMod,"nStartSoul"+sID,StringToInt(sResources));
          } // !OI
        } // parse resources
        SetLocalString(oMod,"sResNPCLead"+sID,GetResRef(oLead));
        if (GetLocalObject(oMod,"oGUARD5"+sID)==OBJECT_INVALID)
          { // set guard markers
            oItem=CreateObject(OBJECT_TYPE_PLACEABLE,"rts_marker",GetLocation(oItem));
            SetLocalObject(oMod,"oGUARD5"+sID,oItem);
            oItem=GetObjectByTag(sID+"_VAULT");
            oItem=CreateObject(OBJECT_TYPE_PLACEABLE,"rts_marker",GetLocation(oItem));
            SetLocalObject(oMod,"oGUARD4"+sID,oItem);
          } // set guard markers
        SendMessageToPC(oPC,"You have "+IntToString(nMana)+" mana, "+IntToString(nSouls)+", and "+IntToString(GetGold(oPC))+" gold at your disposal.");
        DestroyObject(oLead);
      } // there was an NPC leader
      else if (nStartSouls!=0)
      { // get stored resources
        SetLocalInt(oPC,"nManaStore",nMana);
        SetLocalInt(oPC,"nSoulStore",nSouls);
        SetLocalInt(oPC,"nStartSoul",nStartSouls);
        GiveGoldToCreature(oPC,nGold);
        if (GetLocalObject(oMod,"oGUARD5"+sID)==OBJECT_INVALID)
          { // set guard markers
            oItem=CreateObject(OBJECT_TYPE_PLACEABLE,"rts_marker",GetLocation(oItem));
            SetLocalObject(oMod,"oGUARD5"+sID,oItem);
            oItem=GetObjectByTag(sID+"_VAULT");
            oItem=CreateObject(OBJECT_TYPE_PLACEABLE,"rts_marker",GetLocation(oItem));
            SetLocalObject(oMod,"oGUARD4"+sID,oItem);
          } // set guard markers
        SendMessageToPC(oPC,"You have "+IntToString(nMana)+" mana, "+IntToString(nSouls)+", and "+IntToString(GetGold(oPC))+" gold at your disposal.");
      } // get stored resources
      else
      { // parse resources
        oItem=GetObjectByTag(sID+"_RESOURCES");
        if (oItem!=OBJECT_INVALID)
        { // !OI
          sResources=GetName(oItem);
          sParse=fnParsePeriod(sResources);
          sResources=fnRemParsed(sResources,sParse);
          SendMessageToPC(oPC,"You have "+sParse+" mana at your disposal.");
          SetLocalInt(oPC,"nManaStore",StringToInt(sParse));
          SetLocalInt(oMod,"nManaStore"+sID,StringToInt(sParse));
          sParse=fnParsePeriod(sResources);
          sResources=fnRemParsed(sResources,sParse);
          GiveGoldToCreature(oPC,StringToInt(sParse));
          SetLocalInt(oMod,"nGoldStore"+sID,StringToInt(sParse));
          SendMessageToPC(oPC,"You have "+sResources+" souls at your disposal.");
          SetLocalInt(oPC,"nStartSoul",StringToInt(sResources));
          SetLocalInt(oPC,"nSoulStore",StringToInt(sResources));
          SetLocalInt(oMod,"nSoulStore"+sID,StringToInt(sResources));
          SetLocalInt(oMod,"nStartSoul"+sID,StringToInt(sResources));
          oItem=GetObjectByTag(sID+"_START");
          if (GetLocalObject(oMod,"oGUARD5"+sID)==OBJECT_INVALID)
          { // set guard markers
            oItem=CreateObject(OBJECT_TYPE_PLACEABLE,"rts_marker",GetLocation(oItem));
            SetLocalObject(oMod,"oGUARD5"+sID,oItem);
            oItem=GetObjectByTag(sID+"_VAULT");
            oItem=CreateObject(OBJECT_TYPE_PLACEABLE,"rts_marker",GetLocation(oItem));
            SetLocalObject(oMod,"oGUARD4"+sID,oItem);
          } // set guard markers
        } // !OI
      } // parse resources
    } // no leader - assume leadership
    else
    { // there is a leader
      sS=GetName(oPC)+" has joined the "+sTeamName;
      fnAnnounce(sS,1);
      /*oH=GetFirstPC();
      while(oH!=OBJECT_INVALID)
      { // set enemies & friends
        if (GetIsFriend(oH,oLead)==TRUE||GetIsNeutral(oH,oLead)==TRUE)
        { // friend
          if (oPC!=oH)
          { // not yourself
            SetPCLike(oPC,oH);
          } // not yourself
        } // friend
        else
        { // enemy
          if (oH!=oPC)
          { // not yourself
            SetPCDislike(oPC,oH);
          } // not yourself
        } // enemy
        oH=GetNextPC();
      } // set enemies & friends */
    } // there is a leader
    // set reputation of creatures towards you
    SetLocalInt(oPC,"nTeamNum",nTeamN);
    SetLocalInt(oMod,"n"+sID+"Num",nTeamN);
    fnSetFactionToFriendly(oPC,sID);
} // fnTeamSelect()


string fnGetTeamID(int nC)
{ // return the team ID
  string sRet="NA";
  if (nC==1) sRet="SPID";
  else if (nC==2) sRet="DWF";
  else if (nC==3) sRet="UNC";
  else if (nC==4) sRet="UND";
  return sRet;
} // fnGetTeamID()

void fnAnnounce(string sMsg="",int nOption=0)
{ // announce message to players
   object oNext=GetFirstPC();
   while(oNext!=OBJECT_INVALID)
   { // announce
     SendMessageToPC(oNext,"ANNOUNCEMENT:"+sMsg);
     if (nOption==0) AssignCommand(oNext,fnSoundAlert("as_an_owlhoot1"));
     else if (nOption==1) AssignCommand(oNext,fnSoundAlert("as_cv_lute1"));
     oNext=GetNextPC();
   } // announce
} // fnAnnounce()

string fnParsePeriod(string sIn)
{ // Parse period
  string sH=sIn;
  string sR="";
  while (GetStringLength(sH)>0&&GetStringLeft(sH,1)!=".")
  { // build string
    sR=sR+GetStringLeft(sH,1);
    sH=GetStringRight(sH,GetStringLength(sH)-1);
  } // build string
  return sR;
} // fnParsePeriod()

string fnRemParsed(string sO, string sP)
{ // Remove parsed portion from sO
  string sR="";
  if (GetStringLength(sO)>=GetStringLength(sP))
   sR=GetStringRight(sO,GetStringLength(sO)-GetStringLength(sP));
  if (GetStringLeft(sR,1)==".") sR=GetStringRight(sR,GetStringLength(sR)-1);
  return sR;
} // fnRemParsed()

void fnSetFactionToFriendly(object oPC,string sID)
{ // Set faction that you control to friendly
  object oMember=GetObjectByTag(sID+"0");
  object oWP;
  int nCreate=FALSE;
  if(oMember==OBJECT_INVALID)
  { // create dummy
    nCreate=TRUE;
    oWP=GetWaypointByTag(sID+"_START");
    oMember=CreateObject(OBJECT_TYPE_CREATURE,sID+"0",GetLocation(oWP));
  } // create dummy
  if (oMember!=OBJECT_INVALID)
  { // !OI
     AdjustReputation(oPC,oMember,100);
  } // !OI
  else
  {
    SendMessageToPC(oPC,"CRITICAL AREA: A creature placed with tag "+sID+"0 could not be found and is required to set faction you control to friendly!!!");
  }
  if (nCreate==TRUE) DestroyObject(oMember);
} // fnSetFactionToFriendly()

void fnRecordInventory(object oPC)
{ // flush old inventory record and record inventory
  object oItem;
  int nCount;
  object oMod=GetModule();
  string sPre=GetName(oPC)+GetPCPlayerName(oPC);
  string sRes;
  nCount=1;
  sRes=GetLocalString(oMod,sPre+IntToString(nCount));
  while(GetStringLength(sRes)>0)
  { // poll and clear old inventory storage
    DeleteLocalString(oMod,sPre+IntToString(nCount));
    nCount++;
    sRes=GetLocalString(oMod,sPre+IntToString(nCount));
  } // poll and clear old inventory storage
  // write current inventory
  oItem=GetFirstItemInInventory(oPC);
  nCount=0;
  while(oItem!=OBJECT_INVALID)
  { // store PLOT items
    if (GetPlotFlag(oItem)==TRUE)
    { // store this item
      sRes=GetResRef(oItem);
      nCount++;
      SetLocalString(oMod,sPre+IntToString(nCount),sRes);
    } // store this item
    oItem=GetNextItemInInventory(oPC);
  } // store PLOT items
  oItem=GetItemInSlot(INVENTORY_SLOT_ARROWS,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  oItem=GetItemInSlot(INVENTORY_SLOT_BELT,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  oItem=GetItemInSlot(INVENTORY_SLOT_BOLTS,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  oItem=GetItemInSlot(INVENTORY_SLOT_BOOTS,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  oItem=GetItemInSlot(INVENTORY_SLOT_BULLETS,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  oItem=GetItemInSlot(INVENTORY_SLOT_CHEST,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  oItem=GetItemInSlot(INVENTORY_SLOT_CLOAK,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  oItem=GetItemInSlot(INVENTORY_SLOT_HEAD,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  oItem=GetItemInSlot(INVENTORY_SLOT_LEFTHAND,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  oItem=GetItemInSlot(INVENTORY_SLOT_LEFTRING,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  oItem=GetItemInSlot(INVENTORY_SLOT_NECK,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  oItem=GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  oItem=GetItemInSlot(INVENTORY_SLOT_RIGHTRING,oPC);
  if (oItem!=OBJECT_INVALID)
  { // store this item too
    sRes=GetResRef(oItem);
    nCount++;
    SetLocalString(oMod,sPre+IntToString(nCount),sRes);
  } // store this item too
  SetLocalInt(oMod,sPre+"Gold",GetGold(oPC));
} // fnRecordInventory()