Bag Walking

Help section from before the user variable changes that broke all macros

Moderator: MacroQuest Developers

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

Bag Walking

Post by kagonis » Mon May 26, 2003 9:12 am

Okay, since the finditem isnt working, I'm trying to find some other way to handle the inventory places etc.

So far I have made it so all bags are set up in a certain way, and must be open. Assigned a variable with the x/y coordinates of every single slot, and named them as:
/varset b01s01 "x y"
Wich tells me that this is bag 1 slot 1.

Anyway, as you can see in my mino brew script it is quite messy. having to write down a bit of code for every slot can be a bit too much.

Code: Select all

sub chkCombiner
	:comb01
		/mouseto $comb01
		/sendkey down Shift
		/click left
		/sendkey up Shift
		/call chkCursor
	:comb02
		/mouseto $comb02
		/sendkey down Shift
		/click left
		/sendkey up Shift
		/call chkCursor
	:comb03
		/mouseto $comb03
		/sendkey down Shift
		/click left
		/sendkey up Shift
		/call chkCursor
	:comb04
		/mouseto $comb04
		/sendkey down Shift
		/click left
		/sendkey up Shift
		/call chkCursor
	:comb05
		/mouseto $comb05
		/sendkey down Shift
		/click left
		/sendkey up Shift
		/call chkCursor
	:comb06
		/mouseto $comb06
		/sendkey down Shift
		/click left
		/sendkey up Shift
		/call chkCursor
/return
Above is some code for a 6 slot combiner check I made to make sure my container was empty before each combine.

Now, I would much rather have something along the lines in my next example (using some PHP functions to illustrate in the example)

Code: Select all

sub chkCombiner
	for ($i=1;$i<=6;$i++) {
		:comb0$i
			/mouseto ${"comb0".$i}
			/sendkey down Shift
			/click left
			/sendkey up Shift
			/call chkCursor
	}
/return
Anyway, if it isn't possible then so be it, then I will jsut use the old ugly way, it works, but is a mess to debug :p

stigmatine
a lesser mummy
a lesser mummy
Posts: 50
Joined: Wed Oct 02, 2002 2:52 pm

Post by stigmatine » Mon May 26, 2003 2:38 pm

Just a side note, if you open all of the bags that will be needed once your int he forge or brew barrel or whatever screen, then you wont have so much code later, just open all the bags then /sendkey down ctrl/shift ,which ever you prefer, will do the trick.

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

Post by kagonis » Mon May 26, 2003 5:36 pm

Well the above chkCombiner sub is used mainly as a kind of automated error correction, in case wrong items or multiple items have ben put in the combiner, then this function empties the bag.

the chkMouse is a sub that checks what is on the cursor and acts accordingly, auto equips, destroys or puts in predefined slots, depending on my need the particular macro.

I have been thinking about actually writing a sub routing merely for opening the bags, but that would probably be a waste of code lines ;)

User avatar
grimjack
Macro Author
Macro Author
Posts: 525
Joined: Thu Nov 07, 2002 6:51 am
Contact:

Somthing along the lines of this.

Post by grimjack » Mon May 26, 2003 7:57 pm

This would run that on a set of locs defined in the array.
Not checked for errors. I hope this helps.

Thanks

Code: Select all

#define CombArraySz v50
/varset a(3,0) "x y"
/varset a(3,1) "x y"
/varset a(3,2) "x y"
/varset a(3,3) "x y"
/varset a(3,4) "x y"
/varset a(3,5) "x y"
/varset CombArraySz 6
/varset CombCount 0

sub chkCombiner
   :comb
   /mouseto $a(3,$CombCount)
   /sendkey down Shift
   /click left
   /sendkey up Shift
   /call chkCursor
   /varadd CombCount
   /if n $Combcount>$CombArraySz /goto :combdone
   /goto :comb
   :combdone
   /varset #CombCount 0
/return

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

Post by kagonis » Tue May 27, 2003 8:29 am

Nice, thanks :)

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Tue May 27, 2003 9:07 am

Shark may have a change to ParseMouseLoc that will reenable /finditem. I haven't had time to take a look at it or test it yet (works for him), but if everything pans out I'll update the CVS in a day or so.

Sorry for the delay, had a very busy weekend and haven't had time to do much more than argue with Shark about why an external location file (locations.txt) is necessary :)
MQ2: Think of it as Evolution in action.

