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

[Trigger] Adding and Removing Sold Units Buggy

Status
Not open for further replies.
Level 1
Joined
Oct 9, 2019
Messages
5
I'm using a decent amount of add/remove unit X from Y with stock Z, including instaces in loops over unit groups. Sometimes the stock becomes 1 instead of Z, while other times some units just straight up disappear from the shop. I can post screens/map if needed.

Edit:
I don't know what was wrong with the original way but I have circumvented the issue by doing it in a different way.
 
Last edited:
Level 24
Joined
Feb 27, 2019
Messages
833
Does this help?
 
Level 1
Joined
Oct 9, 2019
Messages
5
I've managed to add the triggers in the post. I'm already periodically readding 6 out of 8 units but sometimes their stock is one instead of the amount I want. Do you mean spawning units when I buy dummy items? I can try that later but it sounds like a non-trivial amount of replacing everything in those triggers, hence it's probably better to post the triggers first in case I'm doing something incredibly dumb.
  • Fortifications Income
    • Events
      • Unit - A unit Sells a unit
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Sold unit)) Equal to Increase Income
        • Then - Actions
          • Neutral Building - Remove Increase Income from (Triggering unit)
          • Neutral Building - Add Increase Income 2 to (Triggering unit) with 1 in stock and a max stock of 1
          • Unit - Remove (Sold unit) from the game
          • Hashtable - Save ((Load 0 of (Key (Triggering unit).) from CastleHash.) + 200) as 0 of (Key (Triggering unit).) in CastleHash.
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Sold unit)) Equal to Increase Income 2
        • Then - Actions
          • Neutral Building - Remove Increase Income 2 from (Triggering unit)
          • Neutral Building - Add Increase Income 3 to (Triggering unit) with 1 in stock and a max stock of 1
          • Unit - Remove (Sold unit) from the game
          • Hashtable - Save ((Load 0 of (Key (Triggering unit).) from CastleHash.) + 300) as 0 of (Key (Triggering unit).) in CastleHash.
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Sold unit)) Equal to Increase Income 3
        • Then - Actions
          • Neutral Building - Remove Increase Income 3 from (Triggering unit)
          • Neutral Building - Add Increase Income 4 to (Triggering unit) with 1 in stock and a max stock of 1
          • Unit - Remove (Sold unit) from the game
          • Hashtable - Save ((Load 0 of (Key (Triggering unit).) from CastleHash.) + 400) as 0 of (Key (Triggering unit).) in CastleHash.
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Sold unit)) Equal to Increase Income 4
        • Then - Actions
          • Neutral Building - Remove Increase Income 4 from (Triggering unit)
          • Unit - Remove (Sold unit) from the game
          • Hashtable - Save ((Load 0 of (Key (Triggering unit).) from CastleHash.) + 500) as 0 of (Key (Triggering unit).) in CastleHash.
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Sold unit)) Equal to Upgrade Fortifications
        • Then - Actions
          • Neutral Building - Remove Upgrade Fortifications from (Triggering unit)
          • Neutral Building - Add Upgrade Fortifications 2 to (Triggering unit) with 1 in stock and a max stock of 1
          • Unit - Remove (Sold unit) from the game
          • Unit - Set Max HP of (Triggering unit) to ((Max HP of (Triggering unit)) + 2500)
          • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 2500.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Sold unit)) Equal to Upgrade Fortifications 2
        • Then - Actions
          • Neutral Building - Remove Upgrade Fortifications 2 from (Triggering unit)
          • Neutral Building - Add Upgrade Fortifications 3 to (Triggering unit) with 1 in stock and a max stock of 1
          • Unit - Remove (Sold unit) from the game
          • Unit - Set Max HP of (Triggering unit) to ((Max HP of (Triggering unit)) + 2500)
          • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 2500.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Sold unit)) Equal to Upgrade Fortifications 3
        • Then - Actions
          • Neutral Building - Remove Upgrade Fortifications 3 from (Triggering unit)
          • Neutral Building - Add Upgrade Fortifications 4 to (Triggering unit) with 1 in stock and a max stock of 1
          • Unit - Remove (Sold unit) from the game
          • Unit - Set Max HP of (Triggering unit) to ((Max HP of (Triggering unit)) + 2500)
          • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 2500.00)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Sold unit)) Equal to Upgrade Fortifications 4
        • Then - Actions
          • Neutral Building - Remove Upgrade Fortifications 4 from (Triggering unit)
          • Unit - Remove (Sold unit) from the game
          • Unit - Set Max HP of (Triggering unit) to ((Max HP of (Triggering unit)) + 2500)
          • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 2500.00)
        • Else - Actions
  • Enables
    • Events
      • Unit - A unit Finishes research
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current research level of 1.1E Villager Enable for (Owner of (Triggering unit))) Equal to 1
        • Then - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) of type Central Duchy Castle) and do (Actions)
            • Loop - Actions
              • Neutral Building - Add Villager to (Picked unit) with 17 in stock and a max stock of 17
        • Else - Actions
      • If (ll Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current research level of 1.2E Fletcher Enable for (Owner of (Triggering unit))) Equal to 1
        • Then - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) of type Central Duchy Castle) and do (Actions)
            • Loop - Actions
              • Neutral Building - Add Fletcher to (Picked unit) with 13 in stock and a max stock of 13
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current research level of 1.3E Swordsmith Enable for (Owner of (Triggering unit))) Equal to 1
        • Then - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) of type Central Duchy Castle) and do (Actions)
            • Loop - Actions
              • Neutral Building - Add Swordsmith to (Picked unit) with 10 in stock and a max stock of 10
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current research level of 1.4E Healer Enable for (Owner of (Triggering unit))) Equal to 1
        • Then - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) of type Central Duchy Castle) and do (Actions)
            • Loop - Actions
              • Neutral Building - Add Healer to (Picked unit) with 7 in stock and a max stock of 7
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current research level of 1.5E Pikeman Enable for (Owner of (Triggering unit))) Equal to 1
        • Then - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) of type Central Duchy Castle) and do (Actions)
            • Loop - Actions
              • Neutral Building - Add Pikeman to (Picked unit) with 4 in stock and a max stock of 4
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current research level of 1.6E Horseman Enable for (Owner of (Triggering unit))) Equal to 1
        • Then - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) of type Central Duchy Castle) and do (Actions)
            • Loop - Actions
              • Neutral Building - Add Horseman to (Picked unit) with 2 in stock and a max stock of 2
        • Else - Actions
  • Restocks
    • Events
      • Time - Every 60.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units of type Central Duchy Castle) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current research level of 1.1E Villager Enable for (Owner of (Picked unit))) Greater than or equal to 1
            • Then - Actions
              • Neutral Building - Remove Villager from (Picked unit)
              • Neutral Building - Add Villager to (Picked unit) with 17 in stock and a max stock of 17
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current research level of 1.2E Fletcher Enable for (Owner of (Picked unit))) Greater than or equal to 1
            • Then - Actions
              • Neutral Building - Remove Fletcher from (Picked unit)
              • Neutral Building - Add Fletcher to (Picked unit) with 13 in stock and a max stock of 13
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current research level of 1.3E Swordsmith Enable for (Owner of (Picked unit))) Greater than or equal to 1
            • Then - Actions
              • Neutral Building - Remove Swordsmith from (Picked unit)
              • Neutral Building - Add Swordsmith to (Picked unit) with 10 in stock and a max stock of 10
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current research level of 1.4E Healer Enable for (Owner of (Picked unit))) Greater than or equal to 1
            • Then - Actions
              • Neutral Building - Remove Healer from (Picked unit)
              • Neutral Building - Add Healer to (Picked unit) with 7 in stock and a max stock of 7
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current research level of 1.5E Pikeman Enable for (Owner of (Picked unit))) Greater than or equal to 1
            • Then - Actions
              • Neutral Building - Remove Pikeman from (Picked unit)
              • Neutral Building - Add Pikeman to (Picked unit) with 4 in stock and a max stock of 4
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current research level of 1.6E Horseman Enable for (Owner of (Picked unit))) Greater than or equal to 1
            • Then - Actions
              • Neutral Building - Remove Horseman from (Picked unit)
              • Neutral Building - Add Horseman to (Picked unit) with 2 in stock and a max stock of 2
            • Else - Actions
  • CastleHash
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set VariableSet CastleHash = (Last created hashtable)
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units of type Central Duchy Castle) and do (Actions)
        • Loop - Actions
          • Neutral Building - Add Upgrade Fortifications to (Picked unit) with 1 in stock and a max stock of 1
          • Neutral Building - Add Increase Income to (Picked unit) with 1 in stock and a max stock of 1
          • Hashtable - Save 200 as 0 of (Key (Picked unit).) in CastleHash.
          • Unit - Create 1 Central Duchy Blacksmith for (Owner of (Picked unit)) at ((Position of (Picked unit)) offset by (200.00, 0.00)) facing Default building facing degrees
          • Hashtable - Save Handle Of(Last created unit) as 1 of (Key (Picked unit).) in CastleHash.
 
Status
Not open for further replies.
Top