Ok, got bored... $GetLastFindSlot

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

Moderator: MacroQuest Developers

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

Ok, got bored... $GetLastFindSlot

Post by Valerian » Fri Aug 01, 2003 11:35 pm

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.

User avatar
dont_know_at_all
Developer
Developer
Posts: 5450
Joined: Sun Dec 01, 2002 4:15 am
Location: Florida, USA
Contact:

Post by dont_know_at_all » Fri Aug 01, 2003 11:59 pm

Can you supply a macro to show how this is used?

thanks.

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

Post by EqMule » Sat Aug 02, 2003 8:37 am

Awesome work! thanks!
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.

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

Post by Valerian » Sat Aug 02, 2003 9:14 am

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 

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

Not to be picky ...

Post by MacroFiend » Sat Aug 02, 2003 9:45 am

but wouldn't this fit better as $find(lastslot) instead of a whole new variable?

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

Post by Valerian » Sat Aug 02, 2003 9:50 am

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.

kagonis
a hill giant
a hill giant
Posts: 228
Joined: Sat May 24, 2003 8:48 pm

Post by kagonis » Sun Aug 03, 2003 6:56 am

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 :)

Wildcat
orc pawn
orc pawn
Posts: 21
Joined: Mon Aug 11, 2003 11:04 pm

Post by Wildcat » Mon Aug 11, 2003 11:06 pm

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