1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  4. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Triggered Item Drops

Discussion in 'Trigger (GUI) Editor Tutorials' started by Zinox, Jan 8, 2011.

  1. Zinox

    Zinox

    Joined:
    Sep 24, 2010
    Messages:
    15
    Resources:
    1
    Tutorials:
    1
    Resources:
    1

    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:


    Chapter 1: Why use triggered item drops?


    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!

    Chapter 2: How do they work?


    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. ​

    Chapter 3:What do we need?

    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).
    [​IMG]

    Then open the variable editor from the trigger editor window (ctrl+B).
    [​IMG]

    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.
    [​IMG]

    The purpose of this integer variable is to store the random number we retrieve. Simple, right?​

    Chapter 4: How do I make one?


    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.
    [​IMG]

    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.
    [​IMG]

    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.
    [​IMG]

    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.
    [​IMG]

    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 means that we set the integer to a random number, and if that number is less than or equal to 50 (between 1 and 50) it will drop the item.
    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)

    Under the final else - actions, you can add more blocks for more items. The thing to notice though is the second condition. If the first condition isn't met, then the remaining numbers that the random can be in is 50 to 100. Thus, the chance for the second item to drop is 10%. This is for single item drops though. For independent drops, this is how it would look like:
    • 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)


    For the single item drop, the order matters. You want the items with the lowest chance of dropping to drop, but if not that, then drop one of the less rare items. For independent drops, the order doesn't matter. Using this method, however, you can also do single drops. You can simply check if the conditions are met, set a boolean to true, and then just drop a random one out of the items that have the boolean equal to true.​

    Chapter 5:Advanced Options/Triggers


    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:
    • ItemDrop
    • Events
      • A unit owned by Player 12 (Brown) Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Chest
    • Actions


    Next, we must make sure that the unit killing the chest is a hero, and you can do that with a boolean comparison.
    • 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


    Now that that's done, we put again like in normal triggered item drops the "Set Variable: <Variable name>" to a random number between 1 and 100, and then put the if-then-else block again.
    • 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


    But this time, under the "if- conditions" we put another Integer Comparison, comparing the level of the hero. Click on integer comparison and change the first field like we used to do in Chapter 4, but this time choose Hero - Hero level comparison. Next, change the "Equal to" to "Less than or equal to" in order to represent the "level 10 or lower condition" now, our trigger should look 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
      • 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


    Now, under the "Then - Actions" put another if-then-else block, and now we do EXACTLY the same as we did in Chapter 4, we do the integer comparison of the Set Variable, put the condition that it is less than or equal to 35, and under the 'Then - Actions' Drop small potion of healing, and under the else.....well.....I probably think you now know how to do the rest of items dropped as explained in chapter 4, just put the other item dropped a mana potion at 50% chance.
    • 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)


    After you have finished the above, notice the "Else - Actions" at the very bottom of the trigger. That was the else action of the first if-then-else block of the trigger. That is where we will put the triggers for if they are 11+. Since the first condition stated that the hero level must be less than or equal to 10, the only other levels available are 11+, so no need for any new conditions.

    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)


    Now the drop chances for 11+ are:
    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.
     

    Attached Files:

    Last edited by a moderator: Jan 21, 2011
  2. -Kobas-

    -Kobas-

    Joined:
    Jan 17, 2010
    Messages:
    5,894
    Resources:
    28
    Icons:
    1
    Tools:
    2
    Maps:
    10
    Spells:
    4
    Template:
    5
    Tutorials:
    6
    Resources:
    28
    You can right click on trigger and select copy as text or whatever and paste it here between
    [trigger][/trigger]
    tags.

    You need to edit tutorial form and fix images!

    Also this tutorial can't be approved unit you don't fix your triggers, or should I say memory leaks!

    Other that that tutorial is really simple and it was already explained if I remember right!
    Only difference is that you explained it very nice!

    Please add more options, explain more events and so on:
    Example:
    Item drop different for different unit levels
    Item drop different for different unit types
    ....

    Oh your final trigger don't need that "not equal" even because it is already checked in your first if then else function!
     
  3. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,181
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    There are 101 numbers in [0,100]. You should use [1,100].

    You can use Rnd(1,1000) if you want to get smaller than 1% chance to drop some very rare boss items.

    I'd use chances like this.
    Trig
    • Untitled Trigger 029
      • Events
      • Conditions
      • Actions
        • Set Int = (Random integer number between 1 and 100)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Int Less than or equal to 50
          • Then - Actions
            • -------- Drop item 1 --------
          • Else - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Int Less than or equal to 80
              • Then - Actions
                • -------- Drop item 2 --------
              • Else - Actions
                • -------- Drop nothing --------

    50% chance to drop item 1, 30% chance to drop item 2, 20% chance to drop nothing.

    Or multiple item drops:
    Trig

    • Untitled Trigger 029
      • Events
      • Conditions
      • Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Random integer number between 1 and 100) Less than or equal to 40
          • Then - Actions
            • -------- Drop item 1 --------
          • Else - Actions
            • -------- Drop nothing --------
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Random integer number between 1 and 100) Less than or equal to 30
          • Then - Actions
            • -------- Drop item 2 --------
          • Else - Actions
            • -------- Drop nothing --------


    40% chance to drop item 1 AND 30% chance to drop item 2.

    P(drop something) = 1-P(no drop #1)*P(no drop #2) = 1-.6*.7 = 0,58 -> 58% chance to drop something.
    P(no drop) = 1-P(drop something) = 1-0,58 = 0,42 -> 42%
    P(drop two items) = P(drop #1)*P(drop #2) = 0,4*0,3 = 0,12 -> 12% chance to drop two items.
     
  4. Zinox

    Zinox

    Joined:
    Sep 24, 2010
    Messages:
    15
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Ok, i'll fix image mistakes, add a few more triggers to make a few more advanced item drops. Change how the tutorial looks a bit. thanks for the replies, I'll work on it soon
     
  5. Zinox

    Zinox

    Joined:
    Sep 24, 2010
    Messages:
    15
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Ok, edited the tutorial:
    Added an extra chapter on more advanced item dropping
    Fixed images with
    • trigger
    tags
    if you found another error/mistake in anything please say so ill fix them right away.
     
  6. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Some of the functions are a little messed up (the indenting) in the trigger tags. (mostly the if/then/elses) You might want to fix that. :)

    Otherwise, this tutorial is looking good. Fix that, and then I'll fix grammar mistakes/organization and it will be ready for approval.
     
  7. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Fixed the grammar and organization, and revamped some things. I fixed the triggers up a bit, optimized here and there, and removed some simple point leaks.

    Good job. ~Approved.
     
  8. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,181
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    Actually the are
    1. Greater Healing Potion : 35%
    2. Greater Mana Potion : 15%

    The mana potion can only drop if the random number is between 35 and 50. (35 is excluded)
     
  9. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Whoops, I overlooked that. Fixed.
     
  10. Augustus_Magnus

    Augustus_Magnus

    Joined:
    Jun 2, 2016
    Messages:
    114
    Resources:
    3
    Maps:
    3
    Resources:
    3
    I'm quite stuck, how dd you create that "Set ItemDropLoc" or something?
    [​IMG]
     
  11. Augustus_Magnus

    Augustus_Magnus

    Joined:
    Jun 2, 2016
    Messages:
    114
    Resources:
    3
    Maps:
    3
    Resources:
    3
     

    Attached Files:

    • 0020.PNG
      0020.PNG
      File size:
      20.1 KB
      Views:
      282
  12. sashablanche

    sashablanche

    Joined:
    May 19, 2017
    Messages:
    3
    Resources:
    0
    Resources:
    0
    yeah me too sadly no reply yet
     
  13. Hotwer

    Hotwer

    Joined:
    Mar 10, 2013
    Messages:
    370
    Resources:
    0
    Resources:
    0
    Set ItemDropLoc is a statement of Set from variable of type Region (Rect). Just use Set on this variable and then select Position of (Triggering Unit)
     
    Last edited: May 27, 2017
  14. Augustus_Magnus

    Augustus_Magnus

    Joined:
    Jun 2, 2016
    Messages:
    114
    Resources:
    3
    Maps:
    3
    Resources:
    3
    Okay. Thank you.
     
  15. Null

    Null

    Joined:
    Dec 3, 2018
    Messages:
    263
    Resources:
    35
    Icons:
    35
    Resources:
    35
    This tutorial is very helpful. Thank you !
     
  16. tdrsmynm

    tdrsmynm

    Joined:
    Jul 10, 2016
    Messages:
    120
    Resources:
    0
    Resources:
    0
    Does this have a sample map???
    I'm not really good with triggers, and I want to reverse engineer it. Thank you!
     
  17. Warseeker

    Warseeker

    Joined:
    Feb 18, 2014
    Messages:
    2,782
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Check out one of the Founding of Durotar maps, they use pretty much the same system as the one in this tutorial.
     
  18. Rotgut

    Rotgut

    Joined:
    Dec 29, 2019
    Messages:
    8
    Resources:
    0
    Resources:
    0
    Is it new now in reforged that you can simply:
    Item - Create (some item) at (Position of (Triggering unit))

    Without this set area and then remove area?
     
  19. Nosiaz

    Nosiaz

    Joined:
    Feb 28, 2020
    Messages:
    31
    Resources:
    0
    Resources:
    0
    I have do this, that was working but now the unit doesnt re-spawn, i have use 1 variable for each mob for doesnt have conflict if i use aldready the same, where my trigger is wrong plz ??
     

    Attached Files:

    • mob.PNG
      mob.PNG
      File size:
      47.3 KB
      Views:
      7
  20. Warseeker

    Warseeker

    Joined:
    Feb 18, 2014
    Messages:
    2,782
    Resources:
    1
    Maps:
    1
    Resources:
    1
    It doesn't respawn because you are not storing it's position after it dies you are simply using (Position of Triggering Unit) now if it was a specific unit ir will work fine but since it's a generic event it won't unless you store each unit's position in a variable so you can revive it later.