NEW FEATURE /finditem id xxx and $count(id,xxx) - Please CVS

A forum for feature requests/discussions and user submitted patches that improve MQ2

Moderator: MacroQuest Developers

MacroFiend
a grimling bloodguard
a grimling bloodguard
Posts: 662
Joined: Mon Jul 28, 2003 2:47 am

NEW FEATURE /finditem id xxx and $count(id,xxx) - Please CVS

Post by MacroFiend » Sat Aug 09, 2003 6:22 pm

After seeing the suggestion to add the ItemNumber to a few of the macro variables, I decided these would be good to include it also.

To add $count(id,xxx), update the following in EQLib_MacroParser.cpp

Code: Select all

[color=red]
DWORD parmCount(PCHAR szVar, PCHAR szOutput, PSPAWNINFO pChar)
{
	DWORD i=0;
	PCONTENTS pContainer = 0;
	PCHARINFO pCharInfo = NULL;
	if (NULL == (pCharInfo = GetCharInfo())) return PMP_ERROR_BADPARM;
	if (!strstr(szVar,")")) {
		DebugSpew("PMP - Bad $count() '%s'",szVar);
		return PMP_ERROR_BADPARM;
[/color]
	// $count(id,xxx)
	} else if (!strncmp("count(id,",szVar,9)) { 
		CHAR szArg[MAX_STRING] = {0};
		CHAR szTemp[MAX_STRING] = {0};
		DWORD a,b,c=0;
		DWORD argSize=(strstr(szVar,")")-szVar);
		i += argSize;
		strncpy(szArg,szVar+9,argSize-9);
		GetArg(szTemp,szArg,1);
		for (a=0;a<8;a++) {
			if (!pCharInfo->Inventory[22+a]) continue;
			DebugSpew("Inventory->ItemNumber %d, looking for %s",(*pCharInfo->Inventory[22+a])->ItemNumber,szTemp);
			if ((int)(*pCharInfo->Inventory[22+a])->ItemNumber==atoi(szTemp)) {
				if (((*pCharInfo->Inventory[22+a])->Type != ITEMTYPE_NORMAL) || ((*pCharInfo->Inventory[22+a])->Common.Stackable!=1)) {
					c++;
				} else {
					c+=((PCONTENTS)pCharInfo->Inventory[22+a])->StackCount;
				}
			}

			// Parse through the containers
			if ((*pCharInfo->Inventory[22+a])->Type == ITEMTYPE_PACK) {
				pContainer = (PCONTENTS)(pCharInfo->Inventory[22+a]);
				for (b=0;b<(*pCharInfo->Inventory[22+a])->Container.Slots;b++) {
					if (!pContainer->Contents[b]) continue;
					DebugSpew("Container[%d]->Contents[%d]->Item->ItemNumber %d, looking for %s",a,b,pContainer->Contents[b]->Item->ItemNumber,szTemp);
					if ((int)pContainer->Contents[b]->Item->ItemNumber==atoi(szTemp)) {
						if ((pContainer->Contents[b]->Item->Type != ITEMTYPE_NORMAL) || (pContainer->Contents[b]->Item->Common.Stackable!=1)) {
							c++;
						} else {
							c+=pContainer->Contents[b]->StackCount;
						}
					}
				}
			}
		}
		itoa(c, szTemp, 10);
		strcat(szOutput,szTemp);
[color=red]
	// $count(itemname)
	} else {
		CHAR szArg[MAX_STRING] = {0};
		CHAR szTemp[MAX_STRING] = {0};
		DWORD a,b,c=0;
		DWORD argSize=(strstr(szVar,")")-szVar);
		i += argSize;
		strncpy(szArg,szVar+6,argSize-6);
		GetArg(szTemp,szArg,1,FALSE,FALSE,FALSE,')');
		for (a=0;a<8;a++) {
			if (!pCharInfo->Inventory[22+a]) continue;
			if (!stricmp(szTemp,(*pCharInfo->Inventory[22+a])->Name)) {
				if (((*pCharInfo->Inventory[22+a])->Type != ITEMTYPE_NORMAL) || ((*pCharInfo->Inventory[22+a])->Common.Stackable!=1)) {
					c++;
				} else {
					c+=((PCONTENTS)pCharInfo->Inventory[22+a])->StackCount;
				}
			}
			if ((*pCharInfo->Inventory[22+a])->Type == ITEMTYPE_PACK) {
				pContainer = (PCONTENTS)(pCharInfo->Inventory[22+a]);
				for (b=0;b<(*pCharInfo->Inventory[22+a])->Container.Slots;b++) {
					if (!pContainer->Contents[b]) continue;
					if (!stricmp(szTemp,pContainer->Contents[b]->Item->Name)) {
						if ((pContainer->Contents[b]->Item->Type != ITEMTYPE_NORMAL) || (pContainer->Contents[b]->Item->Common.Stackable!=1)) {
							c++;
						} else {
							c+=pContainer->Contents[b]->StackCount;
						}
					}
				}
			}
		}
		itoa(c, szTemp, 10);
		strcat(szOutput,szTemp);
	}
	return i;
}
[/color]
For /finditem [similar|id] item, update the command in EQLib_Commands.cpp

