Ok, got bored... $GetLastFindSlot
Posted: 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:
EQLib_Main.cpp:
EQLib.h:
and EQLib_Commands:
returns "inv,<slot>" or "<mainslot>,<bagslot>" in a format usable by $item, or NULL if item not found.
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
Code: Select all
CHAR gLastFindSlot[MAX_STRING]={0};
Code: Select all
extern CHAR gLastFindSlot[MAX_STRING];
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);
}