Currently, if you want to spawn a missile, there are 2 ways to do it:
- Create a custom dummy ability, which spawn a missile, and whenever you need to spawn one, create the dummy, give it the ability and make it cast it.
pros:
- it’s fairly simple to do it.
cons:
- most of the abilities, that spawn missiles have extra effects, such as stuns. Setting the stun duration in the editor to 0 does NOT remove the stun completely, so these missiles will always have an unwanted mini-stun.
- if you want to create an ability with a custom effect, the ONLY viable ability you can use is Acid Bomb, as it applies a custom buff, and it doesn’t have a stun. You need to detect when a unit takes damage, and check if it has this buff to know if the damage was from the missile you created. Then you also need to remove the buff, so it doesn’t trigger from other sources of damage, and then apply whatever you want.
Tracking the damage source and their stats and stuff can be a bit difficult this way, as you need to keep the dummy alive longer, and save stuff related to the actual caster in variables, that can be retrieved from the dummy (either hashtable, either using custom indexing)
It’s no longer that simple, and Acid Bomb being the only ability that can be used for missiles with custom effects is extremely inconvenient.
- Use custom missile systems/libraries.
pros:
- you can do almost everything you may want with these.
cons:
- it’s heavier performance-wise. Especially if a big amount of missiles are being managed at the same time.
People using the editor know that native functions are faster than custom made ones. So it’d be nice if we get native functions to spawn and manage these missiles.
After thinking about it a bit more, it seems like the best way to apply them would be something like this:
- missile UnitSpawnMissile(unit shooter, unit target, string art, real speed, real arc, boolean homing)
- missile SpawnMissile(string art, real spawnX, real spawnY, real spawnZ, real speed, real targetX, real targetY, real targetZ, real arc)
- missile SpawnUnitMissile(string art, real spawnX, real spawnY, real spawnZ, unit target, real speed, real arc, boolean homing)
And there should also be functions such as:
- MissileAddDamage(missile missile, real damage, real AoE, attackType aType, damageType dType)
- MissileAddOnHit(missile missile, real radius, code calledFunction)
NOTE: as I see it, this should trigger whenever the missile comes in contact with a unit, and not only when it hits its target. For ONLY hitting the target, the next one should be used:
- MissileAddOnDestinationReach(missile missile, code calledFunction)
And then we should also have some natives such as:
- missile GetTriggerMissile()
- integer GetMissileId(missile missile)
- unit GetMissileShooter(missile missile)
- unit GetMissileTarget(missile missile)
- real GetMissileX(missile missile)
- real GetMissileY(missile missile)
- real GetMissileZ(missile missile)
- real GetMissileOrientation(missile missile)
- SetMissileSpeed(missile missile, real speed)
- DestroyMissile(missile missile)
- SetMissileTarget(missile missile, unit target)
- SetMissileDestination(missile missile, real targetX, real targetY, real targetZ)
With these you can do some good stuff like making a missile switch its target mid-flight. Like you can shoot a missile in a general direction, and if it gets near an enemy - home into them.
And tons of other stuff.
And, along with these, we also really need an “Attack is Launched” event. Since, if we want to spawn multiple custom missiles when a unit attacks, currently there is only 1 semi-viable way to do it:
- set the unit’s weapon type to be instant
- give the unit a passive ability, that prevents it from missing (based on critical strike), as missing its target will cause the attack to not do anything at all.
- make an event to detect when a unit takes damage, and use as conditions "the shooter has the custom anti-miss ability)
- set as actions “set the event damage to 0” and spawn your custom missiles.
I admit it was a lot harder before we got the native “set event damage to 0”, as we also needed several rows of code, as well as a timer, that expires after 0 seconds (next frame), which was quite clunky.
But with the event “Attack is Launched”, we can:
- skip steps 1 and 2
- make it work for ANY unit, in a lot more situations
- make it less prone to bugs