User avatar
grimjack
Macro Author
Macro Author
Posts: 525
Joined: Thu Nov 07, 2002 6:51 am
Contact:

Post by grimjack » Tue May 27, 2003 11:01 am

Mckorr wrote:Shark may have a change to ParseMouseLoc that will reenable /finditem. I haven't had time to take a look at it or test it yet (works for him), but if everything pans out I'll update the CVS in a day or so.

Sorry for the delay, had a very busy weekend and haven't had time to do much more than argue with Shark about why an external location file (locations.txt) is necessary :)
Don't apologize. RL comes before all this crap. I hope you are enjoying your new Motercycle :)

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

Post by kagonis » Tue May 27, 2003 9:05 pm

Hmm, didn't see this update, would be awesome if /finditem was made to work again :)

Anyway, I was going to make a seperate post with the folowing, but basically it is just an expansion to my bag walk thought, here goes...


So far I only have an idea, and wanted to get some expert input before actually starting, after all I know practically nothing about MQ scripting, just started last weekend.

The idea is, that since MQ cannot tell you the positions of each bag, then we need to tell it to MQ.

We do this simply by opening all our bags and possible combiners. Then placing all our bags (and combiners) as we would like them to be organized from now on and forever. Then we place our cursor at the center of the top-left slot in that container and get the /mousepos.

We feed that info to our macro by a simple variable, or in an array, haven't figured out completely yet what is best, after all when you can only make 100 v# variables you have to conserve the use of them :)

Anyway, each bag is defined with at least 2 pieces of information, perhaps 3 if UI slot distance differs, I don't know if it does, but in my default UI the exact distance between 2 slots in the bag is 40.

Then when we walk a bag we increment/decrement our x y position by 40 each time we want to look at the contents of the next slot.

The contents of each slot should be saved somewhere (in an array was my idea) so that we don't have to do the actual bagwalk except when we can't find the component/item we're looking for, that should make the bagwalk, walk the bags and updates their contents, so we can send the pointer directly to the right slot in the right bag.

Here is my base macro code, haven't tested it yet, but tell me what you think, and please feel free to come with suggestions and optimizations

Edit 1: I have tested the following code, and it does what it is supposed to, it walks each bag checking it's contents.

Now I need to make a routine that can look in the array for the items rather than in the bags, and then substract the items from the bag as well.

The idea is to speed up the script by not making the pointer travel to each slot to check it's contents between each combine, but only when it knows that there is something in the slot that it needs.

I just don't know if I can access the arrays as I have envisioned. With my current knowledge of MQ scripting I would think I actually have to walk my "contents" array, checking each entry for the item I need, then move the cursor to the slot.
As you can see the arrays are numbered with bag and slot numbers, ie; $a(1,1) would give me the contents of slot 1 in bag 1, so when walking my array I have to walk it in 2 loops, just like it was added.
1 loop for the bags, with a sub-loop for the slots, but will this get slower to search, than actually just moving the cursor to each bag/each slot every time?
How would it be best optimized?

Edit 2: Well, I added the chkItem sub routine, tested it and it works. It is rather slow though, perhaps it could go faster if I enable #turbo, will test after this, but perhaps someone would have an idea on how to optimize it?

Edit 3: It sure went a lot faster with #turbo enabled, so much faster that the macro forgot to drop the item picked up, into the right slot again, thereby shuffling it all 1 slot (and even 1 bag if last slot in previous) ahead. Throwing in a few delays and retesting it.

Edit 4: It just needed a single /delay 1 extra, and it most certainly is faster to search the array than the actual bags. Fixed the example below with the new /delay.

Edit 5:Okay, was thinking a bit about the combiners (containers to combine in). The easiest way for to find the destroy button is to do a minor calculation:

/varcalc btnDestroyX x+20
/varcalc btnDestroyY y+((s/2)*40)+35

Where:
x is the X coordinate of the top-left slot (the slot we know the coordinates of).
y is the Y coordinate of the top-left slot (the slot we knoe the coordinates of).
s is the total number of slots in the current combiner.

Remember, all these numbers are if using the default UI, or at least default bag UI.

Code: Select all

#turbo
#define totBags v1
#define curBag v2
#define curSlot v3
#define mouseX1 v4
#define mouseX2 v5
#define mouseY v6
#define chkCol v7
#define temp v8

