• You've discovered RedGuides, an EverQuest multi-boxing and scripting community 🧙‍♀️⚙️. We want you to play several EQ characters at once, come join us and say hello! 👋

  • A TLP without truebox has thawed (Very Vanilla ready)
    Frostreaver

Emu MQ2MasterMind

HardOne

Member
Joined
Jan 15, 2006
RedCents
61¢
Rich (BB code):
// MQ2MasterMind.cpp : Defines the entry point for the DLL application. 
// 
// Developer: Fibby 
//      Date: 2/27/2005 
// 
// v1.7 - Changed to allow up to 10 masters, masters names kept, a few extra info messages, 
//        and autogroup code.  All info saved in INI and remembered between sessions.   <<htw>> 
// v1.6a- "I am an idiot" fix.. 
// 
// v1.6 - Added INI support and /setmasterkey command 
//        Fixed stupid bug with inserting slashes in your tells 
// 
// v1.5 - Fixed the parsing error and removed nexttok per ieatacid's comments 
// 
// v1.4 - Made it a little easier to setup the master key.. see comments below 
// 
// v1.3 - Added the ability to reset the master via /resetmaster 
// 
// v1.2 - Fixed several small problem with determining who master is, etc, etc. 
// 
// v1.1 - Updateded Trigger String based on feedback from koad 
// 
// v1.0 - Provides a basic and simple method for allowing control to another via 
//        tells.  The first command the master should send is the identification string 
//        If you don't like the identification string below.. change it. 
// 
//        Supports basic / (slash) commands both EQ and MQ. 
// 
//  Inspired by Ieatacid and the following thread: 
// 
// http://www.macroquest2.com/phpBB2/viewtopic.php?t=10158 
// 
// 

#include "../MQ2Plugin.h" 

char MyMaster[10][MAX_STRING] = { "", "", "", "", "", "", "", "", "", "" }; 
char szMasterTrigger[10][MAX_STRING] = { "", "", "", "", "", "", "", "", "", "" }; 
char szMasterKey[MAX_STRING]; 
char szMasterKeyDefault[MAX_STRING] = "I am thy master!"; 
bool bGotMaster[10]={ false, false, false, false, false, false, false, false, false, false }; 
int NumMasters = 0; 
CHAR MsgGroup[MAX_STRING] = "To join the group, click on the 'FOLLOW' option, or 'DISBAND' to cancel."; 
BOOL autoGroup = true; 
int TimeToInvite = 0; 
BOOL GroupInvite = FALSE; 

void ClearMaster(PSPAWNINFO pChar, PCHAR szLine); 
void SetMasterKey(PSPAWNINFO pChar, PCHAR szLine); 
void ReadINI(); 
void WriteINI(); 

PreSetup("MQ2MasterMind"); 

VOID echo(char* output) 
{ 
   WriteChatColor(output,USERCOLOR_DEFAULT); 
} 

VOID OptAutoGroup(PSPAWNINFO pChar, PCHAR szLine) { 
   char Arg1[MAX_STRING]; 

   GetArg(Arg1,szLine,1); 
   if( !strcmp(Arg1,"on") ) { 
      autoGroup = true; 
      WriteChatColor("AutoGroup Enabled",USERCOLOR_DEFAULT); 
   } else if( !strcmp(Arg1,"off") ) { 
      autoGroup = false; 
      WriteChatColor("AutoGroup Disabled",USERCOLOR_DEFAULT); 
   } else { 
      if (autoGroup) 
         WriteChatColor("AutoGroup Enabled",USERCOLOR_DEFAULT); 
      else 
         WriteChatColor("AutoGroup Disabled",USERCOLOR_DEFAULT); 
   } 
   WriteINI(); 
} 

VOID ClearMasters(PSPAWNINFO pChar, PCHAR szLine) { 
   NumMasters = 0; 
   for(int i = 0; i < 10; i++) 
       bGotMaster = false; 
   WriteChatColor("Masters have been Reset", USERCOLOR_SYSTEM); 
   WriteINI(); 
} 

VOID SetMasterKey(PSPAWNINFO pChar, PCHAR szLine) { 
   strcpy(szMasterKey, szLine); 
   WriteINI(); 
   for(int i = 0; i < 10; i++) 
       bGotMaster = false; 
   WriteChatColor("Masters have been Reset and Redefined", USERCOLOR_SYSTEM); 
} 

VOID ReadINI() { 
   char szTemp[MAX_STRING]; 

   GetPrivateProfileString("Options", "MasterKey", szMasterKeyDefault, szMasterKey, MAX_STRING, INIFileName); 
   for(int i = 0; i<10; i++) { 
      sprintf(szTemp, "Master%d", i); 
        GetPrivateProfileString("Masters", szTemp, "", MyMaster, MAX_STRING, INIFileName); 
      if(strlen(MyMaster) > 0) { 
         bGotMaster = true; 
           sprintf(szMasterTrigger,"%s tells you, '", MyMaster); 
      } 
   } 
   if (gGameState==GAMESTATE_INGAME) { 
      GetPrivateProfileString(GetCharInfo()->Name,"autoGroup","on",szTemp,MAX_STRING,INIFileName); 
      autoGroup = (strncmp(szTemp,"on",3)==0); 
   } 
} 

VOID WriteINI() { 
   char szTemp[MAX_STRING]; 

    WritePrivateProfileString("Options", "MasterKey", szMasterKey, INIFileName); 
   for(int i = 0; i<10; i++) { 
      sprintf(szTemp, "Master%d", i); 
        WritePrivateProfileString("Masters", szTemp, MyMaster, INIFileName); 
   } 
   if (gGameState==GAMESTATE_INGAME) { 
      sprintf(szTemp,"%s",autoGroup?"on":"off"); 
      WritePrivateProfileString(GetCharInfo()->Name,"autoGroup",szTemp,INIFileName); 
   } 
} 

