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

Problem with item stacks when an items is bought.

Status
Not open for further replies.
Level 14
Joined
Aug 8, 2010
Messages
1,022
Hello... again. I have an item problem once more... I have set the max stacks of my item to 10 in the object editor field "Stats - Number of charges". But when i buy only ONE of this item, i get 10 charges, instead of 1. How should i fix this? Or perhaps i don't need to set the charges but to make the items stack, somehow...
 
Level 14
Joined
Aug 8, 2010
Messages
1,022
Yes, i did this. But what if i have 2 stacks of that item in one of the hero slots, and 3 stacks of that item in another of the hero slots? What will happen when i buy the item - both slots increase their stacks with 1, instead of only one of the slots (stacks in first slot are 3, stacks in second slot are 4). This is the problem i'm currently solving.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
  • ItemStacking
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Trigger - Turn off (This trigger)
      • Hero - Drop (Item being manipulated) from (Triggering unit)
      • 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 being manipulated)) Equal to (Item-type of (Item carried by (Triggering unit) in slot (Integer A)))
            • Then - Actions
              • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer A)) to ((Charges remaining in (Item carried by (Triggering unit) in slot (Integer A))) + (Charges remaining in (Item being manipulated)))
              • Item - Remove (Item being manipulated)
            • Else - Actions
      • Hero - Give (Item being manipulated) to (Triggering unit)
      • Trigger - Turn on (This trigger)
This trigger will do the job.

In your problem case; this trigger will increment the first item of the type found in inventory, and since the item is then removed, it cannot increment the second item, since the Charges Remaining of a nonexistent item is 0.

Also, how would you be able to have 2 of the same item, with different charges remaining? You'd need a more advanced item stacking trigger to split them if you wanted to include maximum stack sizes.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
I don't understand how you turn off the trigger, put actions, turn it on AFTERWISE and GET A RESULT?! o_O However, your trigger helped me in some way. It gave me an idea of how to fix this. I'll try it now.

Because this:

  • Hero - Give (Item being manipulated) to (Triggering unit)
Would cause the trigger to run again, causing an infinite loop, causing the game to crash.
 
Level 14
Joined
Aug 8, 2010
Messages
1,022
I am still wondering how it does something at all when it is immediately turned off after it's triggered. :/

EDIT : I came up with this :
  • Add stacks when pick up
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set ItemType = (Item-type of (Item being manipulated))
      • Set ItemMaxCharge = 0
      • Trigger - Run Set item max charges <gen> (ignoring conditions)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ItemMaxCharge Equal to 0
        • Then - Actions
          • Skip remaining actions
        • Else - Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set ItemCharges = (Charges remaining in (Item carried by (Triggering unit) in slot (Integer A)))
          • Set ItemAcquireCharges = (Charges remaining in (Item being manipulated))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ItemCharges Less than ItemMaxCharge
            • Then - Actions
              • Set ItemDifferenceInCharges = (ItemMaxCharge - ItemCharges)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ItemAcquireCharges Greater than or equal to ItemDifferenceInCharges
                • Then - Actions
                  • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer A)) to ItemMaxCharge
                  • Set ItemAcquireCharges = (ItemAcquireCharges - ItemDifferenceInCharges)
                  • Hero - Create ItemType and give it to (Triggering unit)
                  • Item - Set charges remaining in (Last created item) to ItemAcquireCharges
                • Else - Actions
                  • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer A)) to (ItemCharges + ItemAcquireCharges)
            • Else - Actions
  • Set item max charges
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ItemType Equal to Sunfish
        • Then - Actions
          • Set ItemMaxCharge = 10
        • Else - Actions
But the things mess up. I think i also come up to this infinite loop. However, i can't prevent it by turning the trigger off in the beginning and turn it back on at the end... Can you point my mistake?

What happens : i have item with 4 charges, drop it, get it back, the charges are 8, drop it again, take it again and the whole inventory is full with items of the same type, with max charges.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
You have to turn off/turn on the trigger before and after the action where you Create ItemType and give it to (Triggering unit), since that action will cause the trigger to run again, causing an infinite loop.

Just to clarify: turning a trigger off does NOT affect the trigger's remaining actions, it simply disables the events for the trigger.

With your "doubling" problem, I think you're making your trigger needlessly complicated. Try recreate my trigger verbatim, and see if that works. Then add your max charges functions from there.
 
