• 🏆 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] Timer not working for AI players

Status
Not open for further replies.

sentrywiz

S

sentrywiz

I have these triggers:

  • death and win
  • Events
    • Unit - A unit Dies
  • Conditions
    • (Unit-type of (Dying unit)) Equal to Fber
  • Actions
    • Countdown Timer - Start death_timer[(Player number of (Owner of (Dying unit)))] as a One-shot timer that will expire in 10.00 seconds
    • Set death_timer[(Player number of (Owner of (Dying unit)))] = (Last started timer)
    • Countdown Timer - Create a timer window for death_timer[(Player number of (Owner of (Dying unit)))] with title Revival
    • Set death_timer_window[(Player number of (Owner of (Dying unit)))] = (Last created timer window)
    • Countdown Timer - Show death_timer_window[(Player number of (Owner of (Triggering unit)))] for (Owner of (Dying unit))
And the rev triggers:

  • rev me
    • Events
      • Time - death_timer[1] expires
      • Time - death_timer[2] expires
      • Time - death_timer[3] expires
      • Time - death_timer[4] expires
      • Time - death_timer[5] expires
      • Time - death_timer[6] expires
      • Time - death_timer[7] expires
      • Time - death_timer[8] expires
      • Time - death_timer[9] expires
      • Time - death_timer[10] expires
      • Time - death_timer[11] expires
      • Time - death_timer[12] expires
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Remaining time for death_timer[(Integer A)]) Equal to 0.00
            • Then - Actions
              • Set temp_loc = (Random point in (Playable map area))
              • Countdown Timer - Destroy death_timer_window[(Integer A)]
              • Hero - Instantly revive fber_hero[(Integer A)] at temp_loc, Show revival graphics
              • Selection - Select fber_hero[(Integer A)] for player[(Integer A)]
              • Camera - Pan camera for player[(Integer A)] to temp_loc over 0.00 seconds
              • Custom script: call RemoveLocation ( udg_temp_loc )
            • Else - Actions
Everytime an AI Player dies, the revival timer window is shown to ME and it doesn't have numbers on it.
It gets stuck somehow or it doesn't trigger at all. The trigger works for me, but not for the AI


Anyone knows why?
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Are the computer players added in the game lobby?

The trigger doesn't look like it has issues, but you can troubleshoot it like this:
Instead of referencing (player number of (owner of (triggering unit))) so many times, save it to a temp variable at the start of the trigger and use that. Also display this variable so that you can see which value you're getting.

You might need to manually set the array size of death_timer[] in the variable editor.

Instead of (Integer A), use your own integer. Integer A and B sometimes give issues.

The condition you're using to check which player's timer expired is problematic, since it will fire for players that are alive. In addition to that condition, you should also check to see if that hero is dead.
 

sentrywiz

S

sentrywiz

Are the computer players added in the game lobby?

The trigger doesn't look like it has issues, but you can troubleshoot it like this:
Instead of referencing (player number of (owner of (triggering unit))) so many times, save it to a temp variable at the start of the trigger and use that. Also display this variable so that you can see which value you're getting.

You might need to manually set the array size of death_timer[] in the variable editor.

Instead of (Integer A), use your own integer. Integer A and B sometimes give issues.

The condition you're using to check which player's timer expired is problematic, since it will fire for players that are alive. In addition to that condition, you should also check to see if that hero is dead.

I added the condition, thanks for the reminder.

as you and maker said, I added the death timer manually and now it respawns the AI.

However, the death_timer_window variable either doesn't work or there is something that I don't know about it since it still shows all the respawn windows to ME.
Maybe it shows them to the AI, I can't know because ... yeah they are AI.
 
Level 3
Joined
Dec 31, 2003
Messages
42
I think this condition is the problem:
  • (Remaining time for death_timer[(Integer A)]) Equal to 0.00