// Called once, when the plugin is to initialize 
PLUGIN_API VOID InitializePlugin(VOID) 
{ 
   DebugSpewAlways("Initializing MQ2MasterMind"); 
   AddCommand("/resetmasters", ClearMasters, 0, 0, 1); 
   AddCommand("/setmasterkey", SetMasterKey, 0, 0, 1); 
   AddCommand("/autogroup", OptAutoGroup); 
   try { 
      ReadINI(); 
      WriteINI(); 
   } 
   catch(...) { 
#ifndef SUPPRESS_ERRORS 
      echo("[MQ2MasterMind::InitializePlugin] Caught Terminal Error: attempting to continue as normal."); 
#endif 
   } 
} 

// Called once, when the plugin is to shutdown 
PLUGIN_API VOID ShutdownPlugin(VOID) 
{ 
   DebugSpewAlways("Shutting down MQ2MasterMind"); 
   try { 
      RemoveCommand("/resetmasters"); 
      RemoveCommand("/setmasterkey"); 
      RemoveCommand("/autogroup"); 
      WriteINI(); 
   } 
   catch(...) { 
#ifndef SUPPRESS_ERRORS 
      echo("[MQ2MasterMind::ShutdownPlugin] Caught Terminal Error: attempting to continue as normal."); 
#endif 
   } 
} 


// This is called every time EQ shows a line of chat with CEverQuest::dsp_chat, 
// but after MQ filters and chat events are taken care of. 
PLUGIN_API DWORD OnIncomingChat(PCHAR Line, DWORD Color) 
{ 
   DebugSpewAlways("MQ2MasterMind::OnIncomingChat(%s)",Line); 

   // Don't process if not in game 
   if (gGameState!=GAMESTATE_INGAME) 
      return 0; 

   try { 
   if ( autoGroup ) { 
      if( !strcmp(Line,MsgGroup) ) { 
         int randomnumber = 2000 + (rand()%100); 
            TimeToInvite = clock() + randomnumber; 
         GroupInvite = TRUE; 
      } 
   } 

   char szTemp[MAX_STRING]; 

   sprintf(szTemp, " tells you, '%s'", szMasterKey); 
   if (strstr(Line, szTemp)) { 
      char* Father; 
      Father=strtok(Line," "); 
      for(int x = 0; x<10; x++) { 
         if(!stricmp(Father, MyMaster[x])) { 
            bGotMaster[x] = true; 
            sprintf(szTemp, "%s sent master command string and is an active master (#%d)", 
               Father, x); 
              sprintf(szMasterTrigger[x],"%s tells you, '", Father); 
            WriteChatColor(szTemp, USERCOLOR_SYSTEM); 
            return 0; 
         } 
      } 
      int index; 
      for(index=0; index < 10; index++) 
          if(MyMaster[index][0] == 0) 
             break; 
      if(index >= 10) { 
         sprintf(szTemp, "Master command phrase received, but no room for any new masters."); 
         WriteChatColor(szTemp, USERCOLOR_SYSTEM); 
          return 0; 
      } 
        strcpy(MyMaster[index], Father); 
      Sleep(5000); 
       sprintf(szTemp, "Master %d set to: '%s'", index, Father); 
       WriteChatColor(szTemp, USERCOLOR_SYSTEM); 
       sprintf(szTemp,"/tell %s Yes my master, I shall do thy bidding!", MyMaster[index]); 
       sprintf(szMasterTrigger[index],"%s tells you, '", MyMaster[index]); 
       DoCommand((PSPAWNINFO)pCharSpawn,szTemp); 
       bGotMaster[index]=true; 
      WriteINI(); 
   } 
   else { 
      for(int j = 0; j<10 ; j++) { 
         if ((strstr(Line,szMasterTrigger[j])) && (strlen(szMasterTrigger[j]) > 0)) { 
            CHAR TextString[MAX_STRING]; 
            PSTR Text; 

            Text = GetNextArg(Line,1,FALSE,'\''); 

            if (Text[0] == '/') { 
               strcpy(TextString,Text); 
               TextString[strlen(Text)-1] = '\0'; 
            
               sprintf(szTemp, "MQ2MM: Received command '%s' from master %s", TextString, MyMaster[j]); 
               WriteChatColor(szTemp, USERCOLOR_SYSTEM); 
               DoCommand((PSPAWNINFO)pCharSpawn,TextString); 
            } 
         } 
      } 
   } 
   return 0; 
   } // try 
   catch(...) { 
#ifndef SUPPRESS_ERRORS 
      echo("[MQ2MasterMind::ShutdownPlugin] Caught Terminal Error: attempting to continue as normal."); 
#endif 
   return 0; 
   } 
   return 0; 
} 

PLUGIN_API VOID OnPulse(VOID) 
{          
   if (gGameState==GAMESTATE_INGAME) { 
      if (GroupInvite && TimeToInvite <= clock()){ 
         pTarget = NULL; 
         DoCommand(GetCharInfo()->pSpawn,"/invite"); 
         GroupInvite = FALSE; 
      } 
   } 
} 

PLUGIN_API VOID SetGameState(DWORD GameState) 
{ 
   if (GameState==GAMESTATE_INGAME) { 
      try { 
         ReadINI(); 
         WriteINI(); 
      } 
      catch(...) { 
#ifndef SUPPRESS_ERRORS 
         echo("[MQ2MasterMind::SetGameState] Caught Terminal Error: attempting to continue as normal."); 
#endif 
      } 
   } 
}

 
Emu MQ2MasterMind

Users who are viewing this thread

Back
Top
Cart