Skip to content

EUD Tutorial: How to make units other than spellcasters cast spells

Ar3sgice edited this page Sep 23, 2020 · 12 revisions

First of all

Add spell buttons and requirements for that unit. Of course, there are other tutorials about this, so you already knew how to do this.

What you don't know is how to get a unit that originally cannot cast spells to do it.

The Problem

Units other than traditional spellcasters have no castspell animation. Most of the spells require a castspell animation to cast successfully, more specifically, an opcode 0x27 castspell in their animation +7 CastSpell.

Spells that do not require this animation

Some of the spells don't require this animation, and can be added to all units with no problem. These include:

  • Stim Packs
  • Spider Mines
  • Scanner Sweep
  • Defensive Matrix (it uses its own animation)
  • Recall
  • I think there is more but haven't tested all

Iscript Index

Since the problem is having no animation, we can change unit graphics to spellcasters having the animations... but that's certainly not the solution we want.

We want them to keep their original unit models, while somehow getting an animation they don't have.

Changing the Iscript Index in images.dat can help with this. It makes the unit (or any other image) use the iscripts (image scripts) for another unit, while keeping their own unit model.

Picking Iscripts

Iscript indices that have an castspell animation include:

  • Defiler #9
  • Infested Kerrigan #20
  • Queen #27
  • Ghost #70
  • Sarah Kerrigan #77
  • Spider Mines #87
  • Science Vessel #88
  • Nuclear Missile #131
  • Arbiter #146
  • Dark Templar Hero #152
  • High Templar #158
  • Yamato Overlay #314 (Image overlay called by Battlecruiser #66)
  • Medic #360
  • Dark Archon #365
  • Corsair #369
  • Dark Templar Unit #372

Some of these are not suitable for iscript swapping. Defiler crashes the game when used on other units (needs .Lo* file?); Spider Mines and Nuclear Missile are obviously not good picks.

Ghost, Kerrigan and Infested Kerrigan have animations that play very late frames (up to frameset 13-15). This usually results in images being perodically removed when walking, which isn't a very nice thing to happen on your spellcaster. Ghost script works for some units though, for example Hydralisk and Scantid (the Desert critter).

Dark Archon and Science Vessel will add extra images (archon beings/swirls, science vessel turret) to your unit. This can be worked around by making the extra images invisible using drawing functions, but in that case the original unit will be affected.

Lastly, you will usually want your spellcaster to attack. Medic and Science Vessel cannot attack.

The other units left are pretty useful. No one of them is perfect for this use, each one has its merits and demerits.

Usable iscript IDs:

  • High/Dark Templar: Can only attack ground. I think Dark Templar has castspell because of Dark Archon Merge.
  • Queen: Can attack all. Has an animated idle state/walking script which looks nice on some units.
  • Arbiter/Corsair: Can attack all. Low frame count works for almost every unit; has engine overlays which can be removed via Drawing Function.
  • Battlecruiser: Can attack all. Has a charging process when casting any spell; sometimes that's exactly what we want.
  • Ghost: Can attack all. Only for units with high frame counts (Zerg usually has more than Protoss)
  • Dark Archon: Can attack all. Adds archon swirl and being, which can be removed via Drawing Function, or sometimes that's what we want.

Using the Attack Animation with CUnit/Orders

In Order.dat, the animation for spellcasting can be edited for each spell. Usually setting it to anything other than CastSpell will cause the spell to fail, but if set to GroundAttackInit, AirAttackInit, GroundAttackRpt or AirAttackRpt, the unit will use weapons instead of spells.

Note: Currently I think that value is broken in EUD Editor 3's Data Editor.

After that, There is a spellCooldown value in each unit's CUnit section. It is possible to detect the cooldown and change the weapon of the unit to one that casts spells.

This EUD Editor 3 triggers should show how to do this clearly.

The spellCooldown values in the code need to be nudged carefully. It must set the weapon before the animation uses the weapon, then reset the weapon before the unit can use a second one.

The downside of this is that the spell cannot be casted to the ground, since units cannot attack ground. The Use Weapon Targeting flag can be used to help with this, as shown in the triggers.