PDA

View Full Version : Stacking Items

DigitalDemon
12-21-2007, 06:36 PM
ITEM STACKING TUTORIAL
There have been so many questions regarding the combining and/or stacking of items so i decided to make a tutorial!

1] Start
- Create a blank map
- Make a hero inside it
- Make 3 (or more) of the same item near the hero.

2] Stacking Items
- The triggers used for this are not complex. In fact, it is easier than most things.

Basically, what you have to do is to check if the player has an item in his inventory that is the same as the item he picked up. If he does then it stacks the item, otherwise it just.. does nothing and gives the item as normal.

Stack
Events
Unit - A unit Acquires an item
Conditions
((Hero manipulating item) has an item of type (Item-type of (Item being manipulated))) Equal to True
(Item being manipulated) Not equal to (Item carried by (Hero manipulating item) of type (Item-type of (Item being manipulated)))
Actions
Item - Set charges remaining in (Item carried by (Hero manipulating item) of type (Item-type of (Item being manipulated))) to ((Charges remaining in (Item carried by (Hero manipulating item) of type (Item-type of (Item being manipulated)))) + (Charges remaining in (Item being manipulated)))
Hero - Drop (Item being manipulated) from (Hero manipulating item)
Item - Remove (Item being manipulated)

Of course, to shorten the lines you could just assign variable to those things but it's your choice!

Events
Unit - A unit Acquires an item

This makes the trigger run when a player picks up an item.

Conditions
((Hero manipulating item) has an item of type (Item-type of (Item being manipulated))) Equal to True
(Item being manipulated) Not equal to (Item carried by (Hero manipulating item) of type (Item-type of (Item being manipulated)))

This checks if the player has the item and also if the item the player carries is NOT the same item he picked up. This prevents loops and crashes.

Actions
Item - Set charges remaining in (Item carried by (Hero manipulating item) of type (Item-type of (Item being manipulated))) to ((Charges remaining in (Item carried by (Hero manipulating item) of type (Item-type of (Item being manipulated)))) + (Charges remaining in (Item being manipulated)))
Hero - Drop (Item being manipulated) from (Hero manipulating item)
Item - Remove (Item being manipulated)

The first line adds the amount of charges in the picked up item to the amount of charges in the item the hero already had.

The second line makes the hero drop the item he just picked up and the third one removes it!

And you're finished! Now any items you pick up will be automatically stacked.
The only problem is if you want to unstack the items.
How would you do that?
Well, you could, for example make a trigger which takes half the charges in the chosen slot and drops that many. The problem is that it can become odd numbers and you can't have half an item... The WE automatically rounds it down so you lose 1 charge.

Unstack
Events
Player - Player 1 (Red) types a chat message containing -unstack as A substring
Player - Player 2 (Blue) types a chat message containing -unstack as A substring
Player - Player 3 (Teal) types a chat message containing -unstack as A substring
Player - Player 4 (Purple) types a chat message containing -unstack as A substring
Player - Player 5 (Yellow) types a chat message containing -unstack as A substring
Player - Player 6 (Orange) types a chat message containing -unstack as A substring
Player - Player 7 (Green) types a chat message containing -unstack as A substring
Player - Player 8 (Pink) types a chat message containing -unstack as A substring
Player - Player 9 (Gray) types a chat message containing -unstack as A substring
Player - Player 10 (Light Blue) types a chat message containing -unstack as A substring
Player - Player 11 (Dark Green) types a chat message containing -unstack as A substring
Player - Player 12 (Brown) types a chat message containing -unstack as A substring
Conditions
Actions
Set HeroPos = (Position of Hero[(Player number of (Triggering player))])
Set Slot = (Integer((Substring((Entered chat string), 10, 10))))
Set Charges = ((Charges remaining in (Item carried by Hero[(Player number of (Triggering player))] in slot Slot)) / 2)
Item - Set charges remaining in (Item carried by Hero[(Player number of (Triggering player))] in slot Slot) to Charges
Item - Create (Item-type of (Item carried by Hero[(Player number of (Triggering player))] in slot Slot)) at HeroPos
Item - Set charges remaining in (Last created item) to Charges
Custom script: call RemoveLocation(udg_HeroPos)

Oh, and before you use the unstack trigger, you need to define Hero[x] and create the other variables.

Example map:

PurplePoot
12-21-2007, 07:51 PM

DigitalDemon
12-21-2007, 08:01 PM
Mine is simpler to understand IMO. ( No offense )

PurplePoot
12-22-2007, 12:36 AM
Also, this is more of a system than a tutorial. However, I find that Rao's is as easy to understand, personally, or even easier. (Not that it would really make much of a difference to me...)