# [AI]What's worng with my AI triggers? +Rep

#### shinji

Level 14
I'm making an AI for my map. They move fine but they don't shoot. I made them press hot keys to shoot but they don't shoot please help me.
• AI target move
• Events
• Time - Every 5.00 seconds of game time
• 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
• And - All (Conditions) are true
• Conditions
• AITarget[(Integer A)] Equal to No unit
• ((Owner of Player[(Integer A)]) slot status) Equal to Is unused
• Then - Actions
• Set AITarget[(Integer A)] = Player[(Random integer number between 1 and 12)]
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• ((Owner of Player[(Integer A)]) slot status) Equal to Is unused
• Then - Actions
• Set TP[16] = (Position of AITarget[(Integer A)])
• Unit - Order Player[(Integer A)] to Move To TP[16]
• Custom script: call RemoveLocation(udg_TP[16])
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• ((Owner of Player[(Integer A)]) slot status) Equal to Is unused
• Then - Actions
• Set TP[18] = (Position of Player[(Integer A)])
• Set TG4 = (Units within 1100.00 of TP[18])
• Custom script: call RemoveLocation(udg_TP[18])
• Unit Group - Pick every unit in TG4 and do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• And - All (Conditions) are true
• Conditions
• ((Owner of (Picked unit)) is an enemy of (Owner of Player[(Integer A)])) Equal to True
• Or - Any (Conditions) are true
• Conditions
• (Unit-type of (Picked unit)) Not equal to Bullet
• (Unit-type of (Picked unit)) Not equal to Rocket
• Then - Actions
• Unit - Order Player[(Integer A)] to Stop
• Set AITarget[(Player number of (Owner of Player[(Integer A)]))] = Player[(Player number of (Owner of (Picked unit)))]
• Set TP[18] = (Position of Player[(Player number of (Owner of (Picked unit)))])
• Unit - Make Player[(Integer A)] face TP[18] over 0.00 seconds
• Custom script: call RemoveLocation(udg_TP[18])
• Wait 1.00 seconds
• Game - Force (Owner of Player[(Integer A)]) to press the key Z
• Wait 1.00 seconds
• Game - Force (Owner of Player[(Integer A)]) to press the key X
• Wait 1.00 seconds
• Game - Force (Owner of Player[(Integer A)]) to press the key C
• Else - Actions
• Custom script: call DestroyGroup(udg_TG4)
• Else - Actions
• AI Shoot
• Events
• Unit - A unit Is attacked
• Conditions
• ((Owner of (Triggering unit)) slot status) Equal to Is unused
• Actions
• Unit - Order Player[(Player number of (Owner of (Triggering unit)))] to Stop
• Set AITarget[(Player number of (Owner of (Triggering unit)))] = Player[(Player number of (Owner of (Attacking unit)))]
• Set TP[17] = (Position of Player[(Player number of (Owner of (Attacking unit)))])
• Unit - Make (Triggering unit) face TP[17] over 0.00 seconds
• Custom script: call RemoveLocation(udg_TP[17])
• Wait 1.00 seconds
• Game - Force (Owner of (Triggering unit)) to press the key Z
• Wait 1.00 seconds
• Game - Force (Owner of (Triggering unit)) to press the key X
• Wait 1.00 seconds
• Game - Force (Owner of (Triggering unit)) to press the key C

#### Magtheridon96

Level 36
It's not working because the AI isn't going to be selecting the unit
Pressing the Hotkey isn't going to work, so you're going to have to order the unit to cast the spells.
OR, just clear the selection of the AI player, then make him select the hero so you can use the Hotkey method.

#### shinji

Level 14
It's not working because the AI isn't going to be selecting the unit
Pressing the Hotkey isn't going to work, so you're going to have to order the unit to cast the spells.
OR, just clear the selection of the AI player, then make him select the hero so you can use the Hotkey method.

OK. I'll try that.

EDIT : Still doesn't work. Any ideas?

#### Cokemonkey11

Code Reviewer
Level 29
((Owner of Player[(Integer A)]) slot status) Equal to Is unused

This not what you want. You want to check that the player controller is a computer.

Slot status is unused means that the player slot (like Player(2)) does not have any other state (like SLOT_STATE_PLAYING)

This is a bit advanced because I didn't learn how to do this until I learned jass, so if someone could tell you the GUI equivalent that would be helpful.

#### shinji

Level 14
((Owner of Player[(Integer A)]) slot status) Equal to Is unused

This not what you want. You want to check that the player controller is a computer.

Slot status is unused means that the player slot (like Player(2)) does not have any other state (like SLOT_STATE_PLAYING)

This is a bit advanced because I didn't learn how to do this until I learned jass, so if someone could tell you the GUI equivalent that would be helpful.

I wanted it to be unused. Did you know that if you set it to computer, it will automatically use items and go back to base? I didn't want that so I'll leave a player slot open to make this work...

#### Cokemonkey11

Code Reviewer
Level 29
Set the trigger up to order the units to cast the spells as maggie said. If it's still not working, post it here in trigger tags.

#### shinji

Level 14
Set the trigger up to order the units to cast the spells as maggie said. If it's still not working, post it here in trigger tags.

Hmm... Still doesn't work. They shoot sometimes but... They are too stupid...

#### shinji

Level 14
Tags? If you mean the trigger, I have posted it above. I need them to face the target and then cast the skill. (Because it only damages unit in front. Plus the unit doesn't have an attack.)

#### Cokemonkey11

Code Reviewer
Level 29
Set the trigger up to order the units to cast the spells as maggie said. If it's still not working, post it here in trigger tags.

post the trigger in trigger tags, after you've set it up to order the units to cast the spells like maggie said

#### shinji

Level 14
Oh. Ok. But I'm not home right now. Maybe later. (I'm using my iPhone right now)

EDIT : I was testing somethings. I finally made it work. +Rep to you.

Last edited:

Replies
3
Views
422
Replies
8
Views
579
Replies
6
Views
557
Replies
15
Views
621
Replies
5
Views
634