• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

GetSummonedUnit not working on tornado unit

Status
Not open for further replies.
Level 14
Joined
Apr 20, 2009
Messages
1,543
So I've made a spell based off of tornado and I can't get the summoned unit from the spell. I've also tried doing a group enum in range to see if any units in range of the target had the same raw id but that also didn't seem to work. It seems like the unit doesn't exist or something. When I msg out the handle id it is always 0. Does anyone know how to get the unit that is summoned from tornado?
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
strange that does seem to work for me aswell, however when I use GetSummonedUnit() within a unit starts the effect of an ability I can't seem to get the summoned unit...
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
strange that does seem to work for me aswell, however when I use GetSummonedUnit() within a unit starts the effect of an ability I can't seem to get the summoned unit...

Because you are using wrong event/response combination.There is a seperate event for summoning.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
My bad I feel like such a noob because of that, but how would I get the unit from within a spell then? I need it for a spell I'm making...
Even a group enum doesn't seem to work. It seems to pick every unit in range except for the tornado summoned unit :/
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
This is what I'm doing:

JASS:
struct Data
    real pointX
    real pointY
    unit summonedUnit
    integer heroInt
    integer heroLevel
    unit triggerUnit
    player triggerPlayer
    static constant real DAMAGE = 10
    
    method destroy takes nothing returns nothing
        call this.deallocate()
        set this.summonedUnit = null
        set this.triggerUnit = null
        set this.triggerPlayer = null
    endmethod
endstruct

function WaterOrbCallback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local Data data = GetTimerData(t)
    local group g = CreateGroup()
    local unit u
    if GetWidgetLife(data.summonedUnit) > 0 then
        call BJDebugMsg(" summoned unit is alive")
        call GroupEnumUnitsInRange(g, data.pointX, data.pointY , 150 , null)
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
            if IsUnitAlly(u, data.triggerPlayer) and GetWidgetLife(u) > 0 then
                call UnitDamageTarget(data.triggerUnit, u, data.DAMAGE, true, false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_COLD,WEAPON_TYPE_WHOKNOWS)
            endif
            call GroupRemoveUnit(g, u)
        endloop
        call DestroyGroup(g)
    else
        call ReleaseTimer(t)
        call data.destroy()
    endif
endfunction

function WaterOrbActions takes nothing returns boolean
    local group g
    local unit u
    local timer t
    local Data data
    if GetSpellAbilityId() == 'A06Z' then
        set data = Data.create()
        set data.triggerUnit = GetTriggerUnit()
        set data.heroLevel = GetUnitAbilityLevel(data.triggerUnit, 'A06Z')
        set data.heroInt = GetHeroInt(data.triggerUnit, true)
        set data.pointX = GetSpellTargetX()
        set data.pointY = GetSpellTargetY()
        set g = CreateGroup()
        call GroupEnumUnitsInRange(g, data.pointX, data.pointY, 300, null)
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
            call BJDebugMsg(I2S(GetUnitTypeId(u)))
            if GetUnitTypeId(u) == 'h01H' then
                set data.summonedUnit = u
            endif
            call GroupRemoveUnit(g, u)
        endloop
        call DestroyGroup(g)
        call BJDebugMsg(I2S(GetHandleId(data.summonedUnit)))
        set data.triggerPlayer = GetTriggerPlayer()
        set t = NewTimer()
        call SetTimerData(t, data)
        call TimerStart(t, 1, true, function WaterOrbCallback)
    endif
    return false
endfunction

//===========================================================================
function InitTrig_Water_Orb takes nothing returns nothing
    set gg_trg_Water_Orb = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Water_Orb, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Water_Orb, Condition( function WaterOrbActions ) )
endfunction

I know this code is still a little inefficient and not the way to make spells but it's for a custom map and I don't care that much about it.
I know what you guys are saying but I wonder if it's possible to get that unit from within a spell.

h01H is the raw id type for the summoned unit

EDIT: since I need to use a different event, how can I pass struct data to another trigger so that it sets the summoned unit in the trigger that has the summoned unit event?
 
Last edited:
Status
Not open for further replies.
Top