- Joined
- Sep 24, 2010
- Messages
- 17
Triggered Item Drops
In this tutorial, you will learn how to make creeps drop items upon death using triggers. The tutorial will be split into 5 sections:
Triggered item drops are used simply to make a creep drop one or more items.
Now, I know that some of you might be thinking:
"Why can't I easily put the drop table for the creep? I don't need triggers!"
That may work in some specific cases, but otherwise it is not the most controlled method. If you give a creep an item drop table, when the creep dies, the table is gone. Unless you have a method for reviving units, the table will not be retained and the respawned creeps from then on will not drop the appropriate items. So, it is useless if you're making an ORPG (Online role playing game) if all the creeps have one chance to drop an item, am I correct?
If you got mixed up, here is the conclusion:
Respawned creeps will not drop the appropriate items when using the creep item table in the World Editor.
For example, this is a simple creep respawn:
[trigger=Creep revive]Creep Respawn
Events
Unit - A unit owned by Player 12 (Brown) Dies
Conditions
Actions
Wait 13.00 seconds
Unit - Create 1 (Unit-type of (Triggering unit)) for Player 12 (Brown) at (Position of (Triggering unit)) facing Default building facing degrees
[/trigger]
The above trigger is creating a substitute for the dead creep, not reviving it, so the item drop table will be lost, which is why we must use triggers!
Triggered item drops are made using a percentage system similar to the ones used in item drop tables.
The trigger size varies between the number of items you want the creep to drop. In the trigger, we will put in a random number between 1 and 100, to represent the chances of dropping the item. Why from 1 to 100? Using 1 to 100 is the easiest way to represent percentages, and after all, is there such thing as a 234% chance to drop an item in an item drop table? Though it still works if you make the random number between 1 and 460, 1 to 100 makes it simpler to choose values.
Note: You can use a random integer between 1 and 1,000 for VERY RARE boss item drops, so here is another advantage of triggered item drops!
Okay, so let's say we put the random number between 1 and 100, what now?
Now, we make conditions to resemble item percentages, you now... the old "if-then-else" actions.
We make the condition like this: If the random number between 1 and 100 is less than or equal to 30, then there will be a 30% chance to drop an item; understand better? That is for one item though. To make 2 items drop, you will need 2 conditions like this: If the random number between 1 and 100 is less than or equal to 30, then create a small potion; and now under the first "if-then-else" block, we put another "if-then-else" block and use the condition If it is less than or equal to 50.
You will learn more about multiple item drops in the last chapter.
Note: Make sure you have understood chapter 1 and 2 before proceeding; if not, then reread them.
What we need in a triggered item drop is 1 integer variable, that's it. (as well as one location variable to remove leaks)
Okay, what we need is a an integer variable. Variables simply reference to objects or data for later or repeated use, and these are very important to any map. There are many types of variables, each can store different types of values.
Now, how do we make a variable? Open the trigger editor (f4).
Then open the variable editor from the trigger editor window (ctrl+B).
Here we are. If you click on Add Variable, you will find several types of variables. In this case, we want an integer variable, which is any whole number (non-decimal).
An integer can be set to any number you want, including random numbers, all from the action menu when creating triggers, it is the action: Set variable = value.
The purpose of this integer variable is to store the random number we retrieve. Simple, right?
What we need in a triggered item drop is 1 integer variable, that's it. (as well as one location variable to remove leaks)
Okay, what we need is a an integer variable. Variables simply reference to objects or data for later or repeated use, and these are very important to any map. There are many types of variables, each can store different types of values.
Now, how do we make a variable? Open the trigger editor (f4).

Then open the variable editor from the trigger editor window (ctrl+B).

Here we are. If you click on Add Variable, you will find several types of variables. In this case, we want an integer variable, which is any whole number (non-decimal).
An integer can be set to any number you want, including random numbers, all from the action menu when creating triggers, it is the action: Set variable = value.

