• 🏆 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] Need help - AI

Status
Not open for further replies.
Level 2
Joined
May 1, 2008
Messages
9
I kind of need help creating an AI for a custom map. I want the AI just to order all his unit to attack and like just order them to attack them, but i dont want like a certain type of unit dead i want the whole group dead. (Something like NOTD AI)
 
Level 14
Joined
Apr 21, 2007
Messages
1,465
If I understand correctly you want the computer to attack all units owned by the player. All you really need to do is make a trigger that goes something like this:

Code:
Event - Unit - A unit comes within 3000.00 of COMPUTER
Condition - (Owner of (Triggering unit)) Equal to Player 1 (Red)
Action - Unit Group - Pick every unit in (Units owned by Player 12 (Brown)) and do (Unit - Order (Picked unit) to Attack-Move To (Position of (Triggering unit)))

Note that player 1(red) is the user and player 12(brown) is the computer. Also note that COMPUTER is the main base of the AI(It can be a castle, tower, unit, whatever you like).


You could also add a periodic trigger that would make the AI run his forces back to the base:

Code:
Event - Time - Every 60 seconds
Condition - /
Action - Unit Group - Pick every unit in (Units owned by Player 12 (Brown)) and do (Unit - Order (Picked unit) to Attack-Move To COMPUTER)

However if you merly want the player to be attacked when he enters a specific region(say as an ambush) you could do this:

Code:
Event - Unit - Enters Region AMBUSH
Condition - (Owner of (Triggering unit)) Equal to Player 1 (Red)
Action - Unit Group - Pick every unit in (Units owned by Player 12 (Brown)) and do (Unit - Order (Picked unit) to Attack-Move To AMBUSH)
 
Level 2
Joined
May 1, 2008
Messages
9
Wait, i am making a map which involves no base for computer but just a spawn, and i want the cpu just to order all the units that spawns to attack the players(Multiple players). I am sorry if i sort of exampled it wrong.
 
Last edited:
Level 2
Joined
Apr 25, 2008
Messages
17
assuming u want monsters to spawn every few seconds.
and sends the units to attack player 1
  • Spawn Monsters
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
      • (Player 12 (Brown) controller) Equal to Computer
    • Actions
      • Unit - Create 5 Ghoul for Player 12 (Brown) at (Random point in (Playable map area)) facing (Random point in (Playable map area))
      • Unit Group - Pick every unit in (Units owned by Player 12 (Brown)) and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack (Random unit from (Units owned by Player 1 (Red)))
The event - obvious ... every 5 seconds
the Condition - is that player 12 (or AI player) is a computer player
Actions
- Create 5 Ghouls for AI player at a random point on the playable map facing a random point on the map
- This you can change where you want the ghouls to spawn, change the unit spawned ie ghoul to maybe footman, and the number of ghouls spawned

Then the unit group - pick every unit
- This picks every unit owned by player 12 <-- so all the ghouls that spawned and make them do something
-- in this case set the picked ghouls to attack a unit owned by player 1


*this is just a quick example, you can figure the rest out yourself hopefully. Im not too good with GUI but i can write you the JASS if need be. Good luck :D
 
Level 2
Joined
May 1, 2008
Messages
9
I tried both ways and i dont really think event range really works and every 5 secs isnt what i am looking for, i know i can change it but i dont know what to change the event to. Thats my problem now.. i can get it to move and attack but it wont work without a proper event. If you need more detail on what event i am looking for, its like i want the computer to follow the player units around i dont give a crap if they cant catch up but its the following and just heading towards them and attack-move(Enemy player units will move around randomly too)
 
Level 14
Joined
Apr 21, 2007
Messages
1,465
Ok listen, here is how my trigger works and it does work. Assuming you have a barracks that spawns units for the CPU I will make the CPU attack you if you come close to his BARRACKS.

So just add the Event - Unit - A unit comes within 3000.00 of Barracks 0001 <gen>

I tryed it and it works, just use my previous condition and action.
 
Level 2
Joined
Apr 25, 2008
Messages
17
i dont get what you want ... so basically you want the units to spawn right? <-- that is done ... and you want the units to attack move player right ... <-- that is done. I tested that code and it works .... so what is the problem? Both triggers only make them attack player 1 (red) but if you want them to attack all enemies of player 12 you will have to use forces.

I have uploaded the test map.. and in this 5 foot men spawn every 5 seconds in a random place then all foot men are ordered to attack move player1 until he is dead or you lag to death.

I played NOTD and it seems all it does is this ... spawn units in random places and get them to attack the players.
 

Attachments

  • test.w3x
    16.5 KB · Views: 40
Level 5
Joined
Oct 27, 2007
Messages
158
Okay that works but it will only chase red, what if red dies? How will it go after the other players?

At map init you check with GetPlayerSlotState what possibly targets there are for the AI.

With the EVENT_PLAYER _LEAVE event you remove players from the possible targets.

If the player left you can simply pick a new target for the AI from the target players that are still left in the game.
 
Level 2
Joined
May 1, 2008
Messages
9
Can you like make an example of some sort? Cuz i know what ur saying but i just dont know where all the right triggers are
 
Level 2
Joined
Apr 25, 2008
Messages
17
  • Untitled Trigger 002
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set playerGroup = (Create Unit Group)
      • Player Group - Pick every player in (All players controlled by a User player) and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units owned by (Picked player)) and do (Actions)
            • Loop - Actions
              • Unit Group - Add (Picked unit) to playerGroup
on map init, a unit group is created. This group contains all the units owned by any player that is not AI. *Please have a look, research about what was done. This stuff is useful, took me a while to understand too*

Now that a group of units owned by anything that is not Player 12(AI) is created we can do the next part which is the same

  • Untitled Trigger 001
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
      • (Player 12 (Brown) controller) Equal to (==) Computer
    • Actions
      • Unit - Create 1 Ghoul for Player 12 (Brown) at (Random point in (Playable map area)) facing (Random point in (Playable map area))
      • Unit Group - Pick every unit in (Units in (Playable map area) owned by Player 12 (Brown)) and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack (Random unit from playerGroup)
This trigger is exactly the same as the trigger i gave you previously, with a few changed.

The Most important part is Unit - Order (Picked unit) to Attack (Random unit from playerGroup). This orders the unit (ghoul) to attack a random player who is in the created group of units owned by players (playerGroup)

If you need to deal with players leaving and not have that player's unit part of the unit group you will need to add an event when player leaves, create another unit group containing units owned by players.

You might also need to add an event when unit dies, as the ghouls may attack a dead players unit as it is still in the player group. hmm but experiment and try it out.
 
Status
Not open for further replies.
Top