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

I want to order AI to buy certain hero in tavern

Status
Not open for further replies.
Level 7
Joined
Oct 8, 2007
Messages
154
Hi, as threads says I want to order AI to buy certain hero at tavern, at the start of game and maybe later too.

Exactly the problem is that i'm working on footy frenzy AI and already made script in which computer player should buy heroes, upgrade tier, buying upgrades etc. (i have changed game constants etc.) but I know I need to write AI using triggers or jass. Script I got already makes AI to attack enemy with footies and return to base as footies got low life but it's way of playing is very lazy and unagressive like in meele map so i will have to change it later, but for now I want AI at least to buy hero in tavern at the begining game, in tavern there is unit called "random hero" which spawns random hero from heroes array so i just want ai to always buy "random hero" and then see how it plays with hero etc. test it against players.

Could you help me ?
 
Level 7
Joined
Oct 8, 2007
Messages
154
okay, but if so I want hero to be created only if player is ai, and take gold from him the same time, but anyway I want to give ai possibility to buy another hero in later game ...
Please help me I havent been doing trigerss and jass since few years, forgot lots of things and now I decided to write ai to my footy as part of project for university subject "Artifficial Inteligence" ;)
 
Level 10
Joined
Dec 15, 2012
Messages
650
  • AI buy Hero
    • Events
      • Unit - A unit enters NearbyTavern
    • Conditions
      • ((Owner of (Triggering unit)) controller) Equal to Computer
    • Actions
      • Set TempInt = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AI_Order[TempInt] Equal to 1.00
          • ((Owner of (Triggering unit)) Current gold) Greater than or equal to 500
        • Then - Actions
          • Unit - Create 1 Footman for (Owner of (Triggering unit)) at Point facing (Random angle) degrees
          • Player - Add -500 to (Owner of (Triggering unit)) Current gold
        • Else - Actions
          • -------- AI want to buy Hero but it do not has enough gold. Order AI to earn gold. --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • AI_Order[TempInt] Equal to 1.00
              • (Player 1 (Red) Current gold) Less than 500
            • Then - Actions
              • Set AI_Order[TempInt] = 2.00
            • Else - Actions
AI_Order is a does array Real variable.
1.00 => Buy Hero (order AI go to nearby Tavern)
2.00 => Earn gold (Killing creeps or something else)

I hope my expanation is clear :/
 
Level 7
Joined
Oct 8, 2007
Messages
154
  • AI buy Hero
    • -------- AI want to buy Hero but it do not has enough gold. Order AI to earn gold. --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • AI_Order[TempInt] Equal to 1.00
        • (Player 1 (Red) Current gold) Less than 500
      • Then - Actions
        • Set AI_Order[TempInt] = 2.00
      • Else - Actions
AI_Order is a does array Real variable.


Okay... so I guess this trigger should work only for Player 1 Red, I have changed trigger a little but anyway it still is not working.

  • kupbohatera2
    • Events
      • Unit - A unit enters custom hero tavern2 <gen>
    • Conditions
      • ((Owner of (Triggering unit)) controller) Equal to Computer
    • Actions
      • Set TempInt = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AI_Order[TempInt] Equal to 1.00
          • ((Owner of (Triggering unit)) Current gold) Greater than or equal to 1700
        • Then - Actions
          • Unit - Create 1 Random Hero for (Owner of (Triggering unit)) at (Center of spawn ai hero region <gen>) facing Default building facing degrees
          • Player - Add -1700 to (Owner of (Triggering unit)) Current gold
        • Else - Actions
          • -------- ai wants to buy a hero although it does not have money --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • AI_Order[TempInt] Equal to 1.00
              • (Player 7 (Green) Current gold) Less than 1700
            • Then - Actions
              • Set AI_Order[TempInt] = 2.00
            • Else - Actions
