• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

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

Status
Not open for further replies.
Level 14
Joined
Jul 12, 2018
Messages
550
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:
Level 7
Joined
Sep 19, 2012
Messages
204
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
 
  • 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.
 
Level 14
Joined
Jul 12, 2018
Messages
550
  • Why you drop item before removing them?
I thought it was necessary, thank you for pointing that out.

Tasyen said:
(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.
Thanks for the info.

Is this condition more reliable?
          • if.gif
            ((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:
Level 14
Joined
Jul 12, 2018
Messages
550
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
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.
 
Level 7
Joined
Sep 19, 2012
Messages
204
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.

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.
 
Level 14
Joined
Jul 12, 2018
Messages
550
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.
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.
 
Level 14
Joined
Jul 12, 2018
Messages
550
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.
 
Status
Not open for further replies.
Top