MQ2MobItemFinder Plugin

kukmuk

Lifetimer
Joined
Jun 25, 2007
Messages
175
Reaction score
0
Points
0
Here is a plugin I tossed together to suit a purpose that I needed it for... to find all mobs in the zone with visible weapons and show them on the map. It does nothing more than that. Hope this helps others as much as it helped me =) The dll file is attached at the bottom for those who don't care to compile it themselves.

Commands:
Code:
/showmobs

Code:
// MQ2MobItemFinder.cpp : Defines the entry point for the DLL application.
//

// PLUGIN_API is only to be used for callbacks.  All existing callbacks at this time
// are shown below. Remove the ones your plugin does not use.  Always use Initialize
// and Shutdown for setup and cleanup, do NOT do it in DllMain.

#include <list>

#include "../MQ2Plugin.h"


PreSetup("MQ2MobItemFinder");

// Return the number of mobs found with items
// Fills in mobList with the ID of the mob
int getMobsWithItems( std::list <DWORD> &spawnIdList )
{
	int retVal = 0;

	PSPAWNINFO pSpawn=(PSPAWNINFO)pSpawnList;

	// Loop through all of the spawns
	while(pSpawn) 
	{
		if ( pSpawn->Equipment.Primary.ID || pSpawn->Equipment.Offhand.ID )
		{
			// Spawn has an item!
			// But don't look at myself
			if ( pSpawn->SpawnID != GetCharInfo()->pSpawn->SpawnID )
			{
				spawnIdList.push_back (pSpawn->SpawnID);
				retVal++;
			}
		}
		pSpawn = pSpawn->pNext; 
	} 

	return retVal;
}

VOID showMobs(PSPAWNINFO pChar, PCHAR szLine)
{
	std::list <DWORD> mobList;
	int numMobs = getMobsWithItems (mobList);

	// Reset the mapshow
	char szCommandLine[1024];
	sprintf ( szCommandLine,
			  "/mapshow reset" );
	// Execute the mapshow command
	char szChat[1024];
	sprintf( szChat, 
			 "Executing: %s",
			 szCommandLine);
	WriteChatColor(szChat,CONCOLOR_BLUE);
	HideDoCommand ( NULL, szCommandLine, FromPlugin );

	while ( mobList.size() > 0 )
	{
		DWORD currId = mobList.front();
		mobList.pop_front();
		char szCommandLine[1024];
		sprintf ( szCommandLine,
				  "/mapshow id %d",
				  currId );
		// Execute the mapshow command
		char szChat[1024];
		sprintf( szChat, 
				 "Executing: %s",
				 szCommandLine);
		WriteChatColor(szChat,CONCOLOR_BLUE);
		HideDoCommand ( NULL, szCommandLine, FromPlugin );
	}
}

// Called once, when the plugin is to initialize
PLUGIN_API VOID InitializePlugin(VOID)
{
    DebugSpewAlways("Initializing MQ2MobItemFinder");

    //Add commands, MQ2Data items, hooks, etc.
    AddCommand("/showmobs",showMobs);
    //AddXMLFile("MQUI_MyXMLFile.xml");
    //bmMyBenchmark=AddMQ2Benchmark("My Benchmark Name");
	char szChat[1024];
	sprintf( szChat, 
		     "Shows all mobs on map that are holding weapons\nUsage: /showmobs" );
    WriteChatColor(szChat,CONCOLOR_BLUE);
}

// Called once, when the plugin is to shutdown
PLUGIN_API VOID ShutdownPlugin(VOID)
{
    DebugSpewAlways("Shutting down MQ2MobItemFinder");

    //Remove commands, MQ2Data items, hooks, etc.
    //RemoveMQ2Benchmark(bmMyBenchmark);
    RemoveCommand("/showmobs");
    //RemoveXMLFile("MQUI_MyXMLFile.xml");
}
 

Attachments

  • MQ2MobItemFinder.dll
    153.5 KB · Views: 3
  • MQ2MobItemFinder.cpp
    2.6 KB · Views: 3