Code: Select all

[color=red]// ***************************************************************************
// Function:    FindItem
// Description: Our '/finditem' command
//              Brings the named item onto the cursor.
// Usage:       /finditem itemname
// ***************************************************************************
VOID FindItem(PSPAWNINFO pChar, PCHAR szLine)
{
	bRunNextCommand = TRUE;
	UCHAR PriSlot;
	CHAR szSearch[MAX_STRING] = {0};
	CHAR szBuffer[MAX_STRING] = {0};
	BOOL Exact= TRUE;[/color]
	BOOL ByID=FALSE;
[color=red]	gLastFind = LASTFIND_NOTFOUND;
	PCHARINFO pCharInfo = NULL;
	if (NULL == (pCharInfo = GetCharInfo())) return;
	if (szLine[0] == 0) {
[/color]		WriteChatBuffer("Usage: /finditem [similar|id] \"item name\"|\"item id\"",USERCOLOR_DEFAULT);
[color=red]		strcpy(gLastError,"FIND_NOTFOUND");
		return;
	}
	if (pCharInfo->Cursor) {
		WriteChatBuffer("Your hands must be empty to find an item.",CONCOLOR_RED);
		strcpy(gLastError,"FIND_HANDSFULL");
		return;
	}
	GetArg(szSearch,szLine,1);
	if (!stricmp(szSearch,"similar")) {
		Exact=FALSE;
		GetArg(szSearch,szLine,2);
	}
[/color]	if (!stricmp(szSearch,"id")) {
		ByID=TRUE;
		GetArg(szSearch,szLine,2);
	}
[color=red]	_strlwr(szSearch);
	for (PriSlot=0;PriSlot<8;PriSlot++) {
		PITEMINFO pSlot = pCharInfo->Inventory[22+PriSlot];
		CHAR szTemp[MAX_STRING] = {0};
		if (!pSlot) continue;
		_strlwr(strcpy(szTemp,pSlot->Name));
		if (
				(
					(!Exact) &&
					(strstr(szTemp,szSearch))
				) || (
					(Exact) &&
					(!strcmp(szTemp,szSearch))
[/color]				) || (
					(ByID) &&
					((int)pSlot->ItemNumber == atoi(szSearch))
[color=red]				)
		) {
			CHAR szBuf[MAX_STRING] = {0};
			gLastFind = LASTFIND_PRIMARY;
			DebugSpew("FindItem - Found '%s' in primary inventory slot %d",pSlot->Name,PriSlot);
			sprintf(szBuf,"left inv %d",PriSlot);
			Click(pChar,szBuf);
			gLastError[0]=0;
			return;
		}
		if (pSlot->Type == ITEMTYPE_PACK) {
			UCHAR BagSlot;
			DebugSpew("FindItem - Looking inside pack %d: '%s'",PriSlot,pSlot->Name);
			for (BagSlot=0;BagSlot < (DWORD)pSlot->Container.Slots;BagSlot++) {
				PITEMINFO pItem = pSlot->Container.Contents[BagSlot];
				if (!pItem) continue;
				_strlwr(strcpy(szTemp,pItem->Name));
				if (
						(
							(!Exact) &&
							(strstr(szTemp,szSearch))
						) || (
							(Exact) &&
							(!strcmp(szTemp,szSearch))
[/color]						) || (
							(ByID) &&
							((int)pItem->ItemNumber == atoi(szSearch))
[color=red]						)
				) {
					CHAR szBuf[MAX_STRING] = {0};
					BOOL WasOpen = FALSE;
					DebugSpew("FindItem - Found '%s' in slot %d of '%s' (primary slot %d)",pItem->Name,BagSlot,pSlot->Name,PriSlot);
					gLastFind = PriSlot;
					if (pSlot->Container.Open == 0) {
						sprintf(szBuf,"right inv %d",PriSlot);
						Click(pChar,szBuf);
						WasOpen = TRUE;
					}
					if (pSlot->Container.Open == 0) {
						strcpy(gLastError,"FIND_PACKNOTOPEN");
						return;
					}
					sprintf(szBuf,"left pack %d %d",PriSlot,BagSlot);
					Click(pChar,szBuf);
					if (WasOpen) {
						sprintf(szBuf,"left pack %d done",PriSlot);
						Click(pChar,szBuf);
					}
					gLastError[0]=0;
					return;
				}
			}
		}
	}
	sprintf(szBuffer,"Couldn't find a '%s'",szSearch);
	strcpy(gLastError,"FIND_NOTFOUND");
	WriteChatBuffer(szBuffer,CONCOLOR_RED);
}
[/color]
*Edited to add (int) to if conditions and to correct a coloring error.
*Edited to use the updated PMP for $count(id,xxx)
Last edited by MacroFiend on Sat Sep 06, 2003 6:13 pm, edited 5 times in total.