Any timer not running would return true for this, causing your actions to be taken on possibly nonexistant timer windows, heroes etc. That would probably end the execution of the code, and the loop would never reach the AI players. Try (if it exists, I'm guessing it doesn't because you're not using it)
  • (Remaining time for death_timer[(Integer A)]) Equal to Expired timer
or add something like
  • ... and death_timer[(Integer A)] Not equal to no timer

Edit: Some other stuff... You could add this at the end of the actions to halt the loop once the correct timer is found
  • Custom script: exitwhen true
And don't forget to destroy the timer after it executes. Countdown Timer - Start timer automagically creates one for you
 

sentrywiz

S

sentrywiz

I think this condition is the problem:
  • (Remaining time for death_timer[(Integer A)]) Equal to 0.00
Any timer not running would return true for this, causing your actions to be taken on possibly nonexistant timer windows, heroes etc. That would probably end the execution of the code, and the loop would never reach the AI players. Try (if it exists, I'm guessing it doesn't because you're not using it)
  • (Remaining time for death_timer[(Integer A)]) Equal to Expired timer
or add something like
  • ... and death_timer[(Integer A)] Not equal to no timer

Edit: Some other stuff... You could add this at the end of the actions to halt the loop once the correct timer is found
  • Custom script: exitwhen true
And don't forget to destroy the timer after it executes. Countdown Timer - Start timer automagically creates one for you

The problem isn't about destroying the windows, that works fine. The thing is they get created on MY SCREEN for all the other AI players. Mine as well, and theirs.

EDIT:

Fixed it, with the following changes:

  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Dying unit)) Equal to player[(Integer A)]
          • (player[(Integer A)] controller) Equal to User
        • Then - Actions
          • Countdown Timer - Start death_timer[(Player number of player[(Integer A)])] as a One-shot timer that will expire in 10.00 seconds
          • Set death_timer[(Player number of player[(Integer A)])] = (Last started timer)
          • Countdown Timer - Create a timer window for death_timer[(Player number of player[(Integer A)])] with title Rev
          • Set death_timer_window[(Player number of player[(Integer A)])] = (Last created timer window)
          • Countdown Timer - Show death_timer_window[(Player number of player[(Integer A)])] for player[(Integer A)]
          • Game - Display to (All players) for 5.00 seconds the text: (Showing window to: + (Name of player[(Integer A)]))
        • Else - Actions
          • Game - Display to (All players) for 5.00 seconds the text: (Not showing window to: + (Name of player[(Integer A)]))
The game messages are just for testing.
 
Last edited by a moderator:
Level 18
Joined
Nov 21, 2012
Messages
835
Timer Windows shou;d be hide for all players, then show for those who should see that. Maker said that already. For your revieve trigger my suggestion is use GetExpiredTimer, no aviable in Gui , use cust script like this:

  • HeroRevieve
    • Events
      • Time - HeroRevieve[1] expires
      • Time - HeroRevieve[2] expires
      • Time - HeroRevieve[3] expires
      • Time - HeroRevieve[4] expires
      • Time - HeroRevieve[5] expires
      • Time - HeroRevieve[6] expires
      • Time - HeroRevieve[7] expires
      • Time - HeroRevieve[8] expires
      • Time - HeroRevieve[9] expires
    • Conditions
    • Actions
      • For each (Integer TempIntegerA) from 1 to 9, do (Actions)
        • Loop - Actions
          • Custom script: if (GetExpiredTimer() == udg_HeroRevieve[udg_TempIntegerA]) then
          • -------- ---------------------------- --------
          • Countdown Timer - Destroy HeroRevieveWindow[TempIntegerA]
          • -------- your actions here --------
          • -------- ---------------------------- --------
          • -------- ---------------------------- --------
          • Custom script: endif
zibi
 

sentrywiz

S

sentrywiz

Timer Windows shou;d be hide for all players, then show for those who should see that. Maker said that already. For your revieve trigger my suggestion is use GetExpiredTimer, no aviable in Gui , use cust script like this:

  • HeroRevieve
    • Events
      • Time - HeroRevieve[1] expires
      • Time - HeroRevieve[2] expires
      • Time - HeroRevieve[3] expires
      • Time - HeroRevieve[4] expires
      • Time - HeroRevieve[5] expires
      • Time - HeroRevieve[6] expires
      • Time - HeroRevieve[7] expires
      • Time - HeroRevieve[8] expires
      • Time - HeroRevieve[9] expires
    • Conditions
    • Actions
      • For each (Integer TempIntegerA) from 1 to 9, do (Actions)
        • Loop - Actions
          • Custom script: if (GetExpiredTimer() == udg_HeroRevieve[udg_TempIntegerA]) then
          • -------- ---------------------------- --------
          • Countdown Timer - Destroy HeroRevieveWindow[TempIntegerA]
          • -------- your actions here --------
          • -------- ---------------------------- --------
          • -------- ---------------------------- --------
          • Custom script: endif
zibi

Cool, I like this but I already found my own solution. Still I will keep in mind that you can use custom scripts for if/else.

You could also break out of the loop when the correct timer is found, or use a hashtable to attach the player id to each timer. Then there is no need for a loop.

Good point. I will add that. I think it was "exitwhen true" as custom script
 
Status
Not open for further replies.
Top