Despite of fact Region of Custom hero tavern 2 is quite big but I order unit of Green player to follow tavern, so there is no doubt that it enters proper region

  • kup bohatera
    • Events
      • Time - Elapsed game time is 2.00 seconds
    • Conditions
    • Actions
      • Unit - Order Wisp 0053 <gen> to Follow Custom Hero Tavern 2! 0072 <gen>
      • Unit - Order Wisp 0055 <gen> to Follow Custom Hero Tavern 2! 0072 <gen>
      • Unit - Order Wisp 0060 <gen> to Follow Custom Hero Tavern 2! 0072 <gen>
      • Unit - Order Wisp 0057 <gen> to Move To ((Center of (Playable map area)) offset by (-3200.00, 169.00))
      • Unit - Order Wisp 0053 <gen> to Follow Custom Hero Tavern 2! 0072 <gen>
      • Unit - Order Wisp 0053 <gen> to Follow Custom Hero Tavern 2! 0072 <gen>
Maybe the problem is in values inside AI_Order , did I misunderstood variables initialization ?

aiorder.jpg


or maybe TempInt is initialized wrong ???

tempint.jpg


If you want to help me I can send you map to see everything clear and localize mistake.

thanks in advance !
 
Level 10
Joined
Dec 15, 2012
Messages
650
Player 1 (red) is my mistaken xD, actually it should be (Owner of (Triggering unit))
-----------------------------------
Hmmm, nothing wrong with the variables.
  • AI Buy Hero
    • Events
      • Unit - A unit enters Buy Hero <gen>
    • Conditions
      • ((Owner of (Triggering unit)) controller) Equal to Computer
    • Actions
      • Set TempInt = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AI_Order[TempInt] Equal to 1.00
          • ((Owner of (Triggering unit)) Current gold) Greater than or equal to 1700
        • Then - Actions
          • Player - Add -1700 to (Owner of (Triggering unit)) Current gold
          • -------- TempPoint used to remove point leaks --------
          • Set TempPoint = (Position of (Triggering unit))
          • Unit - Create 1 Paladin for (Owner of (Triggering unit)) at TempPoint facing (Random angle) degrees
          • Custom script: call RemoveLocation(udg_TempPoint)
          • Custom script: set udg_TempPoint = null
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Owner of (Triggering unit)) Current gold) Less than 1700
              • AI_Order[TempInt] Equal to 1.00
            • Then - Actions
              • Set AI_Order[TempInt] = 2.00
            • Else - Actions
  • Time to Test
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Visibility - Disable black mask
      • Visibility - Disable fog of war
      • Player - Set Player 2 (Blue) Current gold to 2000
      • Set TempPoint = (Random point in Buy Hero <gen>)
      • Unit - Order Peasant 0001 <gen> to Move To TempPoint
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Custom script: set udg_TempPoint = null
Mine works perfectly, I think you juz forget to give AI money ?? -.- Or maybe your Random Hero has problem ??
 
Level 7
Joined
Oct 8, 2007
Messages
154
Player 1 (red) is my mistaken xD, actually it should be (Owner of (Triggering unit))
-----------------------------------
Hmmm, nothing wrong with the variables.
  • AI Buy Hero
    • Events
      • Unit - A unit enters Buy Hero <gen>
    • Conditions
      • ((Owner of (Triggering unit)) controller) Equal to Computer
    • Actions
      • Set TempInt = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AI_Order[TempInt] Equal to 1.00
          • ((Owner of (Triggering unit)) Current gold) Greater than or equal to 1700
        • Then - Actions
          • Player - Add -1700 to (Owner of (Triggering unit)) Current gold
          • -------- TempPoint used to remove point leaks --------
          • Set TempPoint = (Position of (Triggering unit))
          • Unit - Create 1 Paladin for (Owner of (Triggering unit)) at TempPoint facing (Random angle) degrees
          • Custom script: call RemoveLocation(udg_TempPoint)
          • Custom script: set udg_TempPoint = null
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Owner of (Triggering unit)) Current gold) Less than 1700
              • AI_Order[TempInt] Equal to 1.00
            • Then - Actions
              • Set AI_Order[TempInt] = 2.00
            • Else - Actions
  • Time to Test
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Visibility - Disable black mask
      • Visibility - Disable fog of war
      • Player - Set Player 2 (Blue) Current gold to 2000
      • Set TempPoint = (Random point in Buy Hero <gen>)
      • Unit - Order Peasant 0001 <gen> to Move To TempPoint
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Custom script: set udg_TempPoint = null
Mine works perfectly, I think you juz forget to give AI money ?? -.- Or maybe your Random Hero has problem ??



