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

If (hero is dead) {order_revieve();} // AI question

Status
Not open for further replies.
Level 7
Joined
Mar 6, 2006
Messages
282
Are you using GUI?

When you select a new Event/Condition/Action, there is a dropdown box called "Type".

So if you're searching for an action to revive a hero, you would use that list as reference, and see what most relates to what you need. In this case, it would be 'Hero'.

Then, once looking at the Hero Actions, you'll see there's an action to revive dead heroes.

You can also select "Search for text" and type something like "revive" or "hero".


Edit: whoops, I've never actually used that to revive heroes before, it has a nice little description of exactly what you want. "You can also revive a hero at an altar by issuing a revive order targetting the hero".

Interesting, I never done that before.

Ok, well now you're looking for a new action, try the search this time. Search for things like "issue" or "order". Remember you're ordering the Altar to target the dead Hero, and the order needs to be 'revive'
 
Level 7
Joined
Oct 8, 2007
Messages
154
I know the action but dont really know what event and conditions to make to order AI controlled player to revieve hero when its dead.

I see something like :

Code:
Event:

Time elapsed each 10 seconds

Conditions:

Player controller is Computer
Hero is Dead

Action:

Order Altar to Revieve Hero

But don't know how to perform it in practice I havent been using triggers since long time.

Edit:
Anyway this kind of trigger seems to be laggy cause trigger will be activated each 30 secs :/

I would rather like to have trigger like

  • Events
  • Hero Dies
  • Conditions
  • Player controler is Computer
  • Actions
  • Issue Order to Altar to revieve hero
 
Level 7
Joined
Oct 8, 2007
Messages
154
Ok even to be more exact

I have RANDOM_HERO_ARRAY which contains every hero in game

Other way to make this triger is

  • bot revieves hero
    • Events
      • Unit - Any Unit contained in RANDOM_HERO_ARRAY Dies
    • Conditions
      • (Player 7 (Green) controller) Equal to Computer
    • Actions
      • Unit - Order Barracks 0001 <gen> to Revive Hero (The hero who died)

But I dont know how to make event for "Any Unit Contained in RANDOM_HERO_ARRAY" and Action for hero who just died.

I try to do it but there is no possibility of putting for loop in event or sth like this.
Only option I see is this:
randomher_nqnwqqh.JPG


I'm getting pissed with that trigger maybe shall i usse jass to force program to check all positions in array during Event (InitTrig) function ?
 
Level 7
Joined
Mar 6, 2006
Messages
282
Event - You had it right there! Hero dies, that's a unit event, generic because it could apply to any player.

Condition - This is where you check if it's a hero. The type of condition is a boolean. Hero is a classification, so you do a boolean unit classification check.

The second condition is, yes, if the dying hero belonged to a computer. You should have a LOT of things set to variables if you're doing AI with computers, one of which would be a boolean array at map initialization, for IsComputer or something similar. Something so that your AI triggers only run for the computers. (edit: yea you can use 'Is equal to Computer' too, it all depends on how you select what players will be bots, whether you do it in game or in the lobby)

Actions - When a hero dies, it takes a second before you're allowed to revive it at an altar, so you'd have to wait a few seconds before reviving.

Again, you need to set everything to variables for these computers. All their bases need to be set to a unit array, where the position in the array is equal to their player number. Then you can use "Player number of (Owner of (whatever))" to retrieve the correct base, or whatever else they may own.

Same thing goes for the Hero, it needs to be in a unit array and retrieved the same way.

  • Events
    • Unit - A unit Dies
  • Conditions
    • ((Triggering unit) is A Hero) Equal to True
    • IsComputer Equal to True
  • Actions
    • Wait 5.00 seconds
    • Unit - Order Base[(Player number of (Owner of (Triggering unit)))] to Revive Hero ComputerHero[(Player number of (Owner of (Triggering unit)))]
And the last thing is, you're going to have another trigger that's probably waiting for your hero to revive. There needs to be a timeout on that trig as a fail-safe, and when the timeout hits, try to revive the hero again.
 
Level 7
Joined
Oct 8, 2007
Messages
154
Event - You had it right there! Hero dies, that's a unit event, generic because it could apply to any player.

Condition - This is where you check if it's a hero. The type of condition is a boolean. Hero is a classification, so you do a boolean unit classification check.

The second condition is, yes, if the dying hero belonged to a computer. You should have a LOT of things set to variables if you're doing AI with computers, one of which would be a boolean array at map initialization, for IsComputer or something similar. Something so that your AI triggers only run for the computers. (edit: yea you can use 'Is equal to Computer' too, it all depends on how you select what players will be bots, whether you do it in game or in the lobby)

