1. Music Contest #10 - Results are finally published! Drop by to check some retro songs and congratulate the winners!
    Dismiss Notice
  2. Join Terraining Contest #19 and witness the aftermath!
    Dismiss Notice
  3. The 3rd Melee Mapping Contest is ON! Join in on a ride of a 4v4 melee experience!
    Dismiss Notice
  4. The 30th edition of the Modeling Contest is finally up! The Portable Buildings need your attention, so come along and have a blast!
    Dismiss Notice

[Solved] Please help me fix my GUI item stacking trigger

Discussion in 'Triggers & Scripts' started by hexhound, Nov 19, 2018.

  1. hexhound

    hexhound

    Joined:
    Jul 12, 2018
    Messages:
    155
    Resources:
    0
    Resources:
    0
    Hi, I'm trying to make a map where heroes can purchase the same item many times and thereby upgrade those items. So i made a trigger that checks if you're already holding a version of that item, and then replaces the version you're holding.

    It's working, but sometimes it fails to recognize that you're already holding an item that's supposed to be upgraded, so you end up with both one level X item and one level 1 item in your backpack.

    I have four very basic and simple triggers:

    1) For what happens when you buy the Level 1 item, in this case it's a shield:

    • Heroshield 1to2
      • Events
        • Unit - A unit Acquires an item
      • Conditions
        • (Item-type of (Item being manipulated)) Equal to Hero Shield
      • Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Hero manipulating item) has an item of type Hero Shield) Equal to True
            • (Item being manipulated) Not equal to (Item carried by (Hero manipulating item) of type (Item-type of (Item being manipulated)))
          • Then - Actions
            • Item - Remove (Item being manipulated)
            • Hero - Drop (Item carried by (Hero manipulating item) of type Hero Shield) from (Hero manipulating item)
            • Item - Remove (Last dropped item)
            • Hero - Create Hero Shield 2 and give it to (Hero manipulating item)
          • Else - Actions


    2) for what happens when you're already holding one:
    (this trigger is repeated for as many levels as the items has)
    • Heroshield 2to3
      • Events
        • Unit - A unit Acquires an item
      • Conditions
        • (Item-type of (Item being manipulated)) Equal to Hero Shield
      • Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Hero manipulating item) has an item of type Hero Shield 2) Equal to True
          • Then - Actions
            • Item - Remove (Item being manipulated)
            • Hero - Drop (Item carried by (Hero manipulating item) of type Hero Shield 2) from (Hero manipulating item)
            • Item - Remove (Last dropped item)
            • Hero - Create Hero Shield 3 and give it to (Hero manipulating item)
          • Else - Actions




    3) for when you run into the max level:
    • Heroshield 9isMax
      • Events
        • Unit - A unit Acquires an item
      • Conditions
        • (Item-type of (Item being manipulated)) Equal to Hero Shield
      • Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Hero manipulating item) has an item of type Hero Shield 9) Equal to True
          • Then - Actions
            • Game - Display to (All allies of (Owner of (Triggering unit))) the text: Nine is the highest...
            • Item - Remove (Item being manipulated)
          • Else - Actions


    and 4) for reimbursing if you try to upgrade past the max level:
    • Heroshield Reimburse
      • Events
        • Unit - A unit Sells an item (from shop)
      • Conditions
        • (Item-type of (Sold Item)) Equal to Hero Shield
      • Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Buying unit) has an item of type Hero Shield 9) Equal to True
          • Then - Actions
            • Player - Add 450 to (Owner of (Buying unit)) Current gold
          • Else - Actions


    Any idea why it fails? Is there a better/simpler way i can do this?

    Thanks in advance, you sexy wizards.
     
    Last edited: Nov 21, 2018
  2. CodeBlack

    CodeBlack

    Joined:
    Sep 19, 2012
    Messages:
    180
    Resources:
    1
    Maps:
    1
    Resources:
    1
    May i make a suggestion?

    i dont know exactly what you are trying to achieve, but wouldnt it be easier to:
    • make the item a stackable (like potions)
    • add/remove hidden passives for the stats they give via trigger
    • set their level depending on the number of stacks
    greetings

    CodeBlack
     
  3. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    881
    Resources:
    9
    Tools:
    1
    Maps:
    2
    Spells:
    5
    Tutorials:
    1
    Resources:
    9
    • Why you drop item before removing them?
    • (Item being manipulated) Not equal to (Item carried by (Hero manipulating item) of type (Item-type of (Item being manipulated)))
      • Dat can fail quite often. Depending on the slot the new item takes.
      • A more safer solution is to loop the whole inventory and count the amount of items of the wanted Type, if they are 2, fuse them. Sadly there is no premade action for that.
     
  4. hexhound

    hexhound

    Joined:
    Jul 12, 2018
    Messages:
    155
    Resources:
    0
    Resources:
    0
    I thought it was necessary, thank you for pointing that out.

    Thanks for the info.

    Is this condition more reliable?
            • [​IMG]((Buying unit) has an item of type Hero Shield 9) Equal to True


    I don't fully understand loops yet, although I have a few functioning triggers using loops that i copied and adapted from tutorials on this site. Do you have any suggestion for a tutorial i could check out or how i would begin writing a trigger to do this? Assuming it's doable in GUI.
     
    Last edited: Nov 20, 2018
  5. hexhound

    hexhound

    Joined:
    Jul 12, 2018
    Messages:
    155
    Resources:
    0
    Resources:
    0
    Thanks for mentioning those options.
    Stackable like potions isn't what i'm looking for, these are permanent items like swords and shields with passive bonuses.
    Hidden passives could be an option but then the item doesn't change name when it's upgraded. I want it to be clear to players what each item does.
    I don't think i know enough about item levels to evaluate that suggestion fully, but i believe it's not applicable here. I'm looking to replace the item with a new item that can have different properties if i want it to, or just the same properties but stronger.
     
  6. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    1,726
    Resources:
    0
    Resources:
    0
    No. It returns true when the unit has 1 of the item being bought... and also true when it has 2 of the item and it should stack. This condition gives you no useful information.
     
  7. CodeBlack

    CodeBlack

    Joined:
    Sep 19, 2012
    Messages:
    180
    Resources:
    1
    Maps:
    1
    Resources:
    1
    I guess a complete crafting system that lets you combine two items into one would be the easiest option (unless you want to build it yourself to learn how it is done). I am currently using This.
     
  8. hexhound

    hexhound

    Joined:
    Jul 12, 2018
    Messages:
    155
    Resources:
    0
    Resources:
    0
    Thanks for the link. If it comes to that i'll try it out, but it seems like a big project to take on over a small problem. i'm totally unfamiliar with JASS and the system i have works 95%+ of the time, so i'll be looking for easier solutions first. The worst thing that happens when my system fails is that you have to drop the item on the ground and pick it up again.
     
  9. hexhound

    hexhound

    Joined:
    Jul 12, 2018
    Messages:
    155
    Resources:
    0
    Resources:
    0
    In case anyone comes across this later, this is the trigger i ended up with:

    • Herowpn 1to2
      • Events
        • Unit - A unit Acquires an item
      • Conditions
        • (Item-type of (Item being manipulated)) Equal to Hero Weapon
      • Actions
        • For each (Integer A) from 1 to 6, do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Item-type of (Item carried by (Triggering unit) in slot (Integer A))) Equal to Hero Weapon
                • (Item carried by (Triggering unit) in slot (Integer A)) Not equal to (Item being manipulated)
              • Then - Actions
                • Item - Remove (Item being manipulated)
                • Item - Remove (Item carried by (Triggering unit) in slot (Integer A))
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • ((Hero manipulating item) has an item of type Hero Weapon) Equal to True
                    • (Item being manipulated) Not equal to (Item carried by (Hero manipulating item) of type (Item-type of (Item being manipulated)))
                  • Then - Actions
                    • Item - Remove (Item being manipulated)
                    • Item - Remove (Item carried by (Triggering unit) of type Hero Weapon)
                  • Else - Actions
                • Hero - Create Hero Weapon 2 and give it to (Hero manipulating item)
              • Else - Actions


    Seems to work so far.

    Thanks again Tasyen for the tip about loops.