• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Tome Tax - Shop Item Replacement

Status
Not open for further replies.
Level 16
Joined
Mar 27, 2011
Messages
1,349
Hi all,

Goal: I'm making a Tome tax system. Every few tomes the player purchases, the cost of that tome rises for that player only until a cap is reached (currently 5). I wanted to ditch having triggers do the gold requirement check and deduction after purchase and have the current price listed on the actual item tooltip.
Implementation: When a player clicks on the tome shop, their selection is changed to a dummy shop at the same location owned by the player (each player has 2 shops - one for each neutral shop on the map). Each dummy shop starts with "Tax 1" tomes (the default non taxed version I guess). When they buy 6 of a particular tome, it rises to Tax 2 and so on for each type of tome. When this happens, the tome, in only the triggering player's shop, is replaced with it's upper level.
The Problem: For some reason, some tomes go missing after certain tomes are leveled up to a certain point. Many of the first purchased seem to work flawlessly and at some point the tomes start vanishing after tome purchases.

Which tomes go missing depend on which tomes I purchase prior. I can't see a pattern to this.

Triggers

FYI - This is called by another trigger at Map Initialization.
  • Tome Tax Setup
    • Events
    • Conditions
    • Actions
      • -------- -------- --------
      • -------- Setup Tomes --------
      • -------- -------- --------
      • Set VariableSet TomeTax_Cap = 0
      • Set VariableSet TomeTax_ArtOfFighting_Item[TomeTax_Cap] = Art of Fighting
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_ArtOfFighting_Item[TomeTax_Cap] = Art of Fighting - Tax 2
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_ArtOfFighting_Item[TomeTax_Cap] = Art of Fighting - Tax 3
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_ArtOfFighting_Item[TomeTax_Cap] = Art of Fighting - Tax 4
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_ArtOfFighting_Item[TomeTax_Cap] = Art of Fighting - Tax 5
      • -------- ----------------------------------------------- --------
      • Set VariableSet TomeTax_Cap = 0
      • Set VariableSet TomeTax_Vitality_Item[TomeTax_Cap] = Manual of Vitality
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Vitality_Item[TomeTax_Cap] = Manual of Vitality - Tax 2
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Vitality_Item[TomeTax_Cap] = Manual of Vitality - Tax 3
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Vitality_Item[TomeTax_Cap] = Manual of Vitality - Tax 4
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Vitality_Item[TomeTax_Cap] = Manual of Vitality - Tax 5
      • -------- ----------------------------------------------- --------
      • Set VariableSet TomeTax_Cap = 0
      • Set VariableSet TomeTax_Agility_Item[TomeTax_Cap] = Tome of Agility
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Agility_Item[TomeTax_Cap] = Tome of Agility - Tax 2
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Agility_Item[TomeTax_Cap] = Tome of Agility - Tax 3
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Agility_Item[TomeTax_Cap] = Tome of Agility - Tax 4
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Agility_Item[TomeTax_Cap] = Tome of Agility - Tax 5
      • -------- ----------------------------------------------- --------
      • Set VariableSet TomeTax_Cap = 0
      • Set VariableSet TomeTax_Intelligence_Item[TomeTax_Cap] = Tome of Intelligence
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Intelligence_Item[TomeTax_Cap] = Tome of Intelligence - Tax 2
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Intelligence_Item[TomeTax_Cap] = Tome of Intelligence - Tax 3
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Intelligence_Item[TomeTax_Cap] = Tome of Intelligence - Tax 4
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Intelligence_Item[TomeTax_Cap] = Tome of Intelligence - Tax 5
      • -------- ----------------------------------------------- --------
      • Set VariableSet TomeTax_Cap = 0
      • Set VariableSet TomeTax_Strength_Item[TomeTax_Cap] = Tome of Strength
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Strength_Item[TomeTax_Cap] = Tome of Strength - Tax 2
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Strength_Item[TomeTax_Cap] = Tome of Strength - Tax 3
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Strength_Item[TomeTax_Cap] = Tome of Strength - Tax 4
      • Set VariableSet TomeTax_Cap = (TomeTax_Cap + 1)
      • Set VariableSet TomeTax_Strength_Item[TomeTax_Cap] = Tome of Strength - Tax 5
      • -------- -------- --------
      • -------- Setup Shops --------
      • -------- -------- --------
      • Set VariableSet TempPoint1 = (Position of Tent Of Training 2 0028 <gen>)
      • Set VariableSet TempPoint2 = (Position of Tent Of Training 2 0035 <gen>)
      • Player Group - Pick every player in PlayerGroupAllies and do (Actions)
        • Loop - Actions
          • Unit - Create 1 Tent Of Training (Players Hidden One) for (Picked player) at TempPoint1 facing Default building facing degrees
          • Set VariableSet TomeTax_Shop_Cliff[(Player number of (Picked player))] = (Last created unit)
          • Neutral Building - Add TomeTax_ArtOfFighting_Item[0] to TomeTax_Shop_Cliff[(Player number of (Picked player))] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Vitality_Item[0] to TomeTax_Shop_Cliff[(Player number of (Picked player))] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Agility_Item[0] to TomeTax_Shop_Cliff[(Player number of (Picked player))] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Intelligence_Item[0] to TomeTax_Shop_Cliff[(Player number of (Picked player))] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Strength_Item[0] to TomeTax_Shop_Cliff[(Player number of (Picked player))] with 1 in stock and a max stock of 1
          • Unit - Create 1 Tent Of Training (Players Hidden One) for (Picked player) at TempPoint2 facing Default building facing degrees
          • Set VariableSet TomeTax_Shop_NearWizard[(Player number of (Picked player))] = (Last created unit)
          • Neutral Building - Add TomeTax_ArtOfFighting_Item[0] to TomeTax_Shop_NearWizard[(Player number of (Picked player))] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Vitality_Item[0] to TomeTax_Shop_NearWizard[(Player number of (Picked player))] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Agility_Item[0] to TomeTax_Shop_NearWizard[(Player number of (Picked player))] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Intelligence_Item[0] to TomeTax_Shop_NearWizard[(Player number of (Picked player))] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Strength_Item[0] to TomeTax_Shop_NearWizard[(Player number of (Picked player))] with 1 in stock and a max stock of 1
      • Custom script: call RemoveLocation (udg_TempPoint1)
      • Custom script: call RemoveLocation (udg_TempPoint2)

  • Tome Tax Select Shop
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Triggering unit) Equal to Tent Of Training 2 0028 <gen>
        • Then - Actions
          • -------- Training Hut on the Cliff --------
          • Selection - Select TomeTax_Shop_Cliff[(Player number of (Triggering player))] for (Triggering player)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Triggering unit) Equal to Tent Of Training 2 0035 <gen>
            • Then - Actions
              • -------- Training Hut near the Wizards hut --------
              • Selection - Select TomeTax_Shop_NearWizard[(Player number of (Triggering player))] for (Triggering player)
            • Else - Actions

  • Tome Tax Purchase
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
    • Actions
      • Set VariableSet TempInteger1 = (Player number of (Owner of (Buying unit)))
      • -------- The interval before a new price is required. --------
      • Set VariableSet TempInteger2 = 6
      • -------- ------------------ --------
      • -------- Art of Fighting --------
      • -------- ------------------ --------
      • For each (Integer A) from 0 to TomeTax_Cap, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to TomeTax_ArtOfFighting_Item[(Integer A)]
            • Then - Actions
              • Set VariableSet TomeTax_ArtOfFighting[TempInteger1] = (TomeTax_ArtOfFighting[TempInteger1] + 1)
              • -------- TempInteger3 should truncate the decimal of the result and give us the whole value we want. --------
              • Set VariableSet TempInteger3 = (TomeTax_ArtOfFighting[TempInteger1] / TempInteger2)
              • Game - Display to (All players) for 5.00 seconds the text: (Fighting Integer3: + (String(TempInteger3)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of (Sold Item)) Not equal to TomeTax_ArtOfFighting_Item[TempInteger3]
                  • TempInteger3 Less than or equal to TomeTax_Cap
                • Then - Actions
                  • Game - Display to (All players) for 5.00 seconds the text: (Replacing + (Name of (Sold Item)))
                  • Neutral Building - Remove (Item-type of (Sold Item)) from TomeTax_Shop_Cliff[TempInteger1]
                  • Neutral Building - Add TomeTax_ArtOfFighting_Item[TempInteger3] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
                  • Neutral Building - Remove (Item-type of (Sold Item)) from TomeTax_Shop_NearWizard[TempInteger1]
                  • Neutral Building - Add TomeTax_ArtOfFighting_Item[TempInteger3] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
                • Else - Actions
            • Else - Actions
      • -------- ------------------ --------
      • -------- Vitality --------
      • -------- ------------------ --------
      • For each (Integer A) from 0 to TomeTax_Cap, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to TomeTax_Vitality_Item[(Integer A)]
            • Then - Actions
              • Set VariableSet TomeTax_Vitality[TempInteger1] = (TomeTax_Vitality[TempInteger1] + 1)
              • Set VariableSet TempInteger3 = (TomeTax_Vitality[TempInteger1] / TempInteger2)
              • Game - Display to (All players) for 5.00 seconds the text: (Vitality Integer3: + (String(TempInteger3)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of (Sold Item)) Not equal to TomeTax_Vitality_Item[TempInteger3]
                  • TempInteger3 Less than or equal to TomeTax_Cap
                • Then - Actions
                  • Game - Display to (All players) for 5.00 seconds the text: (Replacing + (Name of (Sold Item)))
                  • Neutral Building - Remove (Item-type of (Sold Item)) from TomeTax_Shop_Cliff[TempInteger1]
                  • Neutral Building - Add TomeTax_Vitality_Item[TempInteger3] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
                  • Neutral Building - Remove (Item-type of (Sold Item)) from TomeTax_Shop_NearWizard[TempInteger1]
                  • Neutral Building - Add TomeTax_Vitality_Item[TempInteger3] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
                • Else - Actions
            • Else - Actions
      • -------- ------------------ --------
      • -------- Agility --------
      • -------- ------------------ --------
      • For each (Integer A) from 0 to TomeTax_Cap, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to TomeTax_Agility_Item[(Integer A)]
            • Then - Actions
              • Set VariableSet TomeTax_Agility[TempInteger1] = (TomeTax_Agility[TempInteger1] + 1)
              • Set VariableSet TempInteger3 = (TomeTax_Agility[TempInteger1] / TempInteger2)
              • Game - Display to (All players) for 5.00 seconds the text: (Agility Integer3: + (String(TempInteger3)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of (Sold Item)) Not equal to TomeTax_Agility_Item[TempInteger3]
                  • TempInteger3 Less than or equal to TomeTax_Cap
                • Then - Actions
                  • Game - Display to (All players) for 5.00 seconds the text: (Replacing + (Name of (Sold Item)))
                  • Neutral Building - Remove (Item-type of (Sold Item)) from TomeTax_Shop_Cliff[TempInteger1]
                  • Neutral Building - Add TomeTax_Agility_Item[TempInteger3] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
                  • Neutral Building - Remove (Item-type of (Sold Item)) from TomeTax_Shop_NearWizard[TempInteger1]
                  • Neutral Building - Add TomeTax_Agility_Item[TempInteger3] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
                • Else - Actions
            • Else - Actions
      • -------- ------------------ --------
      • -------- Intelligence --------
      • -------- ------------------ --------
      • For each (Integer A) from 0 to TomeTax_Cap, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to TomeTax_Intelligence_Item[(Integer A)]
            • Then - Actions
              • Set VariableSet TomeTax_Intelligence[TempInteger1] = (TomeTax_Intelligence[TempInteger1] + 1)
              • Set VariableSet TempInteger3 = (TomeTax_Intelligence[TempInteger1] / TempInteger2)
              • Game - Display to (All players) for 5.00 seconds the text: (Intelligence Integer3: + (String(TempInteger3)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of (Sold Item)) Not equal to TomeTax_Intelligence_Item[TempInteger3]
                  • TempInteger3 Less than or equal to TomeTax_Cap
                • Then - Actions
                  • Game - Display to (All players) for 5.00 seconds the text: (Replacing + (Name of (Sold Item)))
                  • Neutral Building - Remove (Item-type of (Sold Item)) from TomeTax_Shop_Cliff[TempInteger1]
                  • Neutral Building - Add TomeTax_Intelligence_Item[TempInteger3] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
                  • Neutral Building - Remove (Item-type of (Sold Item)) from TomeTax_Shop_NearWizard[TempInteger1]
                  • Neutral Building - Add TomeTax_Intelligence_Item[TempInteger3] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
                • Else - Actions
            • Else - Actions
      • -------- ------------------ --------
      • -------- Strength --------
      • -------- ------------------ --------
      • For each (Integer A) from 0 to TomeTax_Cap, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to TomeTax_Strength_Item[(Integer A)]
            • Then - Actions
              • Set VariableSet TomeTax_Strength[TempInteger1] = (TomeTax_Strength[TempInteger1] + 1)
              • Set VariableSet TempInteger3 = (TomeTax_Strength[TempInteger1] / TempInteger2)
              • Game - Display to (All players) for 5.00 seconds the text: (Strength Integer3: + (String(TempInteger3)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of (Sold Item)) Not equal to TomeTax_Strength_Item[TempInteger3]
                  • TempInteger3 Less than or equal to TomeTax_Cap
                • Then - Actions
                  • Game - Display to (All players) for 5.00 seconds the text: (Replacing + (Name of (Sold Item)))
                  • Neutral Building - Remove (Item-type of (Sold Item)) from TomeTax_Shop_Cliff[TempInteger1]
                  • Neutral Building - Add TomeTax_Strength_Item[TempInteger3] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
                  • Neutral Building - Remove (Item-type of (Sold Item)) from TomeTax_Shop_NearWizard[TempInteger1]
                  • Neutral Building - Add TomeTax_Strength_Item[TempInteger3] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
                • Else - Actions
            • Else - Actions
      • Game - Display to (All players) for 5.00 seconds the text: Finished Trigger Ex...
Can anyone identify where I've gone wrong?
 

Attachments

  • Tomes Missing.jpg
    Tomes Missing.jpg
    116.8 KB · Views: 27
  • Tomes Missing 1.jpg
    Tomes Missing 1.jpg
    186 KB · Views: 24
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,511
I remember fixing this issue by recreating the shop's sold item list each time I made a change. I did this by setting the shop's Sell Limit to 0 and then 12, and then repopulating the item list using a hashtable.

So each player would have their current tomes stored in the hashtable mapped to their player number. Whenever you purchase a tome you update the hashtable to store the new next tier tome inside of it, of course checking to see that you haven't gone above the tier limit.

Also, I advise against using Integer A as the variable inside of your For Loops to avoid conflicts between multiple triggers. It's best to always use a new unique variable for these. Some exceptions apply if you're 100% sure of what you're doing.
 
Last edited:
Level 16
Joined
Mar 27, 2011
Messages
1,349
I remember fixing this issue by recreating the shop's sold item list each time I made a change.

So there is a bug with adding and removing items?

I did this by setting the shop's Sell Limit to 0 and then 12, and then repopulating the item list using a hashtable.

So something like this I presume? I imagine limiting the shop's items to 0 its a quick way or removing all items?

I'll give this a go when I get some time in a couple of hours (very rought concept demonstrated below).

Edit: Your suggestion is working. I think it eats up more resources having to make more item replace calls than what I thought would be necessary, but oh well. Warcraft 3 is buggy :p My code is below for anyone's reference. I've created one more function to accommodate the change (which isn't strictly necessary, but I thought made the system a little cleaner.

  • Tome Tax Copy Copy
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
    • Actions
      • Set VariableSet TempInteger1 = (Player number of (Owner of (Buying unit)))
      • -------- The interval before a new price is required. --------
      • Set VariableSet TempInteger2 = 6
      • -------- ------------------ --------
      • -------- Art of Fighting --------
      • -------- ------------------ --------
      • For each (Integer A) from 0 to TomeTax_Cap, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to TomeTax_ArtOfFighting_Item[(Integer A)]
            • Then - Actions
              • Set VariableSet TomeTax_ArtOfFighting[TempInteger1] = (TomeTax_ArtOfFighting[TempInteger1] + 1)
              • Set VariableSet TempInteger3 = (TomeTax_ArtOfFighting[TempInteger1] / TempInteger2)
              • Game - Display to (All players) for 5.00 seconds the text: (Fighting Integer3: + (String(TempInteger3)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of (Sold Item)) Not equal to TomeTax_ArtOfFighting_Item[TempInteger3]
                  • TempInteger3 Less than or equal to TomeTax_Cap
                • Then - Actions
                  • Game - Display to (All players) for 5.00 seconds the text: (Replacing + (Name of (Sold Item)))
                  • Trigger - Run Tome Tax Refresh Items <gen> (ignoring conditions)
                • Else - Actions
            • Else - Actions
      • -------- ------------------ --------
      • -------- Vitality --------
      • -------- ------------------ --------
      • For each (Integer A) from 0 to TomeTax_Cap, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to TomeTax_Vitality_Item[(Integer A)]
            • Then - Actions
              • Set VariableSet TomeTax_Vitality[TempInteger1] = (TomeTax_Vitality[TempInteger1] + 1)
              • Set VariableSet TempInteger3 = (TomeTax_Vitality[TempInteger1] / TempInteger2)
              • Game - Display to (All players) for 5.00 seconds the text: (Vitality Integer3: + (String(TempInteger3)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of (Sold Item)) Not equal to TomeTax_Vitality_Item[TempInteger3]
                  • TempInteger3 Less than or equal to TomeTax_Cap
                • Then - Actions
                  • Game - Display to (All players) for 5.00 seconds the text: (Replacing + (Name of (Sold Item)))
                  • Trigger - Run Tome Tax Refresh Items <gen> (ignoring conditions)
                • Else - Actions
            • Else - Actions
      • -------- ------------------ --------
      • -------- Agility --------
      • -------- ------------------ --------
      • For each (Integer A) from 0 to TomeTax_Cap, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to TomeTax_Agility_Item[(Integer A)]
            • Then - Actions
              • Set VariableSet TomeTax_Agility[TempInteger1] = (TomeTax_Agility[TempInteger1] + 1)
              • Set VariableSet TempInteger3 = (TomeTax_Agility[TempInteger1] / TempInteger2)
              • Game - Display to (All players) for 5.00 seconds the text: (Agility Integer3: + (String(TempInteger3)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of (Sold Item)) Not equal to TomeTax_Agility_Item[TempInteger3]
                  • TempInteger3 Less than or equal to TomeTax_Cap
                • Then - Actions
                  • Game - Display to (All players) for 5.00 seconds the text: (Replacing + (Name of (Sold Item)))
                  • Trigger - Run Tome Tax Refresh Items <gen> (ignoring conditions)
                • Else - Actions
            • Else - Actions
      • -------- ------------------ --------
      • -------- Intelligence --------
      • -------- ------------------ --------
      • For each (Integer A) from 0 to TomeTax_Cap, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to TomeTax_Intelligence_Item[(Integer A)]
            • Then - Actions
              • Set VariableSet TomeTax_Intelligence[TempInteger1] = (TomeTax_Intelligence[TempInteger1] + 1)
              • Set VariableSet TempInteger3 = (TomeTax_Intelligence[TempInteger1] / TempInteger2)
              • Game - Display to (All players) for 5.00 seconds the text: (Intelligence Integer3: + (String(TempInteger3)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of (Sold Item)) Not equal to TomeTax_Intelligence_Item[TempInteger3]
                  • TempInteger3 Less than or equal to TomeTax_Cap
                • Then - Actions
                  • Game - Display to (All players) for 5.00 seconds the text: (Replacing + (Name of (Sold Item)))
                  • Trigger - Run Tome Tax Refresh Items <gen> (ignoring conditions)
                • Else - Actions
            • Else - Actions
      • -------- ------------------ --------
      • -------- Strength --------
      • -------- ------------------ --------
      • For each (Integer A) from 0 to TomeTax_Cap, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to TomeTax_Strength_Item[(Integer A)]
            • Then - Actions
              • Set VariableSet TomeTax_Strength[TempInteger1] = (TomeTax_Strength[TempInteger1] + 1)
              • Set VariableSet TempInteger3 = (TomeTax_Strength[TempInteger1] / TempInteger2)
              • Game - Display to (All players) for 5.00 seconds the text: (Strength Integer3: + (String(TempInteger3)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of (Sold Item)) Not equal to TomeTax_Strength_Item[TempInteger3]
                  • TempInteger3 Less than or equal to TomeTax_Cap
                • Then - Actions
                  • Game - Display to (All players) for 5.00 seconds the text: (Replacing + (Name of (Sold Item)))
                  • Trigger - Run Tome Tax Refresh Items <gen> (ignoring conditions)
                • Else - Actions
            • Else - Actions
  • Tome Tax Refresh Items
    • Events
    • Conditions
    • Actions
      • -------- ----------- --------
      • -------- Remove Items --------
      • -------- ----------- --------
      • Neutral Building - Limit TomeTax_Shop_Cliff[TempInteger1] to 0 item slots
      • Neutral Building - Limit TomeTax_Shop_Cliff[TempInteger1] to 12 item slots
      • Neutral Building - Limit TomeTax_Shop_NearWizard[TempInteger1] to 0 item slots
      • Neutral Building - Limit TomeTax_Shop_NearWizard[TempInteger1] to 12 item slots
      • -------- ----------- --------
      • -------- Re-Add Items --------
      • -------- ----------- --------
      • Set VariableSet TempInteger3 = (TomeTax_ArtOfFighting[TempInteger1] / TempInteger2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TempInteger3 Less than or equal to TomeTax_Cap
        • Then - Actions
          • Neutral Building - Add TomeTax_ArtOfFighting_Item[TempInteger3] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_ArtOfFighting_Item[TempInteger3] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
        • Else - Actions
          • Neutral Building - Add TomeTax_ArtOfFighting_Item[TomeTax_Cap] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_ArtOfFighting_Item[TomeTax_Cap] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
      • Set VariableSet TempInteger3 = (TomeTax_Vitality[TempInteger1] / TempInteger2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TempInteger3 Less than or equal to TomeTax_Cap
        • Then - Actions
          • Neutral Building - Add TomeTax_Vitality_Item[TempInteger3] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Vitality_Item[TempInteger3] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
        • Else - Actions
          • Neutral Building - Add TomeTax_Vitality_Item[TomeTax_Cap] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Vitality_Item[TomeTax_Cap] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
      • Set VariableSet TempInteger3 = (TomeTax_Agility[TempInteger1] / TempInteger2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TempInteger3 Less than or equal to TomeTax_Cap
        • Then - Actions
          • Neutral Building - Add TomeTax_Agility_Item[TempInteger3] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Agility_Item[TempInteger3] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
        • Else - Actions
          • Neutral Building - Add TomeTax_Agility_Item[TomeTax_Cap] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Agility_Item[TomeTax_Cap] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
      • Set VariableSet TempInteger3 = (TomeTax_Intelligence[TempInteger1] / TempInteger2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TempInteger3 Less than or equal to TomeTax_Cap
        • Then - Actions
          • Neutral Building - Add TomeTax_Intelligence_Item[TempInteger3] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Intelligence_Item[TempInteger3] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
        • Else - Actions
          • Neutral Building - Add TomeTax_Intelligence_Item[TomeTax_Cap] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Intelligence_Item[TomeTax_Cap] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
      • Set VariableSet TempInteger3 = (TomeTax_Strength[TempInteger1] / TempInteger2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TempInteger3 Less than or equal to TomeTax_Cap
        • Then - Actions
          • Neutral Building - Add TomeTax_Strength_Item[TempInteger3] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Strength_Item[TempInteger3] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
        • Else - Actions
          • Neutral Building - Add TomeTax_Strength_Item[TomeTax_Cap] to TomeTax_Shop_Cliff[TempInteger1] with 1 in stock and a max stock of 1
          • Neutral Building - Add TomeTax_Strength_Item[TomeTax_Cap] to TomeTax_Shop_NearWizard[TempInteger1] with 1 in stock and a max stock of 1
Also, I advise against using Integer A as the variable inside of your For Loops to avoid conflicts between multiple triggers.

I found this article:

Unless nesting more than 2 loops, why wouldn't I use Integer A loops? One person says a custom variable loop is faster (not sure by how much), and I presume this is because (internally) a variable does not need to be created (we use an existing global variable). If we wanted one nested loop, I imagine we could nest an Integer B loop (and custom loops from then on if 3 nests is really required?)

  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • -------- Do something --------
          • For each (Integer B) from 1 to 10, do (Actions)
            • Loop - Actions
              • -------- Do something --------
How can an Integer A loop mess with other triggers?
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,511
You should avoid using those Loop variables because they're global variables that can be overwritten from other triggers. Like I said, it's possible to use them without issues, but it's good practice to avoid potential issues and save yourself debugging in the future.

Example of what I mean (written from memory so the triggers will look a little weird):
  • Events:
  • Unit - A unit dies
  • Actions:
  • For loop IntegerA from 1 to 2 do:
  • Unit - Create UnitType[IntegerA] at center of map
  • <---- This is where the Actions from the second trigger will be inserted
  • Item - Create ItemType[IntegerA] and give it to last created unit
  • Display IntegerA as text
  • Events:
  • Unit - A unit enters the map
  • Actions:
  • For loop IntegerA from 3 to 4 do:
  • Display IntegerA as text

If you create and test the two triggers above you should be able to see what I mean. The first trigger will create UnitType[1] during it's first cycle of the Loop, but that unit will then "enter the map", causing the second trigger to run which has a For Loop as well that also uses IntegerA. Because of this when it comes time to Create ItemType[1] it will have the wrong index value [4] because the second For Loop has changed IntegerA to 4.

This concept holds true throughout all of your triggers as it's easy to share variables between triggers and then accidentally overwrite them. I think that a good amount of people believe that triggers always execute separately, but that's not the case. It's possible to cause a trigger to run DURING the execution of another trigger, and that can easily cause problems if global variables (and even some Event Responses) are shared between the two.
 
Last edited:
Status
Not open for further replies.
Top