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

[AI] Ai script

Status
Not open for further replies.
Level 7
Joined
Mar 6, 2014
Messages
203
Hello can you help me how to create better AI system which can buy items, retreating when hp is low, can select random hero from before the game begin, uses skill item like teleport, and chase low hp enemy

Advance thanks
 
Level 13
Joined
Jul 16, 2012
Messages
679
Okay.... Here all my example for AI Trigger

Buying Item
  • Untitled Trigger 001
    • Events
      • Unit - A unit comes within 256.00 of Shop
    • Conditions
      • ((Triggering unit) is in AIGroup) Equal to True
    • Actions
      • Player - Add -1000 to (Owner of (Triggering unit)) Current gold
      • Hero - Create Kelen's Dagger of Escape and give it to (Triggering unit)
Retreating Low HP
  • Untitled Trigger 002
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in AIGroup) Equal to True
      • (Percentage life of (Triggering unit)) Less than or equal to 30.00
    • Actions
      • Set AI_TempPoint = (Player 1 (Red) start location)
      • Unit - Order (Triggering unit) to Move To AI_TempPoint
      • Custom script: call RemoveLocation( udg_AI_TempPoint)
Picking Random Hero

  1. Setup All Heroes
    • Untitled Trigger 003
      • Events
        • Map initialization
      • Conditions
      • Actions
        • Set AI_Heroes[1] = Paladin
        • Set AI_Heroes[2] = Archmage
        • Set AI_HeroesCount = 2
        • Custom script: call DestroyTrigger( GetTriggeringTrigger())
  2. Pick Random Hero
    • Untitled Trigger 004
      • Events
        • Time - Elapsed game time is 5.00 seconds
      • 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
                • ((Player((Integer A))) is in AI_PlayerGroup) Equal to True
              • Then - Actions
                • Set AI_TempPoint = ((Player((Integer A))) start location)
                • Unit - Create 1 AI_Heroes[(Random integer number between 1 and AI_HeroesCount)] for Player[Integer A] at AI_TempPoint facing Default building facing degrees
                • Unit Group - Add (Last created unit) to AIGroup
                • Custom script: call RemoveLocation( udg_AI_TempPoint)
              • Else - Actions
Smell Low HP Unit
  • Untitled Trigger 005
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in AIGroup and do (Actions)
        • Loop - Actions
          • Set AI_TempUnit = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • Custom script: set bj_wantDestroyGroup=true
              • Unit Group - Pick every unit in (Units within 400.00 of (Position of AI_TempUnit)) and do (Actions)
                • Loop - Actions
                  • Set AI_TempUnit2 = (Picked unit)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Percentage life of (Picked unit)) Less than or equal to 10.00
                      • ((Picked unit) is alive) Equal to True
                    • Then - Actions
                      • Unit - Order AI_TempUnit to Attack AI_TempUnit2
                    • Else - Actions
            • Else - Actions
And Thats all..

check it if work properly :)
 
Last edited:
The last trigger will cause malfunctions, you can't have a "pick every unit" function inside one.
In the example it leaks location, and the unit variables should be used instead of "Picked unit", but why there are malfunctions?

@AKA.GywGod133,

In "Buying Item" trigger you should check if triggering unit is a hero.

In "Retreating Low HP" trigger, your event A Unit Dies doesnt make much sense. Also the condition if HP is lower than 30 doesnt make much sense if unit is dead already.
Also this point could be set once in init trigger and never be destroyed, as you always use the same point over and over again.

In "Pick Random Hero" trigger:
  • Unit - Create 1 AI_Heroes[(Random integer number between 1 and AI_HeroesCount)] for Player 1 (Red) at AI_TempPoint facing Default building facing degrees
You create a hero for Player 1 each time. You forget to it to Player[LoopInteger].
 

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,892
In the example it leaks location, and the unit variables should be used instead of "Picked unit", but why there are malfunctions?
What do you think this trigger triggers:
  • Pick
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Player 1 (Red)) and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units owned by Player 2 (Blue)) and do (Actions)
            • Loop - Actions
              • Unit - Explode (Picked unit)
It will only explode the units of player 2, and it should explode the units of player 1, causing malfunction.
 
Level 13
Joined
Jul 16, 2012
Messages
679
@IcemanBo

In "Buying Item" trigger you should check if triggering unit is a hero.

No need to check if the unit is a hero. By using AIGroup, all picked hero will be add it in this group means all unit in AIGroup is a hero.

if you suggestion, add check hero is better. :)

In "Retreating Low HP" trigger, your event A Unit Dies doesnt make much sense. Also the condition if HP is lower than 30 doesnt make much sense if unit is dead already.
Also this point could be set once in init trigger and never be destroyed, as you always use the same point over and over again.

Hmm Btw, Mostly this retreating low hp better use Trigger Loop

In "Pick Random Hero" trigger:
  • Unit - Create 1 AI_Heroes[(Random integer number between 1 and AI_HeroesCount)] for Player 1 (Red) at AI_TempPoint facing Default building facing degrees
You create a hero for Player 1 each time. You forget to it to Player[LoopInteger]

Sorry for that...
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
What do you think this trigger triggers:
  • Pick
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Player 1 (Red)) and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units owned by Player 2 (Blue)) and do (Actions)
            • Loop - Actions
              • Unit - Explode (Picked unit)
It will only explode the units of player 2, and it should explode the units of player 1, causing malfunction.

What:vw_wtf:It should only explode units for player 2, in you want to explode also player 1 units, you do this

  • Pick
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Player 1 (Red)) and do (Actions)
        • Loop - Actions
          • Unit - Explode (Picked unit)
          • Unit Group - Pick every unit in (Units owned by Player 2 (Blue)) and do (Actions)
            • Loop - Actions
              • Unit - Explode (Picked unit)
And there is nothing wrong with this method.It just does what it supposed to do, explodes "last" picked unit, which is units of player 2 now.
 
@AKA.GywGod133, oh yes. You're right. I didn't recognize your condition. :s

@Wrda, I think Ceday already answered it well. But wanted to add that I knew that you mean that, but there was no mistake in AKA.GywGod133's example trigger, because there are own variables used for picked unit to prevent malfunction. (and your statement included this example: "The last trigger will cause malfunctions, you can't have a "pick every unit" function inside one."...
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
the buy could be enhanced, or removed, because your version currently tries(and suceeds in doing so) to create Kelen's Dagger for hero of given player, even if he doesnt have the 1K gold required.

Also you didnt show how to use items, but that is quite hard to do inteligently(smart casting items, not just randomly bashing them, but predicting)
 
Status
Not open for further replies.
Top