Page 1 of 2

Ok, got bored... $GetLastFindSlot

Posted: Fri Aug 01, 2003 11:35 pm
by Valerian
heh. figured I'd find a way to get the slot of the found item, so I could use /sellitem $item($getlastfindslot,stack) and be lazy... anyway, here it is...
EQLib_MacroParser.cpp:

Code: Select all

					// $getlastfindslot
					} else if (!strncmp("getlastfindslot",szVar,15)) {
						i += 14;
						if (gLastFindSlot[0] == 0) {
							strcat(szOutput,"NULL");
							j+=4;
						} else {
							strcat(szOutput,gLastFindSlot);
							j+=strlen(gLastFindSlot);
						}

					// $GetLastError
EQLib_Main.cpp:

Code: Select all

CHAR gLastFindSlot[MAX_STRING]={0};
EQLib.h:

Code: Select all

extern CHAR gLastFindSlot[MAX_STRING];
and EQLib_Commands:

Code: Select all

// ***************************************************************************
// 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;
	gLastFind = LASTFIND_NOTFOUND;
	gLastFindSlot[0]=0;
	PCHARINFO pCharInfo = NULL;
	if (NULL == (pCharInfo = GetCharInfo())) return;
	if (szLine[0] == 0) {
		WriteChatBuffer("Usage: /finditem [similar] \"item name\"",USERCOLOR_DEFAULT);
		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);
	}
	_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))
				)
		) {
			CHAR szBuf[MAX_STRING] = {0};
			gLastFind = LASTFIND_PRIMARY;
			DebugSpew("FindItem - Found '%s' in primary inventory slot %d",pSlot->Name,PriSlot);
			sprintf(gLastFindSlot,"inv,%d",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))
						)
				) {
					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(gLastFindSlot,"%d,%d",PriSlot,BagSlot);
					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);
}
returns "inv,<slot>" or "<mainslot>,<bagslot>" in a format usable by $item, or NULL if item not found.

Posted: Fri Aug 01, 2003 11:59 pm
by dont_know_at_all
Can you supply a macro to show how this is used?

thanks.

Posted: Sat Aug 02, 2003 8:37 am
by EqMule
Awesome work! thanks!

Posted: Sat Aug 02, 2003 9:14 am
by Valerian
ok, here's one off the top of my head... ok, so it's out of a macro I wrote a while ago... anyways, the usefulness of this is rather little, but it does come in handy since /sellitem has a minor bug in regards to false duping...

Code: Select all

| SellItems.mac
| usage: /macro sellitems [similar] "<name>"
#chat say
#event selectionSell "ll give you "

Sub Main
   /if "$p0"=="similar" {
      /varset l1 TRUE
      /varset l2 "$p1"
   } else {
      /varset l2 "$p0"
   }
   :WaitForSellTarget
   /target npc range 2 65
   /delay 1
   /if $target()==FALSE /goto :WaitForSellTarget
   /varset v66 "$target(name,clean)"
   /mouseto target
   /click right
   /varset t1 15s
   /delay 1
   :WaitForMerchant
      /if n $t1==0 /goto :WaitForSellTarget
      /delay 1
      /doevents Chat
   /if n $v65!=1 /goto :WaitForMerchant
      /varset t1 0
      /delay 5
   :Selling
      /varset Selected FALSE
      /doevents flush
      /if $l1==TRUE {
         /finditem similar "$p0"
      } else {
         /finditem "$p0"
      }
:Waitselection
      /doevents selectionSell
      /if n $count("$p0")>0 /if $Selected==FALSE /goto :Waitselection
      /if n $count("$p0")==0 /goto :done
      /delay 2
      [b]/Call MySellItem $item($getlastfindslot,stack)[/b]
   /goto :Selling
   :done
   /click left merchant done
/return


Sub Event_Chat
   /if "$p1"=="$v66" /if "$p0"~~"say" /if "$p2"~~"$char(name)" /varset v65 1
   /if "$p1"=="$v66" /if "$p0"~~"say" /if "$p2"!~"$char(name)" /if "$p2"!~"Welcome to my shop" {
      /delay 10s
      /mouseto target
      /click right
   }
/return

Sub MySellItem
   /if n $p0>0 {
      /varset l1 $p0
   } else /varset l1 1
   /varset l0 $char(cash) 
   /sellitem $l1
   /varset t9 15s
   :WaitSell
      /delay 0
      /if n $l0!=$char(cash) /goto :WaitEnd
   /if $t9>0 /goto :WaitSell
   :WaitEnd
   /varset t9 0
/return 

Not to be picky ...

Posted: Sat Aug 02, 2003 9:45 am
by MacroFiend
but wouldn't this fit better as $find(lastslot) instead of a whole new variable?

Posted: Sat Aug 02, 2003 9:50 am
by Valerian
what's it matter? same code either way, parsemacroparameter() is a fat pig that definately needs reworked somehow... maybe a table of funcs similar to the command list... I may look into modding it to do that eventually.

Posted: Sun Aug 03, 2003 6:56 am
by kagonis
If it works like I think it works, then this feature would be very nice to allways keep tradeskill tools in the same positions in your inventory.

Like, if you're making something that requres a hammer. Then you could write the macro in such a way that it remembers what bag and slot the hammer was taken from, then when combine is done put the hammer bag into that slot instead of just auto equipping it.

Is perhaps not a big feature, but it's these small nifty features that makes MQ so awesome :)

Posted: Mon Aug 11, 2003 11:06 pm
by Wildcat
When I attempt to run this I get a FIND_PACKNOTOPEN almost every time. I think that it has something to do with how long it takes to run Click before returning but I am not positive. If I run /finditem it opens the slot then returns error if i run finditem again it picks up the item. Any idea how to fix? I'm trying to open inventory, find item item, replace the primary slot with that item, put the old primary into a bag and close the inventory in one eq hotkey so i don't need ot have a macro running for it. So keeping it limited to 5 lines is key.

What I have now is:
/click i
/finditem "Foo"
/click left primary
/click left auto
/click i

Re: Ok, got bored... $GetLastFindSlot

Posted: Fri Jan 23, 2026 12:53 am
by xyilla

Re: Ok, got bored... $GetLastFindSlot

Posted: Fri Jan 23, 2026 12:55 am
by xyilla

Re: Ok, got bored... $GetLastFindSlot

Posted: Fri Jan 23, 2026 12:56 am
by xyilla

Re: Ok, got bored... $GetLastFindSlot

Posted: Fri Jan 23, 2026 12:58 am
by xyilla

Re: Ok, got bored... $GetLastFindSlot

Posted: Fri Jan 23, 2026 12:59 am
by xyilla

Re: Ok, got bored... $GetLastFindSlot

Posted: Fri Jan 23, 2026 1:00 am
by xyilla

Re: Ok, got bored... $GetLastFindSlot

Posted: Fri Jan 23, 2026 1:01 am
by xyilla