sub main
	/varset a(21,1) "1205 120"
	/varset a(22,1) 10
	/varset a(21,2) "1105 120"
	/varset a(22,2) 10
	/varset a(21,3) "1005 120"
	/varset a(22,3) 10
	/varset a(21,4) "905 120"
	/varset a(22,4) 10
	/varset a(21,5) "805 120"
	/varset a(22,5) 10
	/varset a(21,6) "705 120"
	/varset a(22,6) 10
	/varset a(21,7) "605 120"
	/varset a(22,7) 10
	/varset a(21,8) "505 120"
	/varset a(22,8) 10
	/varset totBags 7
	/varset chkCol 0
	/varset temp "Pearl"
	/call bagWalk
	/delay 2s
	/echo Searching for $temp
	/call chkItem
/return

sub chkItem
	/varset curBag 1
	:bagLoop
		/varset curSlot 1
	:slotLoop
		/if "$a($curBag,$curSlot)"~~"$temp" {
			/echo Found << $a(1$curBag,$curSlot)x $a($curBag,$curSlot) >> in bag $curBag, slot $curSlot
			/goto :End
		} else /if n $curSlot<$a(22,$curBag) {
			/varadd curSlot 1
			/goto :slotLoop
		}
		/if n $curBag<$totBags {
			/varadd curBag 1
			/goto :bagLoop
		}
	:End
/return

sub bagWalk
	/varset curBag 1
	:bagLoop
		/mouseto $a(21,$curBag)
		/varset curSlot 1
		/varset mouseX1 $mouse(X)
		/varset mouseX2 $mouse(X)
		/varadd mouseX2 40
		/varset mouseY $mouse(Y)
	:slotLoop
		/varcalc chkCol $curSlot%2
		/if n $chkCol==1 /mouseto $mouseX1 $mouseY
		/if n $chkCol==0 /mouseto $mouseX2 $mouseY
		/sendkey down shift
		/click left
		/sendkey up shift
		/delay 1
		/if "$cursor()"!="NULL" {
			/varset a($curBag,$curSlot) "$cursor(name)"
			/varset a(1$curBag,$curSlot) $cursor(stack)
			/if n $chkCol==1 /mouseto $mouseX1 $mouseY
			/if n $chkCol==0 /mouseto $mouseX2 $mouseY
			/click left
			/delay 1
		} else {
			/varset a($curBag,$curSlot) "empty"
			/varset a(1$curBag,$curSlot) 0
		}
		/if n $curSlot<$a(22,$curBag) {
			/varadd curSlot 1
			/if n $chkCol==0 /varadd mouseY 40
			/goto :slotLoop
		}
		/if n $curBag<$totBags {
			/varadd curBag 1
			/goto :bagLoop
		}
	:End
	/echo Finished indexing the bags.
/return

User avatar
grimjack
Macro Author
Macro Author
Posts: 525
Joined: Thu Nov 07, 2002 6:51 am
Contact:

Post by grimjack » Wed May 28, 2003 2:51 am

I would be hesitant to work too much on this with the new code maybe coming down the pipe. /finditem will totaly replace the need to do this sort of thing. What you have put togather though looks good.

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Wed May 28, 2003 10:32 am

I have Shark's code, so far looks good. Well, it compiled and did /click left auto and /click left destroy okay. I still need to read through it and see what he's actually doing.

Then I have to figure out exactly what /finditem does and come up with a macro to test that :) I did a simple /finditem "agate" yesterday and kept getting the "can't find" message, but that might be me doing something completely off base.

I also need to check how he has set it up to work with containers, etc. I never really used a lot of those commands before, so will have to read the source code, and I guess the MQ readme file, to figure it out.

Oh, and the new motorcycle is still disassembled... well, the head is disassembled. Can't work on it until I assemble the new patio furniture, and finish polyeurethaning the new kitchen table and chairs. Just no room in the garage!
MQ2: Think of it as Evolution in action.

boldor
a ghoul
a ghoul
Posts: 94
Joined: Tue Sep 10, 2002 11:46 am

Post by boldor » Wed May 28, 2003 1:47 pm

Couldn't the location.txt used by the mouse parsing routine be modified to include the XML locations of INV 1-8 and then OPEN bag 1-8? Then you could possible do something similar to the Autohunter:

/click right INV1
/click left Bag1slot0

yada yada