How to make enemy pc hero cast spell?

Level 5
Aug 12, 2010
cant find event that is good enought to make enemy cast spell like storm bolt and triggers make it to kamehame, if i do "unit is attacked" event then songoku must come close and then use kamehame that is total nonsence cuz kamehame is ranged skill, if i do every 1 sec pick random unit within range and then cast spell then the situation is this: songoku is fighting players 1,2,3 hes attacking player 1 but random enemy for spell will be other then he is curently attacking or chasing so how to make ?or i just make spell from autocast spell the i dont need triggers at all?


Code Reviewer
Level 26
Mar 19, 2008
Quoting myself makes me confused sometimes by whatever. Btw you should use search engine, there were tons of such issues already.

You have to trigger it.
What's the spell you have based your custom one on?
If its normal ladder skill you can refer to it via actions. Lets say it's custom chain lightning.
  • Unit - Order Yourunit to Orc - Far Seer: Chain Lightning YourTarget
There are 3 types of actions Unit - Issued an order:
- no target
- target object (one for unit, one for destructible, one for item)
- target location

Find the one you need in Unit section in Actions and from filter select the 'base' ability.

If your spell isn't ladder one (egzample channel) you can always use:
// For location
native IssuePointOrder              takes unit whichUnit, string order, real x, real y returns boolean
// Target
native IssueTargetOrder             takes unit whichUnit, string order, widget targetWidget returns boolean
// No target
native IssueImmediateOrder          takes unit whichUnit, string order returns boolean
Ofcourse you can write it with custom scripts in GUI - don't worry.
There is also alternative: you can always replace those functions with 'ById' ones - so instead of 'string' (order egzample: "thunderbolt") you can write the Id (integer number) of given order.
native IssueTargetOrderById         takes unit whichUnit, integer order, widget targetWidget returns boolean
As you see, instead of 'string' function requires integer variable. If you gonna follow that method this will be usefull for you.

With that knowledge you should be able to order CPU to cast any spell.
This tutorial can be useful as well.
Level 5
Aug 12, 2010
I know Action, i need Event and Conditions to use spell on specific unit enemy pc is chasing trying to get close to attack. "Aquares an enemy" lol there is no event but i want that.

and i cant understand yout Jass

Eh i'll just use autocastable abilities so even mindless pc can cast it, but i unit can use only 1 autocast so i'll just make much work and add/remove abilities every 1 sec haha so much lagg...
Last edited:
Level 10
Jun 6, 2007
If it's a melee map, computer will use spells as it would use their base abilities. For that spell, shockwave might work best. If you really want to trigger it, you could use a periodic event. Add all units who need to use spells (for example all units trained by computer) to a unit group. Then pick all unit's in that group every second, and check if the number of enemies within x range > 0. This solution might cause lag though. If it's possible to do it by using melee AI, then I suggest you to do so.
This link might be useful.