EqMule
Developer
Developer
Posts: 2697
Joined: Fri Jan 03, 2003 9:57 pm
Contact:

Re: NEW FEATURE /finditem id xxx and $count(id,xxx)

Post by EqMule » Sun Aug 10, 2003 7:52 pm

Great job, it compiles fine, but I had to make a couple changes... (I get warnings if I dont in VC6 at least...)

Code: Select all

if ([b](int)[/b]pCharInfo->Inventory[22+a]->ItemNumber==atoi(szTemp))

Code: Select all

if ([b](int)[/b]pCharInfo->Inventory[22+a]->Container.Contents->ItemNumber==atoi(szTemp))

Code: Select all

) || ( 
							(ByID) && 
							([b](int)[/b]pItem->ItemNumber == atoi(szSearch))
and

Code: Select all

) || ( 
                     (ByID) && 
                     ([b](int)[/b]pItem->ItemNumber == atoi(szSearch))
Now... I have a couple questions for you.

Code: Select all

for (a=0;a<8;a++)
what if the bags have 10 slots?

and lastly, I must be blind or stupid, or maybe both, but I couldnt figure out a way to /echo the ID of for example an "Iron Ration" and if I dont know the ID I cant use this function right? What am I missing here, please enlighten me, I would very much like this thing to work... Do I need to write a /echo $item("Iron Ration",id) command to be able to use this?

Im tired, bare with me...
oh and you might wanna recolor the post because this line

Code: Select all

[color=red]BOOL ByID=FALSE;[/color]
is red... Im sure you meant to have the line above it red :)
Last edited by EqMule on Mon Aug 11, 2003 3:25 am, edited 1 time in total.
My status o/
If you like MQ2 and would like to contribute, please do. My goal is 25 donations per month.
So far I've received Image donations for this month's patches.

Bitcoin: 1Aq8ackjQ4f7AUvbUL7BE6oPfT8PmNP4Zq
Krono: PM me.
I can always use characters for testing, PM me if you can donate one.

MacroFiend
a grimling bloodguard
a grimling bloodguard
Posts: 662
Joined: Mon Jul 28, 2003 2:47 am

Post by MacroFiend » Sun Aug 10, 2003 9:20 pm

Doesn't surprise me that VC6 gave warnings and VC7 didn't *g*

As for the loop, I just re-used the existing /finditem code but from looking at it, the loop is for top level inventory items and not bags. The 3rd top level IF in the loop handles bags. The part that deals with bags in inventory is:

Code: Select all

if (pCharInfo->Inventory[22+a]->Type == ITEMTYPE_PACK) { 
                           for (b=0;b<pCharInfo->Inventory[22+a]->Container.Slots;b++) { 
Thanks for catching the coloring part. BOOL Exact should have been red while ByID yellow. Just wrapped the color around the wrong line.

As for getting the ID for an item, Valerian added $item(xxx,id) and $cursor(id). On his thread, I added $equip(xxx,id) and $pack([bank,]xxx,id)
The thread w/ the code additions is:
http://macroquest2.com/phpBB2/viewtopic ... highlight=

EqMule
Developer
Developer
Posts: 2697
Joined: Fri Jan 03, 2003 9:57 pm
Contact:

Post by EqMule » Mon Aug 11, 2003 3:24 am

ahh Thanks, I knew I was missing something like that, I will get thoose in as well, cant wait to try this out... oh and here is the last change I made in case you wanna change your post for vc6 compatibility

Code: Select all

) || ( 
                     (ByID) && 
                     ([b](int)[/b]pItem->ItemNumber == atoi(szSearch))
My status o/
If you like MQ2 and would like to contribute, please do. My goal is 25 donations per month.
So far I've received Image donations for this month's patches.

Bitcoin: 1Aq8ackjQ4f7AUvbUL7BE6oPfT8PmNP4Zq
Krono: PM me.
I can always use characters for testing, PM me if you can donate one.

MacroFiend
a grimling bloodguard
a grimling bloodguard
Posts: 662
Joined: Mon Jul 28, 2003 2:47 am

Request for inclusion to CVS

Post by MacroFiend » Sat Sep 06, 2003 6:12 pm

This has been done and working for some time but hasn't made it in to CVS. Please test and add. It has been updated for the 8/28 patches and new PMP routine.

Valerian
a grimling bloodguard
a grimling bloodguard
Posts: 709
Joined: Sun Jul 28, 2002 3:29 am

Post by Valerian » Sat Sep 06, 2003 8:01 pm

in CVS


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: NEW FEATURE /finditem id xxx and $count(id,xxx) - Please CVS

Post by xyilla » Fri Jan 23, 2026 9:49 am