Level 14
Joined
Aug 8, 2010
Messages
1,022
Hm... i have this now :
  • Add stacks when pick up
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set ItemType = (Item-type of (Item being manipulated))
      • Set ItemMaxCharge = 0
      • Trigger - Run Set item max charges <gen> (ignoring conditions)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ItemMaxCharge Equal to 0
        • Then - Actions
          • Skip remaining actions
        • Else - Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set ItemCharges = (Charges remaining in (Item carried by (Triggering unit) in slot (Integer A)))
          • Set ItemAcquireCharges = (Charges remaining in (Item being manipulated))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • ItemCharges Less than ItemMaxCharge
            • Then - Actions
              • Set ItemDifferenceInCharges = (ItemMaxCharge - ItemCharges)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ItemAcquireCharges Greater than or equal to ItemDifferenceInCharges
                • Then - Actions
                  • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer A)) to ItemMaxCharge
                  • Set ItemAcquireCharges = (ItemAcquireCharges - ItemDifferenceInCharges)
                  • Trigger - Turn off (This trigger)
                  • Hero - Create Sunfish and give it to (Triggering unit)
                  • Trigger - Turn on (This trigger)
                  • Item - Set charges remaining in (Last created item) to ItemAcquireCharges
                • Else - Actions
                  • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer A)) to (ItemCharges + ItemAcquireCharges)
              • Item - Remove (Item being manipulated)
            • Else - Actions
  • Set item max charges
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ItemType Equal to Sunfish
        • Then - Actions
          • Set ItemMaxCharge = 10
        • Else - Actions
It does exactly what i want but there is a problem once more... If i drop an item and get it back, a bug happens. I dropped a 6 stack item, got it back, but only with two stacks. It's because the ItemCharge and ItemAcquired variables are the same (6) and so, when the trigger does (6+6)-10, i get an item with two stacks. And i don't know how to fix it... :goblin_jawdrop:

EDIT : the problem wasn't this. I've fixed it tough. Everything works PERFECTLY! Here are the final triggers :
  • Add stacks when pick up
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set ItemType = (Item-type of (Item being manipulated))
      • Set ItemMaxCharge = 0
      • Trigger - Run Set item max charges <gen> (ignoring conditions)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ItemMaxCharge Equal to 0
        • Then - Actions
          • Skip remaining actions
        • Else - Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Hero - Drop (Item being manipulated) from (Triggering unit)
          • Trigger - Turn off (This trigger)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Item-type of (Item carried by (Triggering unit) in slot (Integer A))) Equal to ItemType
                  • (Charges remaining in (Item carried by (Triggering unit) in slot (Integer A))) Not equal to ItemMaxCharge
            • Then - Actions
              • Set ItemLowerThanMaxCharges = True
            • Else - Actions
              • Set ItemLowerThanMaxCharges = False
          • Hero - Give (Item being manipulated) to (Triggering unit)
          • Trigger - Turn on (This trigger)
          • Set ItemCharges = (Charges remaining in (Item carried by (Triggering unit) in slot (Integer A)))
          • Set ItemAcquireCharges = (Charges remaining in (Item being manipulated))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • ItemCharges Less than ItemMaxCharge
                  • ItemLowerThanMaxCharges Equal to True
            • Then - Actions
              • Set ItemDifferenceInCharges = (ItemMaxCharge - ItemCharges)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ItemAcquireCharges Greater than or equal to ItemDifferenceInCharges
                • Then - Actions
                  • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer A)) to ItemMaxCharge
                  • Set ItemAcquireCharges = (ItemAcquireCharges - ItemDifferenceInCharges)
                  • Trigger - Turn off (This trigger)
                  • Hero - Create Sunfish and give it to (Triggering unit)
                  • Trigger - Turn on (This trigger)
                  • Item - Set charges remaining in (Last created item) to ItemAcquireCharges
                • Else - Actions
                  • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer A)) to (ItemCharges + ItemAcquireCharges)
              • Item - Remove (Item being manipulated)
            • Else - Actions
  • Set item max charges
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ItemType Equal to Sunfish
        • Then - Actions
          • Set ItemMaxCharge = 10
          • Set ItemStackID = 1
        • Else - Actions
Thanks for showing me that turn Trigger-ON/OFF thingy to prevent infinite loops, rulerofiron99. :)
 
Last edited:
Status
Not open for further replies.
Top