HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Tower(Defense) Autocast Tutorial (GUI)

10-26-2007, 04:30 PM#1
SkriK
I came across the problem myself and i searched the forum for a tut, but couldn't find any. I also noticed that many others had asked the question aswell. So i experimented a bit and came up with a simple solution.
I haven't encountered any problems using this type of triggering, but if you do, please tell.

I am not too confident about my skills of explanation, so if you need something cleared out, just ask.

You can base a spell of any that exists in the editor. Since they all have unique Order Strings.
The only thing you have to think about, is what Order String the ability has.

======================================

Spell Based On Point Target
If you want a point-based spell, such as Shockwave, Carrion Swarm and Crushing Wave, make your spell based on either of them.
In this case, I'll use Shockwave.

Now look at what Order String it has:
Zoom (requires log in)
To make it auto-cast, you WILL need a trigger, but not in JASS.

Example Trigger:
Trigger:
Collapse Events
Unit - A unit Is attacked
Collapse Conditions
(Unit-type of (Attacking unit)) Equal to Shockwaver
Collapse Actions
Set TargetPoint = Position of (Attacked Unit)
Unit - Order (Attacking unit) to Orc Tauren Chieftain - Shockwave (TargetPoint)
Custom script: call RemoveLocation(udg_TargetPoint)
Custom script: set udg_TargetPoint = null
Copy this text to put in your custom scripts:
call RemoveLocation(udg_TargetPoint)
set udg_TargetPoint = null

This will make the Attacking unit cast any spell with the Order String: "shockwave" on the Attacked unit.
This also works for point-target AOE spells, just use matching order strings to make it work.

Here's a custom spell i made with shockwave as Order String.
Zoom (requires log in)

======================================

Spell Based On Unit Target
Using this, you can make any single target spell autocast. Just make sure the spell is based on a Unit Target spell. I'm gonna use Storm Bolt.

Order String:
Zoom (requires log in)

Trigger: (Try making it by yourself before checking.)
Hidden information:
Trigger:
Collapse Events
Unit - A unit Is attacked
Collapse Conditions
(Unit-type of (Attacking unit)) Equal to Caster
Collapse Actions
Set TargetPoint = Position of (Attacked Unit)
Unit - Order (Attacking unit) to Human Mountain King - Storm Bolt (TargetPoint)
Custom script: call RemoveLocation(udg_TargetPoint)
Custom script: set udg_TargetPoint = null

This will make the Attacking unit cast any spell with the Order String: "thunderbolt" on the Attacked unit.

Another custom spell:
Zoom (requires log in)

======================================

Hope this is of any use. Regards, -SkriK
Attached Images
File type: gifUntitled-2.gif (2.1 KB)
File type: gifUntitled-3.gif (2.3 KB)
File type: gifUntitled-4.gif (2.1 KB)
File type: gifUntitled-5.gif (2.3 KB)
10-26-2007, 06:21 PM#2
aaero
I think your explanation is pretty clear, except I don't think your tutorial title is especially fitting. Autocast to me is Blizzard's autocast functionality for spells. Your method casts spells on attack.

The primary thing you'll have to fix, though, is that you have memory leaks :/. Normally, I think people can be a little overly picky about leaks, but this is an obviously troublesome leak that will eventually cause large problems - you'll want to fix it.

To do that in GUI, you can clean them up using global variables and custom script.

Somehow I'm still not 100% on what causes leaks (I'm not sure if you're leaking units or just locations), so I think someone more knowledgeable will come by with that. As an example of how to remove the location leak -

New Global - TargetLocation (Type Location)


Trigger:
Collapse Events
Unit - A unit Is attacked
Collapse Conditions
(Unit-type of (Attacking unit)) Equal to Shockwaver
Collapse Actions
Set TargetLocation = Position of (Attacked Unit)
Unit - Order (Attacking unit) to Orc Tauren Chieftain - Shockwave (TargetLocation)
Custom Script: call RemoveLocation(udg_TargetLocation)
Custom Script: set udg_TargetLocation = null

What you're doing there is cleaning up the code to make up for a mistake in the World Editor. It's complicated, but when you have a function running this often you don't want leaks.
10-26-2007, 06:31 PM#3
SkriK
Cheers man, i'm don't have any knowledge of leaks at all. Thanks for pointing it out.
Btw, the Custom Scripts' a must have?
10-26-2007, 06:43 PM#4
Castlemaster
Just the one custom script. Newbies can copy/paste it.
10-26-2007, 06:44 PM#5
aaero
I wish they weren't necessary, because I know how confusing they can be when you're not used to looking at them. Unfortunately, Blizzard didn't include any of that kind of clean up for locations in the GUI editor, so you're forced to use custom script.
10-26-2007, 07:11 PM#6
Silvenon
Trigger:
Custom Script: set udg_TargetLocation = null

Wtf??? No no.....nulling globals isn't necessary, that isn't considered as a leak :)
10-27-2007, 06:34 PM#7
aaero
Silvenon is correct - no need for that final custom script line. Oops!