Please Help with Important Trigger Problem

Progesterone

New Member
Dear all,
I need to create a trigger for a computer player which will ask his Barracks to IMMEDIATELY train a particular unit (knight), and MOVE that unit to a particular region (Region X) WHENEVER there are less than 2 of that unit(knights) in Region X; AND most importantly STOP the training when there are 2 or more knights in Region X. (ie, my goal is that I do not want more than 3 knights in Region X at any one time)

1)Trigger A
Event
Time - Every 3.00 seconds of game time
Condition
(Number of units in (Units in RegionX <gen> matching ((Unit-type of (Matching unit)) Equal to Knight))) Less than 2
Action
Unit - Order Barracks 0108 <gen> to train/upgrade to a Knight

3)Trigger B
Event
Unit - Barracks 0108 <gen> Finishes training a unit
Condition
(Unit-type of (Trained unit)) Equal to Knight
Action
Unit - Order (Trained unit) to Attack-Move To (Center of RegionX <gen>)

The problem I have: even though there were already more than TWO knights in Region X, the barracks KEPT ON TRAINING MORE KNIGHTS.

The reason for this, which I understood, was due to the BUILD ORDER phenomenon: ie, it takes time for the training of the knight to be completed and the knight to reach Region X; during this period, my trigger as above will cause the Barracks to ADD A KNIGHT IN THE BUILD ORDER every 3 seconds, and therefore, even though eventually my trained knights reached Region X and now the condition(that there are less than 2 knights in Region X) is not "true" anymore, the Barracks will just keep on training as there are still knights left in the Build Order.

I have tried increasing the "every x seconds" in Trigger A, but the effect is very inconsistent.
Can someone help me to overcome this problem to accomplish my goal as stated above?
Thanks a lot !
 

0WN3D

New Member
2 ways of fixing it
1: change teh training time of the knight to 3 seconds so that they wont stack
2: Not rly sure but it there is...... Use the unit cancel order action(If tehre is that is)
 

Progesterone

New Member
Thanks for the reply, but changing the build time will affect the game when other players are attacking, as the computer player will have an unfair advantage given that its knights can be produced so fast.
Can't find the cancel "build order", any ideas which category it is under ?
Is there a way to limit "build order to structures", ie, only allow barracks to have one order at a time ?
 

Napenthe

New Member
You could add a line to turn the trigger off for the length of the build time + travel time, then back on after. So there won't be any extras qued.

Say the unit build time + travel time to regionx was 145 sec.

Event
Time - Every 3.00 seconds of game time
Condition
(Number of units in (Units in RegionX <gen> matching ((Unit-type of (Matching unit)) Equal to Knight))) Less than 2
Action
Unit - Order Barracks 0108 <gen> to train/upgrade to a Knight
Trigger - Turn off (This trigger)
Wait 145.00 seconds
Trigger - Turn on (This trigger)

This will make it take a little longer to replace all knights if more than one dies but it should work.

or this might work;
make an integer variable with an initial value of 3. Make it so every time one of the knights dies it sets the variable to (variable -1). Then set (variable +1) whenever the building starts a knight.
it would look something like this:
Event
Time - Every 3.00 seconds of game time
Condition
knight_variable Less than 2
Action
Unit - Order Barracks 0108 <gen> to train/upgrade to a Knight
Set variable (knight_variable +1)

and a trigger to subtract 1 from 'knight_variable' when one of the knights dies.
 

Progesterone

New Member
Thanks for the reply !
I tried that but keep on getting this problem: the computer will initially train a knight once there is lesser or equal to 1 knight in region, but subsequently, when the knights are killed again to make the condition true (ie, lesser or equal to 1 knight in region), it does not train anymore ! In other words, it only works ONCE !
But why, given that the event is "EVERY x seconds" ?
How do I solve this problem ?
Appreciate your help very much !
 

Napenthe

New Member
Trigger:
  • copy the trigger in the trigger editor (right click, copy as text).
    • Then post the text surrounded by <div class="bbCodeBlock bbCodeBlock--screenLimited bbCodeBlock--code"><div class="bbCodeBlock-title">Trigger:</div><div class="wc3trigger"><ul class="wc3" id="wc3_1">
    • <li class="lasttree"><span class="default">and</span></li>
    • </ul>
    • </div></div>
 

Progesterone

New Member
Hi, thanks, my trigger looks like this:
Trigger:
  • Top Def A2
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
      • (Number of units in (Units in FrTopDefAct &lt;gen&gt; matching ((Unit-type of (Matching unit)) Equal to Knight))) Less than or equal to 1
    • Actions
      • Unit - Order Barracks 0108 &lt;gen&gt; to train/upgrade to a Knight
      • Trigger - Turn off Top Def A2 &lt;gen&gt;
      • Wait 40.00 seconds
      • Trigger - Turn on Top Def A2 &lt;gen&gt;


The Problem: the trigger does not loop ! Ie, initially when there is "less than or equal to 1 knight" in region FrTopDefAct, it will start training knights, but subsequently, when the knights get killed such that there is "less than or equal to 1 knight" in region FrTopDefAct, the barracks does not train any more knights !

Please help me ! Thanks !
 

evilwolf

Member
Thats because you turned the trigger off...
Once its turned off it will no longer do the actions you used below...
 

Progesterone

New Member
How about these 2 triggers ?
I tried but still cannot work.
My objective is for computer to train knights whenever there are less than 2 knights in region FrTopDefAct, and Stop training knights when there are 2 knights in the region.

Trigger:
  • Top Def A2
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
      • (Number of units in (Units in FrTopDefAct &lt;gen&gt; matching ((Unit-type of (Matching unit)) Equal to Knight))) Less than or equal to 1
    • Actions
      • Unit - Order Barracks 0108 &lt;gen&gt; to train/upgrade to a Knight
      • Trigger - Turn on Top Def Off &lt;gen&gt;
      • Trigger - Turn off Top Def A2 &lt;gen&gt;


Trigger:
  • Top Def Off
    • Events
      • Player - Player 5 (Yellow)'s Current gold becomes Greater than or equal to 300.00
    • Conditions
    • Actions
      • Wait 41.00 seconds
      • Trigger - Turn on Top Def A2 &lt;gen&gt;
      • Trigger - Turn off Top Def Off &lt;gen&gt;


Both triggers are enabled, and Trigger Top Def A2 is Initially On, while Trigger Top Def Off is Initially Off

Please help ! Thanks !
 

NeuroToxin

New Member
Why not just set an integer, when the integer becomes equal to 3, stop the training. Set the integer to 0, everytime the barracks trains one, set it to integer + 1
 

Progesterone

New Member
Thanks for the suggestion but the "Integer" method will not work for my case.
Reason: I need the computer to train a knight WHENEVER there are lesser than 2 knights in the region, ie, it's not just a one-time trigger, but it needs to be looped throughout the game.
You may suggest "how about 'minus one' to the integer everytime a knight dies, but that will not work as well, because this trigger needs to be "replicated" at 3 different locations (ie, checkpoints where the computer player is defending): ie, each location has a seperate barracks which will train a knight and send to that particular region (A, B or C) whenever there are lesser than 2 knights in the respective regions.
Any other suggestions ?
Been surfacing this problem for quite a while but still unable to come to a solution, will appreciate someone who can help me solve this very much !
Thanks !
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Integer Arrays work. Seriously, they fix every problem listed there. Even if they don't, hashtables should.
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Trigger:
  • Barracks Defense
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 3, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • NumberOfKnights[(Integer A)] Less than or equal to 1
            • Then - Actions
              • Unit - Order Barracks[(Integer A)] to train/upgrade to a Knight
              • Set NumberOfKnights[(Integer A)] = (NumberOfKnights[(Integer A)] + 1)
            • Else - Actions
    • Barracks Defense Assign
      • Events
        • Unit - A unit Finishes training a unit
      • Conditions
        • (Unit-type of (Trained unit)) Equal to Knight
      • Actions
        • Unit - Set the custom value of (Trained unit) to (Custom value of (Triggering unit))
        • Unit - Order (Trained unit) to Attack-Move To (Center of RegionToDefend[(Custom Value of (Triggering Unit))])
        • -------- The Triggering Unit is the Barracks, as far as I can tell. --------
    • Barracks Defense Reduce
      • Events
        • Unit - A unit owned by Player 5 (Yellow) Dies
      • Conditions
        • (Unit-type of (Triggering unit)) Equal to Knight
      • Actions
        • Set NumberOfKnights[(Custom value of (Triggering unit))] = ((Custom value of (Triggering unit)) - 1)


At the start assign each of your barracks a custom value to be used as the index for Arrays. Assign all the regions the same way. The first trigger is the one that begins training, then increases the number of Knights currently existing (regardless of whether it is trained or not). The second one assigns all Knights the custom value of their Barracks, which tells you which Barracks should train another Knight when one dies. The last trigger will reduce the number of Knights of one Barracks currently existing when one Knight dies. This will allow the first trigger to make that Barracks train a new knight. I hope this helped - it used up all 24.2% of my laptop's remaining power.
 

evilwolf

Member
You could replace the triggering unit with another unit exactly like one once there are 2 knights in the region, I think it will interupt the training queue.
That's the problem of the trigger, 'Trained Unit' should only work for 'Unit - A unit Finishes training a unit' events. I was kind of hoping 'Constructing Structure' would fit, but it doesn't either.

Also, this part wont work either from what I've seen during my past testing:

The construction wont be cancled.

And another small detail:

Doesn't do anything (O'rly?), so it's no use placing it. It only exists for the 'If / Then / Else' action (without the multiple functions).

--
Now ofcourse if I cant find anything an option would be to make the building sell items rather then training units, and triggering the whole production process using timers and everything. The disadvantage of this is that you'll be unable to see a construction bar for the unit.
--

=====================EDIT=====================
Alright... I'm bloody brilliant! :D :D :D
I've made a trigger that worked perfectly, it only has one disadvantage... it doesn't work without a wait. I don't know why it doesn't work without one, but it's a wait of 0.01 seconds.
Trigger:
  • Stop training
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Issued order) Equal to (Order(Footman))
    • Actions
      • Wait 0.01 seconds
      • Game - Force (Owner of (Triggering unit)) to press Escape/Cancel

This will not work if:
1. The player deselects the building within 0.01 seconds of starting to build the unit.
2. The player issuses a new order within 0.01 seconds of starting to build the unit.
3. Your PC explodes.

I'm not sure, but this really is the only way I could find to cancel unit production without having to replace the Barracks every time... <,<
I've been able to make it bug by pressing the Hotkey for Footman and at the same time selecting a different unit.
=====================/EDIT====================
This works!
 

Progesterone

New Member
Trigger:
  • Barracks Defense
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 3, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • NumberOfKnights[(Integer A)] Less than or equal to 1
            • Then - Actions
              • Unit - Order Barracks[(Integer A)] to train/upgrade to a Knight
              • Set NumberOfKnights[(Integer A)] = (NumberOfKnights[(Integer A)] + 1)
            • Else - Actions
    • Barracks Defense Assign
      • Events
        • Unit - A unit Finishes training a unit
      • Conditions
        • (Unit-type of (Trained unit)) Equal to Knight
      • Actions
        • Unit - Set the custom value of (Trained unit) to (Custom value of (Triggering unit))
        • Unit - Order (Trained unit) to Attack-Move To (Center of RegionToDefend[(Custom Value of (Triggering Unit))])
        • -------- The Triggering Unit is the Barracks, as far as I can tell. --------
    • Barracks Defense Reduce
      • Events
        • Unit - A unit owned by Player 5 (Yellow) Dies
      • Conditions
        • (Unit-type of (Triggering unit)) Equal to Knight
      • Actions
        • Set NumberOfKnights[(Custom value of (Triggering unit))] = ((Custom value of (Triggering unit)) - 1)


At the start assign each of your barracks a custom value to be used as the index for Arrays. Assign all the regions the same way. The first trigger is the one that begins training, then increases the number of Knights currently existing (regardless of whether it is trained or not). The second one assigns all Knights the custom value of their Barracks, which tells you which Barracks should train another Knight when one dies. The last trigger will reduce the number of Knights of one Barracks currently existing when one Knight dies. This will allow the first trigger to make that Barracks train a new knight. I hope this helped - it used up all 24.2% of my laptop's remaining power.
Thanks for the reply ! Appreciate your efforts lots !
Got a question: You said "At the start assign each of your barracks a custom value to be used as the index for Arrays. Assign all the regions the same way." How exactly do I do that ? Do I just create variables and name it Barracks and click array and put number as 3 ? And how to do it for regions ?
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • C Cherry.Grove:
    My one game was basically Among Us but you sabotaged an entire medieval city simulated drastically inefficiently with dynamic NPCs :S
  • C Cherry.Grove:
    of course I never finished it x D
  • jonas jonas:
    xD
  • jonas jonas:
    I think you can still run the original game, just there's a chance your map won't work with the newer patches
  • jonas jonas:
    what development framework have you been looking at for mobile development?
  • jonas jonas:
    I'm currently creating (as a hobby) a space invaders like game for mobile using Xamarin, after starting a few larger projects that I also may not have finished :rolleyes::p
  • The Helper The Helper:
    Awesome! you should look at the Atari VCS platform it does not have a huge user base but the one it has is super active at around 11k and they have no games in there store
  • The Helper The Helper:
    basically it is linux
  • The Helper The Helper:
    OMG it is BanLord as Blackveiled on the forum
  • The Helper The Helper:
    what is up buddy
  • jonas jonas:
    thanks for the tip, that sounds cool. Never heard about the VCS before but seems like it should be a good match
  • tom_mai78101 tom_mai78101:
    The winter vacation left a toll on me. I missed staying up late and sleeping in late.
  • C Cherry.Grove:
    i haven't looked into it yet
  • C Cherry.Grove:
    If I could use something Python compatible it would save me some learning
  • C Cherry.Grove:
    But Unity might be easiest
  • C Cherry.Grove:
    looking at old posts here makes me happy. Makes me be all like "wow I was pretty smart in 2009"
  • C Cherry.Grove:
    mostly failing at life through adulthood really demotivated me for a while
  • C Cherry.Grove:
    ....what I don't get is why the fuck they would force us to permanently convert to a version of the game everyone fucking hated : \
  • C Cherry.Grove:
    Raid Shadow Legends texture pack smh
  • jonas jonas:
    Most people fail at life throughout their adulthood. Sometimes we get to learn from it. Usually it just feels like crap.
    +1
  • The Helper The Helper:
    What does not kill you makes you stronger is what they say
  • C Cherry.Grove:
    for real! :cool:
  • Varine Varine:
    Are we still on the topic of failing? I failed lots!
  • jonas jonas:
    If you ever want to talk about it we're here. The way I see it, you're still around. That required a few very difficult successes if you ask me:)

    Members online

    Affiliates

    Hive Workshop NUON Dome
    Top