The way items are developed in WC3 is everything else than comfortable for users of the map editor. I was experiencing uncountable bugs when making use of items in my custom maps. Ways to avoid those bugs are sometimes not easy to see. #1 rule when manipulating items is: What ever you do with them, give it some time to work.
Example #1: Referring to dropped items[/size]
Maybe you want a unit to drop an item that you need to manipulate or refer to immediately. This won't work in most cases. Let's see an example:
Event: ... Condition: ... Action: Hero - Drop (item being manipulated) from (Triggering unit) Item - Set charges remaining in (Last dropped item) to 2
This won't work, because the procedure of dropping items needs some time to complete. To avoid misfunction with this, just change the trigger like the one below:
Event: ... Condition: ... Action: Hero - Drop (item being manipulated) from (Triggering unit) Wait 0.10 seconds Item - Set charges remaining in (Last dropped item) to 2
And it will work!
The same problem will appear when giving items to units. Example #2:
Event: ... Condition: ... Action: For each (Integer A) from 1 to 6 do (Actions) Loop - Actions Hero - Create healing salve and give it to (Triggering unit) Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer A) to 2
In this case your 'Triggering unit' should receive 6 healing salves with 2 charges each, but it won't, because giving items to units also takes some time to complete. Another problem is that you cannot wait in loops, so you have to do it this way: Event: ... Condition: ... Action: Hero - Create healing salve and give it to (Triggering unit) Wait 0.10 seconds Item - Set charges remaining in (Item carried by (Triggering unit) in slot (1) to 2 Hero - Create healing salve and give it to (Triggering unit) Wait 0.10 seconds Item - Set charges remaining in (Item carried by (Triggering unit) in slot (2) to 2 ...
Sucks, right?
[size=150]Example #3: Manipulating items from dead or replaced units.
Maybe you know the Syllabear form DotA. It is a hero that can summon a bear with inventory, able to buy, carry and use items. If the bear dies, you can re-summon it again, still keeping every item once purchased. Try to create something like this with the editor. You will suffer! The problem is, that you cannot revive units like heros via triggers. So once the bear dies, you have to create a new bear, giving every item to it, its predecessor had. To do so, you should know that even if you set the value "Drop items upon death" for the bear's inventory in the object editor to 'false' it will drop them, as soon as the dead bear's body is rotten. So every item will not appear upon dead directly, but a bit later, when the body is gone. Referring now to any item the dead unit was once carrying, will fail.
To avoid items beeing dropped after a units body has beed rotten, use:
Unit - Remove (Triggering unit) from the game.
Where 'Triggering unit' is meant to be the unit that was dying here.
In this case, the items your 'Triggering unit' was carrying will now be removed too. Note, that they will also be dropped automatically when the unit is removed via triggers. You won't recognize it in any way, but referring to any item owned by your 'Triggering unit' won't lead to anything. Let's see an example how to make re-summoning work correctly:
1. Storing our units (refered via a variable called 'bear') inventory in an array (called 'inventory' of type 'item-type'):
Event: Condition: Action: For each (Integer A) from 1 to 6 do (Actions) Loop - Actions Set inventory[(Integer A)] = Item-type of (Item carried by (bear) in slot (Integer A))
2. Removing the unit upon death
Event: Unit - A unit owned by player 1 (red) dies. Condition: ... Action: Unit - Remove (Triggering) unit from the game
3. Creating a new unit and giving every item of its predecessor to it: Event: ... Condition: ... Action: Unit - Create 1 bear for player 1 (red) at ([wherever you want to spawn it]) facing [whatever you want it to face it] Hero - Create inventory[1] and give it to (Last created unit) Hero - Create inventory[2] and give it to (Last created unit) ...
If you don't need to refer the given items immediately, you can also use a loop to give them to the bear.