AI Chooses Heroes

sentrywiz

New Member
Reaction score
25
This is simple matter, as I already know you will be fighting who to answer first. However, when it comes to this let me explain it a bit.


If those of you who will answer, played Grand Battle (yeah, awesome map) know that the computer players choose heroes one computer each time. That all is basic math, but how do you tell:


1) A computer that the hero has already been chosen so that he needs to choose another? Is it something with Hero_Array[Some Number] Not Equal to True >then what?

2) Limit the heroes to only one unit-type of hero per team. This also means that players have in a way, two taverns to choose from but they can only choose from their own.
 

Jedi

New Member
Reaction score
63
I am not sure about what you mean(it seems others too :p)

Lets say you have 10 heroes.And HeroType is a unit-type variable with array.

HeroType[1] == ..
2
3
4
...

Maybe, when someone picked a hero, you can check with a loop which hero is it.Since you know jass, I will explain with it.
JASS:
//Our event is a unit sells a unit
local integer i = 1
local integer id = GetUnitTypeId(GetSoldUnit())
loop
    exitwhen i > 10
    if id == udg_HeroType<i> then
        set udg_HeroType<i> = 0 //Unit types are basically integers, this means set udg_HeroType<i> = null
    endif
    set i = i + 1
endloop
</i></i></i>


And when create a hero for AI,

JASS:
local integer unitId
loop
    set unitId = GetRandomInt(1, 10) //Random Int between Max herotype and min herotype number.
    if udg_HeroType[unitId] != 0 then //If This hero type not picked yet
        //Create a hero for AI
        set udg_HeroType[unitId] = 0 //Null this too, this hero is picked.
        exitwhen true //Finish the loop
    endif
endloop
 

sentrywiz

New Member
Reaction score
25
I've solved my first problem through trial and error. Cookie for me

The second problem still remains. How to check if a hero has been chosen. Just to explain a bit about my map:

-There is no tavern (players don't buy heroes)
-There are no dialogs
-There is click ->show hero information ; double click -> choose hero type of system. There are 12 hero units from which the players click/double click and that is how they choose their hero.
-For AI, there is only Hero_Array[Integer]. The system randomly selects a number between 1 and 12 and creates it for the AI.


Now I can say that I've seen in maps how when a player chooses a hero via the system explained above, the unit (probably) gets the locust ability and cannot be chosen. That is a good way to limit selection to one type of hero per team, but how do you make this for an AI? You can't force the AI to select a unit... can you?


@Thanks Jedi, but I am not a JASSer yet, I understand as much to not be stupid looking at it :p

I still appreciate if you could explain it with GUI.
 

LurkerAspect

Now officially a Super Lurker
Reaction score
118
Is your system like in quite a few modern AoS's where you have a ring of heroes and players choose from that? Just make so that in yours, everytime a hero is chosen, simply remove it from the ring. It wouldn't be too hard to make an AI do that, I think.

I would add your whole selection of heroes to a unit group, and then everytime a hero is chosen, remove him from that unit group. Then tell the AI to "buy" a random unit from that group (there is a GUI function for that). That way, it would be impossible for the AI (or anyone) to choose two of the same kind of hero. How about when someone chooses a hero, you make that demo hero belong to that player and then send it to the start of the game?

Just throwing out some ideas that might help here :)
 

sentrywiz

New Member
Reaction score
25
Yeah that's that. Here is an image of how that looks like...

Untitled.jpg


I am thinking of the same thing right now. Some way for the AI and the players to literally "fight" over picking the champions. The only problem is to make the AI double-click the hero. But that can be solved via pick all units in > unit group for team 1 and pick random unit, create 1 unit of the selected unit and remove the unit to prevent further activation.


Wait...

Did I just gave an answer to my own question? :D
 

sentrywiz

New Member
Reaction score
25
Yeah, I agree. I knew that through trial and error if I don't give up I will reach the solution. However thanks for the push and the idea, +rep

IT WORKS. Seriously it does. With one little setback...

The trigger that issues AI to pick a random unit causes all of them to pick the same hero. Hmm...

Here is the trigger to what AI picks units:

Trigger:
  • AI Creation
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players controlled by a Computer player) and do (Actions)
        • Loop - Actions
          • For each (Integer A) from 1 to 10, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Player[(Integer A)] is an ally of Player 11 (Dark Green)) Equal to True
                  • (Player[(Integer A)] controller) Equal to Computer
                • Then - Actions
                  • Unit Group - Pick every unit in BirajHeroi[1] and do (Actions)
                    • Loop - Actions
                      • Unit - Remove (Picked unit) from the game
                      • Unit - Create 1 (Unit-type of (Picked unit)) for Player[(Integer A)] at Fontana[1] facing Default building facing degrees
                      • Game - Display to (All players) the text: (PlayerColors[(Integer A)] + ((Name of Player[(Integer A)]) + (|r go odbra + (PlayerColors[(Integer A)] + (Name of (Picked unit))))))
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Player[(Integer A)] is an ally of Player 12 (Brown)) Equal to True
                      • (Player[(Integer A)] controller) Equal to Computer
                    • Then - Actions
                      • Unit Group - Pick every unit in BirajHeroi[2] and do (Actions)
                        • Loop - Actions
                          • Unit - Remove (Picked unit) from the game
                          • Unit - Create 1 (Unit-type of (Picked unit)) for Player[(Integer A)] at Fontana[2] facing Default building facing degrees
                          • Game - Display to (All players) the text: (PlayerColors[(Integer A)] + ((Name of Player[(Integer A)]) + (|r go odbra + (PlayerColors[(Integer A)] + (Name of (Picked unit))))))
                    • Else - Actions
          • Custom script: call RemoveLocation(udg_Fontana[2])
          • Custom script: call RemoveLocation(udg_Fontana[1])


BirajHeroi[1],BirajHeroi[2] is the unit group that is set to: Random 1 Units from Team 1/2 Region
PlayerColors is string array for setting of colors.
Player is a player array for players 1-10
Fontana[1], Fontana[2] is point array for team 1/2 spawn points


In game there are two problems:

-Computers pick same hero
-Game message runs 4 times for one player.. like the player chose the unit 4 times, even though only 1 unit was created
 

LurkerAspect

Now officially a Super Lurker
Reaction score
118
Hmm, as for getting your message 4 times per hero, check all your loops, because there are a couple of loops that pick every unit in a group and then play a message, so that could be where that problem is coming from.

As for everyone picking the same hero first up, you don't seem to be removing your random selection from the original pool of heroes (not that I can see.)

I think using so many group variables is your problem with this trigger.

This is what I was thinking:
Trigger:
  • AI Choose Hero
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Set Hero_Pool = (Units in HeroPool &lt;gen&gt;)
      • 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))) controller) Equal to Computer
            • Then - Actions
              • Set Temp_Unit = (Random unit from Hero_Pool)
              • Unit Group - Remove Temp_Unit from Hero_Pool
              • Unit - Change ownership of Temp_Unit to (Player((Integer A))) and Change color
              • If (((Player((Integer A))) is an ally of Player 12 (Brown)) Equal to True) then do (Unit - Move Temp_Unit instantly to Fontana[1]) else do (Unit - Move Temp_Unit instantly to Fontana[2])
              • Game - Display to (All players) the text: &lt;whatever you had e...
            • Else - Actions
              • Do nothing
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top