- Joined
- Mar 29, 2004
- Messages
- 1,991
Item stacking is a nasty business. And since I've been grappling with it recently for my All-In-One Micro Map, I thought it good to pass on my findings in the form of a pleasant little tutorial.
What you need:
- Basic triggering knowledge
- Basic item editing knowledge
For your stacking item, you need two items - a "runic" one (Stats - Use Automatically When Acquired = True) and a "non-runic" one (Stats - Use Automatically When Acquired = False). Now, the player will be interacting with both of these in slightly different ways, so the same name is probably essential. However, the Item Editor lacks an "Editor - Suffix" field, so to avoid confusion give both versions different names and change them back when you're finished. Why? Well, with a runic item, even when your inventory is full, you'll still be able to stack.
Now, you can create a very simple item stacking system thus:
So, what if the player has a full inventory and no non-runic potion to add to? We get a nice non-runic potion deposited on the ground. Oh oh. In the heat of battle, the hero might pick up the runic version somewhere else after dropping something, and later go back to that initially dropped non-runic potion - argh, we've got two stacks! This can be very nasty if you've dropped a large stack in a stash or backpack and forgotten about it, then built up a new stack. Maybe two heroes have two different stacks, and one wants to give its stack to the other - again, two large stacks. This might not happen too often, but it's an inconvenience for the poor player.
So we need something a little more complex. Note that in a multiplayer, or even multihero environment, you may need to resort to local variables and jass and all that madness. But we don't like that, so I'll stick to the easy version.
For this you will need two variables. These will hold the number of non-runic potions you have (I'll get to that later) and one to hold the number of charges in the newly acquired item. For this example: Item_TempPotionCount and Item_TempChargeCount.
First of all, the trigger must respond to an item being acquired. The item must be either of the two versions of the stackable item.
We must make sure our temporary variables are reset to avoid spillage from previous trigger executions. At this stage, you'd be initialising your local variables.
And finally, if TempPotionCount is not 2 and it's not 1 either, it's 0. So we create a non-runic potion for the hero, and again leave TempChargeCount at 0.
0. Initialise variables: TempPotionCount and TempChargeCount to 0.
1. Establish how many non-runic potions we have in the hero's inventory.
2. If we have 2, we've picked a stack while we have a stack - set charges and remove the picked item.
3. If we have 1,
4. If we picked a rune while we have a stack - set charges.
5. Else we picked a stack off the ground - do nothing.
6. If we have 0, we've picked a rune while we have no stack - create a non-runic potion.
7. Add the number of charges onto the non-runic potion in the inventory.
Thank you, and good night.
RDZ
What you need:
- Basic triggering knowledge
- Basic item editing knowledge
For your stacking item, you need two items - a "runic" one (Stats - Use Automatically When Acquired = True) and a "non-runic" one (Stats - Use Automatically When Acquired = False). Now, the player will be interacting with both of these in slightly different ways, so the same name is probably essential. However, the Item Editor lacks an "Editor - Suffix" field, so to avoid confusion give both versions different names and change them back when you're finished. Why? Well, with a runic item, even when your inventory is full, you'll still be able to stack.
Now, you can create a very simple item stacking system thus:
-
Stacking HealPotion
-
Events
- Unit - A unit owned by Player 1 (Red) Acquires an item
-
Conditions
- (Item-type of (Last created item)) Equal to Potion of Healing (Runic)
-
Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- ((Hero manipulating item) has an item of type Potion of Healing (Non-Runic)) Equal to True
-
Then - Actions
- Item - Set charges remaining in (Item carried by (Hero manipulating item) of type Potion of Healing (Non_Runic)) to ((Charges remaining in (Item carried by (Hero manipulating item) of type Potion of Healing(Non-Runic))) + 1)
-
Else - Actions
- Hero - Create Potion of Healing (Non-Runic) and give it to (Hero manipulating item)
-
If - Conditions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
Events
So, what if the player has a full inventory and no non-runic potion to add to? We get a nice non-runic potion deposited on the ground. Oh oh. In the heat of battle, the hero might pick up the runic version somewhere else after dropping something, and later go back to that initially dropped non-runic potion - argh, we've got two stacks! This can be very nasty if you've dropped a large stack in a stash or backpack and forgotten about it, then built up a new stack. Maybe two heroes have two different stacks, and one wants to give its stack to the other - again, two large stacks. This might not happen too often, but it's an inconvenience for the poor player.
So we need something a little more complex. Note that in a multiplayer, or even multihero environment, you may need to resort to local variables and jass and all that madness. But we don't like that, so I'll stick to the easy version.
For this you will need two variables. These will hold the number of non-runic potions you have (I'll get to that later) and one to hold the number of charges in the newly acquired item. For this example: Item_TempPotionCount and Item_TempChargeCount.
First of all, the trigger must respond to an item being acquired. The item must be either of the two versions of the stackable item.
-
Potion Stacking Heal
-
Events
- Unit - A unit owned by Player 1 (Red) Acquires an item
-
Conditions
-
Or - Any (Conditions) are true
-
Conditions
- (Item-type of (Item being manipulated)) Equal to Potion of Healing (Runic)
- (Item-type of (Item being manipulated)) Equal to Potion of Healing (Non-Runic)
-
Conditions
-
Or - Any (Conditions) are true
- Actions
- ...
-
Events
We must make sure our temporary variables are reset to avoid spillage from previous trigger executions. At this stage, you'd be initialising your local variables.
- Set Item_TempPotionCount = 0
- Set Item_TempChargeCount = 0
-
For each (Integer A) from 1 to 6, do (Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- (Item-type of (Item carried by (Hero manipulating item) in slot (Integer A))) Equal to Potion of Healing
-
Then - Actions
- Set Item_TempPotionCount = (Item_TempPotionCount + 1)
- Else - Actions
-
If - Conditions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- Item_TempPotionCount Equal to 2
-
Then - Actions
- Set Item_TempChargeCount = (Charges remaining in (Item being manipulated))
- Item - Remove (Item being manipulated)
- Else - Actions
-
If - Conditions
- ...
And finally, if TempPotionCount is not 2 and it's not 1 either, it's 0. So we create a non-runic potion for the hero, and again leave TempChargeCount at 0.
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- Item_TempPotionCount Equal to 1
-
Then - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- (Item-type of (Item being manipulated)) Equal to Potion of Healing
-
Then - Actions
- Set Item_TempChargeCount = (Charges remaining in (Item being manipulated))
- Else - Actions
-
If - Conditions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
Else - Actions
- Hero - Create Potion of Healing and give it to (Hero manipulating item)
-
If - Conditions
- Item - Set charges remaining in (Item carried by (Hero manipulating item) of type Potion of Healing) to ((Charges remaining in (Item carried by (Hero manipulating item) of type Potion of Healing)) + Item_TempChargeCount)
0. Initialise variables: TempPotionCount and TempChargeCount to 0.
1. Establish how many non-runic potions we have in the hero's inventory.
2. If we have 2, we've picked a stack while we have a stack - set charges and remove the picked item.
3. If we have 1,
4. If we picked a rune while we have a stack - set charges.
5. Else we picked a stack off the ground - do nothing.
6. If we have 0, we've picked a rune while we have no stack - create a non-runic potion.
7. Add the number of charges onto the non-runic potion in the inventory.
Thank you, and good night.
RDZ
Last edited: