• 🏆 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!

Help fixing the Timers

Status
Not open for further replies.
Level 8
Joined
Feb 20, 2020
Messages
200
Hello!
I need to fix this trigger, the idea of the trigger is, a hero unit dies, wait 30 sec, create another random hero in the same region of the dying one, i need it to work for multiple heroes dying at the same time.
It is only reviving the last monster.


  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet ForestRegions[1] = Flor1 <gen>
      • Set VariableSet ForestRegions[2] = Flor2 <gen>
      • Set VariableSet ForestRegions[3] = Flor3 <gen>
      • Set VariableSet ForestRegions[4] = Flor4 <gen>
      • Set VariableSet ForestRegions[5] = Flor5 <gen>
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • Set VariableSet RandomForestChance = (Random integer number between 1 and 100)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomForestChance Less than or equal to 20
            • Then - Actions
              • Unit - Create 1 Paladin for Player 11 (Dark Green) at (Center of ForestRegions[(Integer A)]) facing Default building facing degrees
              • Unit Group - Add (Last created unit) to ForestGroup
              • Set VariableSet ForestMonsterList[(Integer A)] = (Last created unit)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomForestChance Less than or equal to 40
                • Then - Actions
                  • Unit - Create 1 Archmage for Player 11 (Dark Green) at (Center of ForestRegions[(Integer A)]) facing Default building facing degrees
                  • Unit Group - Add (Last created unit) to ForestGroup
                  • Set VariableSet ForestMonsterList[(Integer A)] = (Last created unit)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • RandomForestChance Less than or equal to 70
                    • Then - Actions
                      • Unit - Create 1 Mountain King for Player 11 (Dark Green) at (Center of ForestRegions[(Integer A)]) facing Default building facing degrees
                      • Unit Group - Add (Last created unit) to ForestGroup
                      • Set VariableSet ForestMonsterList[(Integer A)] = (Last created unit)
                    • Else - Actions
                      • Unit - Create 1 Blood Mage for Player 11 (Dark Green) at (Center of ForestRegions[(Integer A)]) facing Default building facing degrees
                      • Unit Group - Add (Last created unit) to ForestGroup
                      • Set VariableSet ForestMonsterList[(Integer A)] = (Last created unit)
  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Dying unit) is in ForestGroup.) Equal to True
      • ((Dying unit) is A Hero) Equal to True
      • (Owner of (Dying unit)) Equal to Player 11 (Dark Green)
    • Actions
      • Set VariableSet MonsterDead = (Dying unit)
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • MonsterDead Equal to ForestMonsterList[(Integer A)]
            • Then - Actions
              • Unit Group - Remove MonsterDead from ForestGroup.
              • Countdown Timer - Start ForestMonsterTimer as a One-shot timer that will expire in 30.00 seconds
              • Set VariableSet MonsterNumber = (Integer A)
              • Set VariableSet ForestPositionRespawn = ForestRegions[MonsterNumber]
            • Else - Actions
  • Respawn New
    • Events
      • Time - ForestMonsterTimer expires
    • Conditions
    • Actions
      • Set VariableSet RandomForestChance = (Random integer number between 1 and 100)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • RandomForestChance Less than or equal to 20
        • Then - Actions
          • Unit - Create 1 Paladin for Player 11 (Dark Green) at (Center of ForestPositionRespawn) facing Default building facing degrees
          • Unit Group - Add (Last created unit) to ForestGroup
          • Set VariableSet ForestMonsterList[MonsterNumber] = (Last created unit)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomForestChance Less than or equal to 40
            • Then - Actions
              • Unit - Create 1 Archmage for Player 11 (Dark Green) at (Center of ForestPositionRespawn) facing Default building facing degrees
              • Unit Group - Add (Last created unit) to ForestGroup
              • Set VariableSet ForestMonsterList[MonsterNumber] = (Last created unit)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomForestChance Less than or equal to 70
                • Then - Actions
                  • Unit - Create 1 Mountain King for Player 11 (Dark Green) at (Center of ForestPositionRespawn) facing Default building facing degrees
                  • Unit Group - Add (Last created unit) to ForestGroup
                  • Set VariableSet ForestMonsterList[MonsterNumber] = (Last created unit)
                • Else - Actions
                  • Unit - Create 1 Blood Mage for Player 11 (Dark Green) at (Center of ForestPositionRespawn) facing Default building facing degrees
                  • Unit Group - Add (Last created unit) to ForestGroup
                  • Set VariableSet ForestMonsterList[MonsterNumber] = (Last created unit)
 
Last edited:
Level 5
Joined
Jun 12, 2018
Messages
148
Hi marcos, there is no need to write another thread for your problem, please make only one in the future if it concerns the same thing.

Concerning your triggers, it is working for only one hero because you are using only one timer (ForestMonsterTimer global variable). Therefore if one of your heroes dies 10 seconds (for example) after the previous one, the timer will be refreshed and linked to the last dying hero. Same goes with your variable of type 'point' called ForestPositionRespawn.

You need to use arrays to store every information you need and get it back when your timer expires. Question is now : what should I use as indexes to identify my heroes ?

