Counting non-stack items macro.

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

Moderator: MacroQuest Developers

macrotoon
a ghoul
a ghoul
Posts: 106
Joined: Wed Sep 18, 2002 4:38 pm

Counting non-stack items macro.

Post by macrotoon » Fri Sep 27, 2002 9:44 am

I have 2 in here. One will count up to 10 items the other will count the total of them. This is for nonstackable items only.

I think when i ran it it only showed the correct amount for $v84, and the rest showed as 84 of xxx items. It might have been because the item names i put in, cant remember exactly.

It should work for stacked items also, but will tell you how many stacks you have of them, and not the total. You can refine it for stacks of items.

Gimme some feedback on my first posted macro please. Good, bad or ugly. I can handle them.

If we can improve on it, I'll post over on the depot.

Im goint to try it again tonight.


Code: Select all

| -------COUNTITEMS.MAC-------

#turbo
Sub Main
	/Varset v84 0
	/varset v85 0
	/varset v86 0
	/for v1 0 to 7
		/for v2 0 to $pack($v1,slots)
			/delay 0
			/if "$item($v1,$v2,name)"~~"$p0" /varadd v84 1
			/if "$item($v1,$v2,name)"~~"$p1" /varadd v85 1
			/if "$item($v1,$v2,name)"~~"$p2" /varadd v86 1
		/next v2
	/next v1
:echo
/echo $v84 $p0
/echo $v85 $p1
/echo $v86 $p2
/return

| -------COUNTITEMS.MAC-------

#turbo
Sub Main
	/Varset v84 0
	/varset v85 0
	/varset v86 0
	/for v1 0 to 7
		/for v2 0 to $pack($v1,slots)
			/delay 0
			/if "$item($v1,$v2,name)"~~"$p0" /if n $v84<10 /varadd v84 1
			/if "$item($v1,$v2,name)"~~"$p1" /if n $v85<10 /varadd v85 1
			/if "$item($v1,$v2,name)"~~"$p2" /if n $v86<10 /varadd v86 1
		/next v2
	/next v1
:echo
/echo $v84 $p0
/echo $v85 $p1
/echo $v86 $p2
/return

gingertips
a hill giant
a hill giant
Posts: 230
Joined: Wed Jun 26, 2002 3:47 am
Location: Tseu-Qorcam

Post by gingertips » Fri Sep 27, 2002 9:46 am

thanks - this could prove useful to a macro im writing!

macrotoon
a ghoul
a ghoul
Posts: 106
Joined: Wed Sep 18, 2002 4:38 pm

Post by macrotoon » Fri Sep 27, 2002 9:51 am

I actually have it in my routines.mac.

Actually i need to subtact one from the packs its looking in.

v1 is the pack number and v2 is the slots in the pack. if you have 10 slots v2 needs to count from 0 to 9.

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

Post by Valerian » Fri Sep 27, 2002 10:31 am

um... what's wrong with $count(itemname)?

macrotoon
a ghoul
a ghoul
Posts: 106
Joined: Wed Sep 18, 2002 4:38 pm

Post by macrotoon » Fri Sep 27, 2002 6:49 pm

:D $count(itemname)
Returns the total count of itemname in your inventory
:D

Well, after reading the manual, actually doing a search for count i found this feature.

I do think this is a bit easier and much faster than my way of doing it.

Thanks Valerian!

User avatar
eqsolro
a ghoul
a ghoul
Posts: 113
Joined: Fri Sep 13, 2002 4:20 pm
Location: Germany

Re: Counting non-stack items macro.

Post by eqsolro » Sat Sep 28, 2002 6:04 pm

Great ....

but i dont understand is the Varadd function

when i add something


|kill vars
/zapvars
|set Vars
/varset v1 0

|Check, checks Slots in Bag 0 - means Bag 1 left up
Sub Check
/if v1 >=9 /goto :exit
|add 1 to v1
/varadd v1 1
/if "$item(0,v1,empty)"~~"TRUE" {/echo slot is filled} else {/call Check}
/return



Ok, this breaks without Errors .. but i wont work anyway .... yust for fun - i set

/echo v1 - after /varadd an he counts

1.0
2.0
3.0
4.0
5.0

but it never stops ;) - damn, why he count it with dot zero ???
.0 after every number .. hmm ore im using a wrong format ?
MAybe someone have a nice little idear ... and .. yes .. it was a fantastic holiday .. hehe :)

User avatar
DeathSpiral
a ghoul
a ghoul
Posts: 95
Joined: Thu Aug 22, 2002 6:31 pm

Re: Counting non-stack items macro.

Post by DeathSpiral » Sat Sep 28, 2002 6:31 pm

eqsolro wrote:/echo v1 - after /varadd an he counts

1.0
2.0
3.0
4.0
5.0

but it never stops ;) - damn, why he count it with dot zero ???
.0 after every number .. hmm ore im using a wrong format ?
MAybe someone have a nice little idear ... and .. yes .. it was a fantastic holiday .. hehe :)
Because /var(add|sub|calc) doesn't calc the equation as an int, it does it as some sort of floating number (not sure which, didn't open the source to check). If you want it to strip the .0 the easiest way would be do....

Code: Select all

/echo $int($v1)
which will produce the plain old output of

Code: Select all

1
2
3
4
5
(used the same output from above).
I am orc pawn, hear me yell for centurians...