The purpose of this integer variable is to store the random number we retrieve. Simple, right?
Okay, you can relax now, the hard part is behind you!
Now that you hopefully understood the last 3 chapters, we shall begin with the trigger. In my first example, we will make a trigger for a kobold to drop a scroll of healing with 50% chance drop rate. First make the variable of type integer and name it: KoboldItemDrop, to stay organized.
Now let's start the trigger. Create the event: Unit - A unit of Player 12 (Brown) dies. If the creeps or hostile creatures in your map belong to a different player, change the player that the event is corresponding to. Put the condition that the triggering unit is a kobold.
Now we need to set the variable to a random number between 1 and 100. To do this, go to the Set Variable action and then choose KoboldItemDrop as the variable to set. Go to the value field, and choose Math - Random number between 1 and 100. The reason we must use a variable for this is that if we choose a random number between 1 and 100, it won't be the same number as last time. Once we get our first random number, we will store it so that will be the number we reference to.
Create an if-then-else block. Use Integer Comparison in the if-conditions (this is to compare KoboldItemDrop) and put in the first field the KoboldItemDrop variable.
In the second field, you will put less than or equal to. In the third field, you will put 50
Now under the "Then" actions, put the item dropped at the position of triggering unit (scroll of healing).
Now, our trigger should be something like this:
This is for 1 item however. If you want 2 or more items to drop, you would need more if-then-else blocks. If you want the items to drop at an individual chance, the if-then-else blocks will be independent, or stand-alone outside of any other blocks. However, if you want only 1 item to drop per creep, you will need a chain of if-then-else blocks. The first "if" will be for the lowest percentage, and then the next block would occur in the "else" section of the first. That "if" would have the next percentage, and so on for all the items in its drop table.
Now that you hopefully understood the last 3 chapters, we shall begin with the trigger. In my first example, we will make a trigger for a kobold to drop a scroll of healing with 50% chance drop rate. First make the variable of type integer and name it: KoboldItemDrop, to stay organized.
Now let's start the trigger. Create the event: Unit - A unit of Player 12 (Brown) dies. If the creeps or hostile creatures in your map belong to a different player, change the player that the event is corresponding to. Put the condition that the triggering unit is a kobold.

Now we need to set the variable to a random number between 1 and 100. To do this, go to the Set Variable action and then choose KoboldItemDrop as the variable to set. Go to the value field, and choose Math - Random number between 1 and 100. The reason we must use a variable for this is that if we choose a random number between 1 and 100, it won't be the same number as last time. Once we get our first random number, we will store it so that will be the number we reference to.

Create an if-then-else block. Use Integer Comparison in the if-conditions (this is to compare KoboldItemDrop) and put in the first field the KoboldItemDrop variable.