Then you can think about three options :
  • Use arbitrary values like 0, 1, 2 (not recommanded if you want to work with other dev)
  • Use global variable as IDs (ex: ID_PALADIN_HERO) and initialize them during map init (set variable - ID_PADADIN_HERO = 1....)
  • Use a unit indexer library (like this one) which gives you unique IDs for every unit on the map
    You can then access to the ID of the unit with its custom value (check example below)
  • Countdown Timer - Start HeroesTimers[(Custom value of (Dying unit))] as a One-shot timer that will expire in 30.00 seconds
You don't even have to copy/paste every "Timer - ForestMonsterTimer[0], ForestMonsterTimer[1] expires" events as you can dynamically add a new event like shown below :
  • Countdown Timer - Start HeroesTimers[ID_PALADIN_HERO] as a One-shot timer that will expire in 30.00 seconds
  • Trigger - Add to Respawn New <gen> the event (Time - HeroesTimers[ID_PALADIN_HERO] expires)
Tell me if this is clear for you.
 
Level 8
Joined
Feb 20, 2020
Messages
200
ok, let me see if i get it...
First i import the unit indexer, that will index all the units created or already in the map.
Than i change the countdown timer for the ID of the monster., like you showed...
but the third part i dont get, about the "trigger - add..."
And what about the other triggers, dont need to change anything?

i removed the event from Respawn New, made it not initially on and well i did that to the respaw trigger and well... it didnot work!

here is the trigger now:

  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Dying unit) is in ForestGroup.) Equal to True
      • ((Dying unit) is A Hero) Equal to True
      • (Owner of (Dying unit)) Equal to Player 11 (Dark Green)
    • Actions
      • Set VariableSet MonsterDead = (Dying unit)
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • MonsterDead Equal to ForestMonsterList[(Integer A)]
            • Then - Actions
              • Unit Group - Remove MonsterDead from ForestGroup.
              • Countdown Timer - Start ForestMonsterTimer[(Custom value of MonsterDead)] as a One-shot timer that will expire in 30.00 seconds
              • Trigger - Add to Respawn New <gen> the event (Time - ForestMonsterTimer[(Custom value of MonsterDead)] expires)
              • Set VariableSet MonsterNumber = (Integer A)
              • Set VariableSet ForestPositionRespawn = ForestRegions[MonsterNumber]
            • Else - Actions
 
Last edited:
Level 5
Joined
Jun 12, 2018
Messages
148
You forgot to set ForestPositionRespawn variable to a point array :

  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Dying unit) is in ForestGroup.) Equal to True
      • ((Dying unit) is A Hero) Equal to True
      • (Owner of (Dying unit)) Equal to Player 11 (Dark Green)
    • Actions
      • Set VariableSet MonsterDead = (Dying unit)
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • MonsterDead Equal to ForestMonsterList[(Integer A)]
            • Then - Actions
              • Unit Group - Remove MonsterDead from ForestGroup.
              • Countdown Timer - Start ForestMonsterTimer[(Custom value of MonsterDead)] as a One-shot timer that will expire in 30.00 seconds
              • Trigger - Add to Respawn New <gen> the event (Time - ForestMonsterTimer[(Custom value of MonsterDead)] expires)
              • Set VariableSet MonsterNumber = (Integer A)
              • Set VariableSet ForestPositionRespawn[(Custom value of MonsterDead)] = ForestRegions[MonsterNumber] //this also needs to be an array indexed by the hero's custom value
            • Else - Actions
Then you have to remove the event in Respawn New trigger as we are now adding the events dynamically for each timer. Adapt your code to get the position from this array in this trigger and I think you're done.
 
Level 8
Joined
Feb 20, 2020
Messages
200
it should be initially on or just normal but without events? well it still not working...


  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Dying unit) is in ForestGroup.) Equal to True
      • ((Dying unit) is A Hero) Equal to True
      • (Owner of (Dying unit)) Equal to Player 11 (Dark Green)
    • Actions
      • Set VariableSet MonsterDead = (Dying unit)
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • MonsterDead Equal to ForestMonsterList[(Integer A)]
            • Then - Actions
              • Unit Group - Remove MonsterDead from ForestGroup.
              • Countdown Timer - Start ForestMonsterTimer[(Custom value of MonsterDead)] as a One-shot timer that will expire in 30.00 seconds
              • Trigger - Add to Respawn New <gen> the event (Time - ForestMonsterTimer[(Custom value of MonsterDead)] expires)
              • Set VariableSet MonsterNumber = (Integer A)
              • Set VariableSet ForestPositionRespawn[(Custom value of MonsterDead)] = ForestRegions[MonsterNumber]
            • Else - Actions
 
Last edited:
Level 5
Joined
Jun 12, 2018
Messages
148
normal, initially on and without events yes. Post your map here if you don't mind it will be easier to debug, else you can still repost all your triggers.
 
Level 5
Joined
Jun 12, 2018
Messages
148
It was a bit tricky because I didn't find a way to find a GUI condition to compare the expired timer with the ones saved. I had to use vJass custom scripts conditions to get the expired timer.

Also the "Timer - Start Timer" function is not working if one don't initialize the timer variables within the timer array, therefore you just have to call a simple line of code before starting a timer :
Code:
set udg_MY_TIMER_ARRAY[INDEX] = CreateTimer()

I've attached the fixed map in this post, I think the custom scripts parts will be ok for you to understand.

Also, the fix I did is not using the Unit Indexer library as it's not necessary for your problem.
 

Attachments

  • TesteRespawn fixed.w3m
    42.4 KB · Views: 19
Status
Not open for further replies.
Top