Actions - When a hero dies, it takes a second before you're allowed to revive it at an altar, so you'd have to wait a few seconds before reviving.

Again, you need to set everything to variables for these computers. All their bases need to be set to a unit array, where the position in the array is equal to their player number. Then you can use "Player number of (Owner of (whatever))" to retrieve the correct base, or whatever else they may own.

Same thing goes for the Hero, it needs to be in a unit array and retrieved the same way.

  • Events
    • Unit - A unit Dies
  • Conditions
    • ((Triggering unit) is A Hero) Equal to True
    • IsComputer Equal to True
  • Actions
    • Wait 5.00 seconds
    • Unit - Order Base[(Player number of (Owner of (Triggering unit)))] to Revive Hero ComputerHero[(Player number of (Owner of (Triggering unit)))]
And the last thing is, you're going to have another trigger that's probably waiting for your hero to revive. There needs to be a timeout on that trig as a fail-safe, and when the timeout hits, try to revive the hero again.


  • bot ozywia bohatera
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • (Player 7 (Green) controller) Equal to Computer
    • Actions
      • Unit - Order Barracks 0001 <gen> to Revive Hero (Revivable Hero)
I did it like this but it doesnt work

I dont know how to put
  • ComputerHero[(Player number of (Owner of (Triggering unit)))]
Into a trigger
 
Level 7
Joined
Oct 8, 2007
Messages
154
This is a lot better to do for heroes as you do not need to make a timer or anything for the revival time. It is not immediate this way.

  • Events
    • Unit - A unit Becomes revivable
  • Conditions
  • Actions
    • Unit - Order myUnit to Revive Hero (Revivable Hero)

It looks cool but doesnt work :/ I even try with standard altar of storms and it doesnt works, however i checked if trigger is activated via event "hero becomes reviveable by issuing other actions to it and it worked so it looks like the target of action is wrong or something :/

  • bot revieves a hero
    • Events
      • Unit - A unit Becomes revivable
    • Conditions
    • Actions
      • Unit - Order Altar of Storms 0166 <gen> to Revive Hero (Revivable Hero)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
The trigger may not work as the heroes could possible not be revivable. This happens because some events fire before their the event triggerer is applied, eg unit is damaged fires before the damage is dealt to the unit's life.

The simplest and safest solution would be to add an infinite loop with a triggersleepaction (wait) that lets it evaluate every few seconds. Until the alter actually starts reviving the hero you keep looping. Even once the hero is being revived you keep looping as the alter may be destroyed so another alter may need to be used. Only once the hero has been revived, then you stop looping and let the thread die.
 
Level 7
Joined
Oct 8, 2007
Messages
154
The trigger may not work as the heroes could possible not be revivable. This happens because some events fire before their the event triggerer is applied, eg unit is damaged fires before the damage is dealt to the unit's life.

The simplest and safest solution would be to add an infinite loop with a triggersleepaction (wait) that lets it evaluate every few seconds. Until the alter actually starts reviving the hero you keep looping. Even once the hero is being revived you keep looping as the alter may be destroyed so another alter may need to be used. Only once the hero has been revived, then you stop looping and let the thread die.

awww could you give an example of such trigger

I try

  • bot ozywia bohatera
    • Events
      • Unit - A unit Becomes revivable
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 1000, do (Actions)
        • Loop - Actions
          • Wait 60.00 seconds
          • Unit - Order Upgrade Center 0176 <gen> to Revive Hero (Revivable Hero)

It doesnt work anyway :(
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
that is most likely, because after Wait, the Revivable Hero loses reference to the hero actually revivable, so it returns null instead
I also dont understand why you have the loop in there

You can try this:

  • Events
    • Unit - A unit Becomes revivable
  • Conditions
    • //whatever conditions you want
  • Actions
    • Custom script: local unit revive = GetRevivableUnit()
    • Wait 60.00 seconds
    • Unit - Order (Last created unit) to Revive Hero revive
    • Custom script: set revive = null
make sure you have global variable called revive, or you change the name of the local unit revive

edit: Simplified version:

  • Events
    • Unit - A unit Becomes revivable
  • Conditions
    • //whatever conditions you want
  • Actions
    • Wait 60.00 seconds
    • Unit - Order (Last created unit) to Revive Hero (Triggering Unit)
 
Last edited:
Status
Not open for further replies.
Top