Hi guys, I'm delving into my first attempt with an AI and hoping for a little bit of help.
I have a grid of rooms in a square, which players can claim/control by walking a unit to the center so long no other enemy units are alive in that room. What I'd like to do is get empty player slots/computer players a bit involved in the game.
Every 20 seconds I'd like to make computer owned units in each room to attack move in a random direction around to the nearest room they do not control.
The easiest way I thought would be to put the rooms in to an array, then group units per room and check +X / -X rooms away until I find an empty one and gogo?
I'm not quite sure how to build a loop to run through each room thou and at the same time connect the lowest array room with the highest to form a full 'circle'.
Controlling a region means you have the most amount of units in that region right?
So basically you have a trigger set up for each player so that if a unit enters Room A, it's added to that players Node 1 control group. So "Player 1 Room A" variable as a unit group.
Another trigger is If a unit leaves the node, it's taken out of the unit group.
If a unit dies, it's taken out of the unit group. So you have a variable group for each player holding all the live units for that player inside the Room A.
Then you have 3 more triggers. One trigger set for if any unit dies, another for if any unit enters Room A, and another trigger that if any unit leaves. These three triggers all trigger a comparison trigger each individual player. 4 players, 4 triggers.
The comparison trigger compares units in the player's control group, to the number of living units in the "Room A Controller group"
If the numbers are higher than the Room A Controller group, then remove all units from from Room A Controller group, then pick all units from that player's control group and add all those units to Room A Controller group.
The AI timer will give the AI an order. Separate trigger.
The way you do AI is you have AI Timer expires as an event. For each player you have a AI trigger
Comparison. Owner of (unit 1 from Room A Controller group)) != 2
Controller of Player 2 = computer
Issue order to unit in unit group any unit in entire map owned by player 2, to attack center of Room A.
So with that, you have a trigger for each player keeping track of how it's doing in the region. You have a trigger working out who is doing the best in the region. You have another trigger working out when to issue orders. Then you have a trigger for each player working out if that player is the one who gets the orders.
But that AI will always attack in 1 order. You can randomize the order with If then else commands.
So AI timer expires
Set AI variable = Random integer
If owner of unit in unit group Room A Controller != Player 2
And AI Variable = 1
Then Issue order to unit in unit group any unit in entire map owned by player 2, to attack center of Room A.
Else
If owner of unit in unit group Room B Controller != Player 2
And AI Variable = 2
Then Issue order to unit in unit group any unit in entire map owned by player 2, to attack center of Room A.
Else
etc
So that you are checking if player 2 owns it, and if it's randomly picked for attack, then attack it.
You would need a quick timer to check every half a second or so though because there may be like 30 times where they integer doesn't link up with the last room it has to attack.
It's easier to just have
AI timer expires
Set AI variable = Random integer
Pick unit in unit group any unit set to alliance enemy with by player 2
And picked unit to "enemy group"
Issue order to unit in unit group any in entire map owned by player 2, to attack random unit from "Enemy group".
Check out my map if you want to see what I did.
Adrenaline Rush Elite
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hi guys, I'm delving into my first attempt with an AI and hoping for a little bit of help.
I have a grid of rooms in a square, which players can claim/control by walking a unit to the center so long no other enemy units are alive in that room. What I'd like to do is get empty player slots/computer players a bit involved in the game.
Every 20 seconds I'd like to make computer owned units in each room to attack move in a random direction around to the nearest room they do not control.
The easiest way I thought would be to put the rooms in to an array, then group units per room and check +X / -X rooms away until I find an empty one and gogo?
I'm not quite sure how to build a loop to run through each room thou and at the same time connect the lowest array room with the highest to form a full 'circle'.
Ok really you need to set up multiple triggers.
Controlling a region means you have the most amount of units in that region right?
So basically you have a trigger set up for each player so that if a unit enters Room A, it's added to that players Node 1 control group. So "Player 1 Room A" variable as a unit group.
Another trigger is If a unit leaves the node, it's taken out of the unit group.
If a unit dies, it's taken out of the unit group. So you have a variable group for each player holding all the live units for that player inside the Room A.
Then you have 3 more triggers. One trigger set for if any unit dies, another for if any unit enters Room A, and another trigger that if any unit leaves. These three triggers all trigger a comparison trigger each individual player. 4 players, 4 triggers.
The comparison trigger compares units in the player's control group, to the number of living units in the "Room A Controller group"
If the numbers are higher than the Room A Controller group, then remove all units from from Room A Controller group, then pick all units from that player's control group and add all those units to Room A Controller group.
The AI timer will give the AI an order. Separate trigger.
The way you do AI is you have AI Timer expires as an event. For each player you have a AI trigger
Comparison. Owner of (unit 1 from Room A Controller group)) != 2 Controller of Player 2 = computer Issue order to unit in unit group any unit in entire map owned by player 2, to attack center of Room A.
So with that, you have a trigger for each player keeping track of how it's doing in the region. You have a trigger working out who is doing the best in the region. You have another trigger working out when to issue orders. Then you have a trigger for each player working out if that player is the one who gets the orders.
But that AI will always attack in 1 order. You can randomize the order with If then else commands.
So AI timer expires
Set AI variable = Random integer
If owner of unit in unit group Room A Controller != Player 2 And AI Variable = 1 Then Issue order to unit in unit group any unit in entire map owned by player 2, to attack center of Room A. Else If owner of unit in unit group Room B Controller != Player 2 And AI Variable = 2 Then Issue order to unit in unit group any unit in entire map owned by player 2, to attack center of Room A. Else etc
So that you are checking if player 2 owns it, and if it's randomly picked for attack, then attack it.
You would need a quick timer to check every half a second or so though because there may be like 30 times where they integer doesn't link up with the last room it has to attack.
It's easier to just have AI timer expires
Set AI variable = Random integer
Pick unit in unit group any unit set to alliance enemy with by player 2 And picked unit to "enemy group" Issue order to unit in unit group any in entire map owned by player 2, to attack random unit from "Enemy group".
Check out my map if you want to see what I did.
Adrenaline Rush Elite