yay ! Now it works but as you said my random hero might not be working and so it is, it spawns my unit called "random hero" without calling my hero randomization function which works when you buy it at tavern in way you know player does.

  • Random Hero
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • (Unit-type of (Sold unit)) Equal to Random Hero
    • Actions
      • Unit - Create 1 RANDOM_HERO_ARRAY[(Random integer number between 1 and NUM_HEROES)] for (Owner of (Sold unit)) at ((Owner of (Sold unit)) start location) facing Default building facing degrees
      • Hero - Create Scroll of Town portal and give it to (Last created unit)
      • Hero - Create Jaood's Amulet of Power and give it to (Last created unit)
      • Unit - Remove (Sold unit) from the game
But anyway you get some rep point from me ;) and I think it shall work if I just paste those actions into your trigger ;)



// EDIT

I changed trigger and now it works this way :

  • kupbohatera2
    • Events
      • Unit - A unit enters custom hero tavern2 <gen>
    • Conditions
      • ((Owner of (Triggering unit)) controller) Equal to Computer
    • Actions
      • Set TempInt = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AI_Order[TempInt] Equal to 1.00
          • ((Owner of (Triggering unit)) Current gold) Greater than or equal to 1700
        • Then - Actions
          • Unit - Create 1 RANDOM_HERO_ARRAY[(Random integer number between 1 and NUM_HEROES)] for Player 7 (Green) at (Player 7 (Green) start location) facing Default building facing degrees
          • Hero - Create Scroll of Town portal and give it to (Last created unit)
          • Hero - Create Jaood's Amulet of Power and give it to (Last created unit)
          • Player - Add -1700 to (Owner of (Triggering unit)) Current gold
        • Else - Actions
          • -------- ai wants to buy a hero although it does not have money --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • AI_Order[TempInt] Equal to 1.00
              • ((Owner of (Triggering unit)) Current gold) Less than 1700
            • Then - Actions
              • Set AI_Order[TempInt] = 2.00
            • Else - Actions
Anyway as you see it works only for Player 7 (Green) when I change it into Owner of Triggering unit it doesnt work for any player how it should do is there an easy way to make 1 trigger for all players or shall I copy and make such trigger for every single player ?
 
Level 10
Joined
Dec 15, 2012
Messages
650
Maybe the point leak ruins your trigger. Fix it ! Leaks make your game becomes laggy when they are getting many.
  • Enter Region Buy Hero
    • Events
      • Unit - A unit enters AI Buy Hero <gen>
    • Conditions
      • ((Owner of (Triggering unit)) controller) Equal to Computer
    • Actions
      • Set TempInt = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AI_Order[TempInt] Equal to 1.00
          • ((Owner of (Triggering unit)) Current gold) Greater than or equal to 1700
        • Then - Actions
          • Set TemporaryPoint = ((Owner of (Triggering unit)) start location)
          • Unit - Create 1 Blood Mage for (Owner of (Triggering unit)) at TemporaryPoint facing (Random angle) degrees
          • //You can create items for your computer's hero at here.
          • Player - Add -1700 to (Owner of (Triggering unit)) Current gold
          • Custom script: call RemoveLocation(udg_TemporaryPoint)
          • Custom script: set udg_TemporaryPoint = null
        • Else - Actions
          • -------- Not enough gold --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • AI_Order[TempInt] Equal to 1.00
              • ((Owner of (Triggering unit)) Current gold) Less than 1700
            • Then - Actions
              • Set AI_Order[TempInt] = 2.00
            • Else - Actions
              • Set TempInt = 0
View this for more information : http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/
 
Last edited:
Status
Not open for further replies.
Top