Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Stacking Items

Discussion in 'Trigger (GUI) Editor Tutorials' started by DigitalDemon, Dec 21, 2007.

  1. DigitalDemon

    DigitalDemon

    Joined:
    Jun 1, 2007
    Messages:
    98
    Resources:
    3
    Maps:
    2
    Tutorials:
    1
    Resources:
    3
    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:
     

    Attached Files:

    Last edited: Dec 21, 2007
  2. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
  3. DigitalDemon

    DigitalDemon

    Joined:
    Jun 1, 2007
    Messages:
    98
    Resources:
    3
    Maps:
    2
    Tutorials:
    1
    Resources:
    3
    Mine is simpler to understand IMO. ( No offense )
     
  4. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    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...)
     
  5. madcat2

    madcat2

    Joined:
    Aug 25, 2005
    Messages:
    1,138
    Resources:
    0
    Resources:
    0
    No, hurt to have two. Theres different people in this world and some may find the other easier to understand and some might find this one easier to understand. Basically if the other one is to hard to understand they can come over here and try this one and see if it helps, and if both are just not geting to them they go ask in the trigger or jass pages but at least they may have a idea how the system may work from reading the one thats easier for them, so the jass and trigger people only have to help in the parts needed. So basically you can just attach this one to the other and mark it as "If you had trouble with the other one try this one." Because giving them a second option never hurts.
     
  6. ShaDowPoWeR

    ShaDowPoWeR

    Joined:
    Nov 18, 2007
    Messages:
    48
    Resources:
    0
    Resources:
    0
  7. Basinator

    Basinator

    Joined:
    Jul 25, 2007
    Messages:
    73
    Resources:
    0
    Resources:
    0
    Mega necro, but got a few qs

    Where do I can find this?

    Also, I don't really understand what is happening here, can someone explain?

    Thanks!
     
  8. muzzel

    muzzel

    Joined:
    Jun 27, 2008
    Messages:
    1,303
    Resources:
    2
    JASS:
    1
    Wurst:
    1
    Resources:
    2
    Considering the last post in this threat was 6 years ago im not sure if he will answer.
     
  9. Basinator

    Basinator

    Joined:
    Jul 25, 2007
    Messages:
    73
    Resources:
    0
    Resources:
    0
    Who said it has to be him who answers?
     
  10. vypur85

    vypur85

    Joined:
    Jan 27, 2014
    Messages:
    158
    Resources:
    1
    Maps:
    1
    Resources:
    1
    > Where do I can find this?
    It's a Boolean comparison in the condition list.

    > Also, I don't really understand what is happening here...
    The first condition is to check if the unit already has that item or not. If already has then proceed to stacking.
    The second condition is to ensure the item is not the item the hero just acquired.

    Here's a scenario:
    You pick up a Gun item.
    If your unit already has Gun item, then proceed to stack.
    The Gun that your unit already has, is not the Gun that your unit just picked up from the ground.

    That's all.
     
  11. Basinator

    Basinator

    Joined:
    Jul 25, 2007
    Messages:
    73
    Resources:
    0
    Resources:
    0
    Thanks for the explanation, I although I am still derping around inside myself with "itemBeingManipulated" and "HeroManipulatingItem"
     
  12. ngkn92

    ngkn92

    Joined:
    Oct 28, 2012
    Messages:
    82
    Resources:
    0
    Resources:
    0
    about unstack

    Why do u have to /2 and lose 1 stack?
    Do like this,
    set int_1 = charge/2
    (the number hero keep)​
    set int_2 = charge-int_1
    (hero drop this)​
    Done.

    btw, I keep got the issue that sometimes it stack, sometimes it doesn't.

    *edited:
    the problem solved anyway, just me trying to be stupid.
     
    Last edited: May 29, 2014
  13. emperor_d3st

    emperor_d3st

    Joined:
    Apr 13, 2008
    Messages:
    1,427
    Resources:
    0
    Resources:
    0
    This doesn't take into account the scenario when your inventory is full.
     
  14. 6oranges

    6oranges

    Joined:
    Jun 16, 2017
    Messages:
    1
    Resources:
    0
    Resources:
    0
    This file attached has a revised version of the trigger above. By placing items in a certain region those items are the only ones that will stack. Also I replaced "Unit - A unit Acquires an item" with has been issued an order.

    Advantages:
    • Allows you to stack Items when inventory full without extra rune item.
    • Allows you to choose which items are stack able.
    • Only takes two triggers for all stack able items you choose.

    Disadvantages:
    • When you hold shift to do multiple things in a row after picking up a stack able item all further commands are not guaranteed to activate. This is because picking up items too far away (more than 200) causes your hero to move to the item and then attempt to pick it up again. This move resets your shift queue.

    A workaround is: when holding shift to pick up one of the stack able items then some other order first tell your hero to move next to the item and then pick it up.
     

    Attached Files:

  15. mYster4teN

    mYster4teN

    Joined:
    Sep 14, 2017
    Messages:
    3
    Resources:
    0
    Resources:
    0
    hey 6oranges! you saved my ideas on my new survival map! i was looking for such a simple way like this!:):)
     
  16. mYster4teN

    mYster4teN

    Joined:
    Sep 14, 2017
    Messages:
    3
    Resources:
    0
    Resources:
    0
    I've made a way you can "unstack" your items ins 6oranges Triggers:

    When the dummy ability called "unstack" is casted By your hero, one charge of an item located in hero's slot 1 will appear in your inventory, or in the ground if the inventory is full, and you can stack the items back by simply draging the item over another of the same type in the hero's inventory.



    (The [Item - Set custom value of (Last created item) to 9] and them to 0 after the [Hero - Give (Last created item) to (Casting unit)] Actions are just to avoid the unstacked charge to come back to the original stack.
    And i needed to add another condition at "Stacking" trigger, to complete the action).
     

    Attached Files:

  17. Thualluandra

    Thualluandra

    Joined:
    Jun 19, 2017
    Messages:
    8
    Resources:
    0
    Resources:
    0
    I've tested that bro and I realize you forgot something.
    This can prevent any bugs with items that doesn't have any charge or 0 charges, like permanent items.
    I found that out because I got 2 Claws of Attack and it stacked to one. And I didn't want that.
    Just add this conditions to the list and it'll all work fine.

    • (Charges remaining in (Item carried by (Hero manipulating item) of type (Item-type of (Item being manipulated)))) Greater than 0
     
  18. BalanceDruid7

    BalanceDruid7

    Joined:
    Sep 25, 2015
    Messages:
    34
    Resources:
    0
    Resources:
    0
    Doesnt work.
    Bugs out when you have a free inventory slot before the item you pick up