• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Spell targeting for both units and points

Status
Not open for further replies.
Level 1
Joined
Mar 15, 2021
Messages
3
Is there any way to have create a point targeted ability, shockwave for example, and then detect whether that ability was cast on a point or on a unit?
I am creating a system where you carry some kind of gun, and when you fire at a point you will fire a volley of 6 or so "shockwave" like projectiles with some amount of random scattering for recoil. However if possible I would like to implement so that if a unit was targeted with the original spell, that unit would be stored in a variable then as the casting unit could sort of track the target unit as they fired the volley. I was hoping that it would just work, but when I use the below point targeted spell on a unit, GetSpellTargetUnit() is returning null. I'm new to JASS so feel free to roast me on anything I'm doing poorly too.

JASS:
library SpellSystem

    globals
        private integer SPELL_ID = 'A000'
    endglobals

    function SpellStart takes nothing returns integer
        local integer spellId = GetSpellAbilityId()
        local player castingPlayer = GetTriggerPlayer()
        local unit casterUnit = GetTriggerUnit()
        local unit targetUnit = GetSpellTargetUnit()
        local real targetX = GetSpellTargetX()
        local real targetY = GetSpellTargetY()
   
        if (spellId == SPELL_ID) then
            call BJDebugMsg("Player     : " + I2S(GetPlayerId(castingPlayer)))
            call BJDebugMsg("Spell fired: " + I2S(spellId))
            call BJDebugMsg("Caster Unit: " + I2S(GetUnitTypeId(casterUnit)))
            call BJDebugMsg("Target Unit: " + I2S(GetUnitTypeId(targetUnit)))        //This outputs: "Target Unit: 0"
            call BJDebugMsg("Target Loc:  " + R2S(targetX) + ", " + R2S(targetY))
        endif

        return spellId
    endfunction

    function InitTrig_SpellSystem takes nothing returns nothing
        local trigger SpellSystem = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(SpellSystem, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddAction(SpellSystem, function SpellStart)
    endfunction

endlibrary
 
Last edited:
Level 1
Joined
Mar 15, 2021
Messages
3
So I've actually solved the problem, If you actually use shockwave it does just work, mine didn't because I was using channel with the target type set to point target. With my map I can actually get away with using shockwave to trigger the spell effect but I will look to see if there is a way to have it function using channel.
 
Level 13
Joined
Feb 5, 2018
Messages
567
So I've actually solved the problem, If you actually use shockwave it does just work, mine didn't because I was using channel with the target type set to point target. With my map I can actually get away with using shockwave to trigger the spell effect but I will look to see if there is a way to have it function using channel.

If you want similiar spells like this you should be able to set channel to "Unit or Point target". Then see if it actually works :)
 
Level 1
Joined
Mar 15, 2021
Messages
3
If you want similiar spells like this you should be able to set channel to "Unit or Point target". Then see if it actually works :)
I imagine it's as simple as checking if GetSpellTargetUnit() exists or not.
It is exactly that simple, all of the above works perfectly. I feel a little foolish now haha. Thank you all for the help.

For the record my issue was that if you use channel with the target type set to "Point target" and not "Unit or Point target" then GetSpellTargetUnit() will return null regardless of whether you clicked on a unit or not.
 
Status
Not open for further replies.
Top