In the second field, you will put less than or equal to. In the third field, you will put 50
Now under the "Then" actions, put the item dropped at the position of triggering unit (scroll of healing).
Now, our trigger should be something like this:
-
Kobold Item Drop
-
Events
-
Unit - A unit owned by Player 12 (Brown) Dies
-
-
Conditions
-
(Unit-type of (Triggering unit)) Equal to Kobold
-
-
Actions
-
Set KoboldItemDrop = (Random integer number between 1 and 100)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
KoboldItemDrop Less than or equal to 50
-
-
Then - Actions
-
Set ItemDropLoc = Position of (Triggering Unit)
-
Item - Create Scroll of Healing at ItemDropLoc
-
Custom script: call RemoveLocation(udg_ItemDropLoc)
-
-
Else - Actions
-
Do nothing
-
-
-
This is for 1 item however. If you want 2 or more items to drop, you would need more if-then-else blocks. If you want the items to drop at an individual chance, the if-then-else blocks will be independent, or stand-alone outside of any other blocks. However, if you want only 1 item to drop per creep, you will need a chain of if-then-else blocks. The first "if" will be for the lowest percentage, and then the next block would occur in the "else" section of the first. That "if" would have the next percentage, and so on for all the items in its drop table.
-
Kobold Item Drop
-
Events
-
Unit - A unit owned by Player 12 (Brown) Dies
-
-
Conditions
-
(Unit-type of (Triggering unit)) Equal to Kobold
-
-
Actions
-
Set KoboldItemDrop = (Random integer number between 1 and 100)
-
Set ItemDropLoc = Position of (Triggering Unit)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
KoboldItemDrop Less than or equal to 50
-
-
Then - Actions
-
Item - Create Scroll of Healing at ItemDropLoc
-
-
Else - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
KoboldItemDrop Less than or equal to 60
-
-
Then - Actions
-
Item - Create <any item you choose> at ItemDropLoc
-
-
Else - Actions
-
-
-
-
Custom script: call RemoveLocation(udg_ItemDropLoc)
-
-
Kobold Item Drop
-
Events
-
Unit - A unit owned by Player 12 (Brown) Dies
-
-
Conditions
-
(Unit-type of (Triggering unit)) Equal to Kobold
-
-
Actions
-
Set KoboldItemDrop = (Random integer number between 1 and 100)
-
Set ItemDropLoc = Position of (Triggering Unit)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
KoboldItemDrop Less than or equal to 50
-
-
Then - Actions
-
Item - Create Scroll of Healing at ItemDropLoc
-
-
Else - Actions
-
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
KoboldItemDrop Less than or equal to 60
-
-
Then - Actions
-
Item - Create <any item you choose> at ItemDropLoc
-
-
Else - Actions
-
-
Custom script: call RemoveLocation(udg_ItemDropLoc)
-
Now that you understand normal item drops, how about we try a bit more advanced triggers?
For example, we can do special things such as make items drop depending on the level of the hero killing the unit.
In the following example, we have a unit called Chest and it revives every 13 seconds. If the level of the hero killing it is 10 and below, then it has a 35% chance to drop a healing potion and a 50% chance to drop a mana potion. However, if the level of the hero is 11 or greater, then there is a 35% chance to drop a greater healing potion and a 50% chance to drop a greater mana potion.
Start off with the standard item drop:
The trigger will end up looking like this:
1. Greater Healing Potion : 35%
2. Greater Mana Potion : 50%
Now that is how we do the item drop according to hero level, which you can apply to any of the creeps you want. If you have some sort of class system, you can add more if-then-else blocks and, for example, drop a wand for a mage hero or drop a sword for a warrior hero.
Overall, triggered item drops are much better than the normal item tables. They add for ample control on the situation, and can allow for a lot more creativity.
If you find any of this confusing, just PM me and I'll try to help you out. Enjoy the tutorial and good luck with your item drops.
For example, we can do special things such as make items drop depending on the level of the hero killing the unit.
In the following example, we have a unit called Chest and it revives every 13 seconds. If the level of the hero killing it is 10 and below, then it has a 35% chance to drop a healing potion and a 50% chance to drop a mana potion. However, if the level of the hero is 11 or greater, then there is a 35% chance to drop a greater healing potion and a 50% chance to drop a greater mana potion.
Start off with the standard item drop:
-
ItemDrop
-
Events
-
A unit owned by Player 12 (Brown) Dies
-
-
Conditions
-
(Unit-type of (Triggering unit)) Equal to Chest
-
-
Actions
-
ItemDrop
-
Events
-
A unit owned by Player 12 (Brown) Dies
-
-
Conditions
-
And - All (Conditions) are true
-
Conditions
-
(Unit-type of (Triggering unit)) Equal to Chest
-
(Triggering unit is (A hero)) Equal to True
-
-
-
-
Actions
-
ItemDrop
-
Events
-
A unit owned by Player 12 (Brown) Dies
-
-
Conditions
-
(Unit-type of (Triggering unit)) Equal to Chest
-
(Triggering unit is (A hero)) Equal to True
-
-
Actions
-
Set ChestItemDrop = Random Integer between 1 and 100
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
Then - Actions
-
Else - Actions
-
-
-
ItemDrop
-
Events
-
A unit owned by Player 12 (Brown) Dies
-
-
Conditions
-
(Unit-type of (Triggering unit)) Equal to Chest
-
(Triggering unit is (A hero)) Equal to True
-
-
Actions
-
Set ChestItemDrop = Random Integer between 1 and 100
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Hero level of (Triggering unit)) Less than or equal to 10
-
-
Then - Actions
-
Else - Actions
-
-
-
ItemDrop
-
Events
-
A unit owned by Player 12 (Brown) Dies
-
-
Conditions
-
(Unit-type of (Triggering unit)) Equal to Chest
-
(Triggering unit is (A hero)) Equal to True
-
-
Actions
-
Set ChestItemDrop = Random Integer between 1 and 100
-
Set ChestTempLoc = Position of (Triggering Unit)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Hero level of (Triggering unit)) Less than or equal to 10
-
-
Then - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
ChestItemDrop less than or equal to 35
-
-
Then - Actions
-
Item - Create 1 healing potion at ChestTempLoc
-
-
Else - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
ChestItemdrop less than or equal to 85
-
-
Then - Actions
-
Item - Create 1 Mana potion at ChestTempLoc
-
-
Else - Actions
-
-
-
-
-
Else - Actions
-
-
Custom script: call RemoveLocation(udg_ChestTempLoc)
-
The trigger will end up looking like this:
-
ItemDrop
-
Events
-
A unit owned by Player 12 (Brown) Dies
-
-
Conditions
-
(Unit-type of (Triggering unit)) Equal to Chest
-
(Triggering unit is (A hero)) Equal to True
-
-
Actions
-
Set ChestItemDrop = Random Integer between 1 and 100
-
Set ChestTempLoc = Position of (Triggering Unit)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Hero level of (Triggering unit)) Less than or equal to 10
-
-
Then - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
ChestItemDrop Less than or equal to 35
-
-
Then - Actions
-
Item - Create 1 Healing Potion at ChestTempLoc
-
-
Else - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
ChestItemDrop less than or equal to 85
-
-
Then - Actions
-
Item - Create 1 Mana Potion at ChestTempLoc
-
-
Else - Actions
-
-
-
-
-
Else - Actions
-
-------- The hero's level is 11 or greater --------
-
If - Conditions
-
ChestItemDrop Less than or equal to 35
-
-
Then - Actions
-
Item - Create 1 Greater Healing Potion at ChestTempLoc
-
-
Else - Actions
-
If - Conditions
-
ChestItemDrop Less than or equal to 85
-
-
Then - Actions
-
Item - Create 1 Greater Mana Potion at ChestTempLoc
-
-
Else - Actions
-
-
-
-
Custom script: call RemoveLocation(udg_ChestTempLoc)
-
1. Greater Healing Potion : 35%
2. Greater Mana Potion : 50%
Now that is how we do the item drop according to hero level, which you can apply to any of the creeps you want. If you have some sort of class system, you can add more if-then-else blocks and, for example, drop a wand for a mage hero or drop a sword for a warrior hero.
Overall, triggered item drops are much better than the normal item tables. They add for ample control on the situation, and can allow for a lot more creativity.
If you find any of this confusing, just PM me and I'll try to help you out. Enjoy the tutorial and good luck with your item drops.
Attachments
-
Trigger editor.PNG10.8 KB · Views: 6,140
-
Variable Editor.PNG11.6 KB · Views: 6,061
-
set variable.PNG4.6 KB · Views: 6,138
-
Condition action.PNG4.5 KB · Views: 6,161
-
Kitem.PNG5.5 KB · Views: 6,028
-
Math.PNG7.3 KB · Views: 514
-
Ifthenelse.PNG11.9 KB · Views: 6,158
-
0 and 50.PNG6.5 KB · Views: 515
-
scroll of healing.PNG15.9 KB · Views: 685
-
Full trig.PNG14.9 KB · Views: 586
-
Second random higher.PNG22.1 KB · Views: 630
-
Capture.PNG26.7 KB · Views: 598
-
Capture1.PNG24.1 KB · Views: 6,365
Last edited by a moderator: