• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

problems with saving group in hashtable

Status
Not open for further replies.
Level 3
Joined
May 26, 2009
Messages
34
I want in to save a unitgroup in a hashtable, attached to a timer
but i can't load this unitgroup, except, I don't attach it, but save it in the category 1 for example...
JASS:
function ForcePushGroupMove takes nothing returns nothing
        call BJDebugMsg("test1")        //important
endfunction

function ForcePushTimerCallback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer ID = GetHandleId(t)
    local unit u = LoadUnitHandle(udg_ForcePushH, ID, 0)
    local real array x
    local real array y
        if LoadReal(udg_ForcePushH, ID, 2) < LoadReal(udg_ForcePushH, ID, 1) then
            set udg_TempInt[0] = ID
            set udg_TempReal[0] = (10*LoadInteger(udg_ForcePushH, ID, 0)) * (1.001-LoadReal(udg_ForcePushH, ID, 2)/LoadReal(udg_ForcePushH, ID, 1))
            call BJDebugMsg(I2S(CountUnitsInGroup(LoadGroupHandle(udg_ForcePushH, ID, 0))))         //important
            call ForGroup(LoadGroupHandle(udg_ForcePushH, ID, 3), function ForcePushGroupMove)      //important
            call SaveReal(udg_ForcePushH, ID, 2, LoadReal(udg_ForcePushH, ID, 2)+udg_TempReal[0])
        else
            call ForGroup(LoadGroupHandle(udg_ForcePushH, ID, 0), function ForcePushDestroyEffects)
            call DestroyGroup(LoadGroupHandle(udg_ForcePushH, ID, 0))
            call DestroyTimer(t)
            call FlushChildHashtable(udg_ForcePushH, ID)
        endif    
endfunction

function ForcePushActions takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local real array x
    local real array y
    local group g = CreateGroup()
    local timer t = CreateTimer()
    local location l = GetSpellTargetLoc()
        set x[1] = GetUnitX(u)
        set y[1] = GetUnitY(u)
        set x[0] = GetLocationX(l)
        set y[0] = GetLocationY(l)
        call RemoveLocation(l)
        set l = null
        set udg_TempUnit[0] = u
        set udg_TempReal[0] = bj_RADTODEG * Atan2(y[0]-y[1], x[0]-x[1])
        call GroupEnumUnitsInRange(g, x[0], y[0], 800, Condition(function ForcePushInRangeAngle))
        set udg_TempInt[0]=GetHandleId(t)
        
        call SaveGroupHandle(udg_ForcePushH, udg_TempInt[0], 0, CreateGroup())      //important
        call GroupAddGroup(g, LoadGroupHandle(udg_ForcePushH, udg_TempInt[0], 0))   //important
        
        call ForGroup(g, function ForcePushDamage)
        call SaveReal(udg_ForcePushH, udg_TempInt[0], 2, 0)
        call SaveReal(udg_ForcePushH, udg_TempInt[0], 1, GetUnitAbilityLevel(u, 'A002')*80)
        call SaveInteger(udg_ForcePushH, udg_TempInt[0], 0, GetUnitAbilityLevel(u, 'A002'))
        call TimerStart(t, 0.03, true, function ForcePushTimerCallback)
        set u = null
endfunction

The test1 message isn't displayed :sad:
 
JASS:
function ForcePushConditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A002'
endfunction

function ForcePushInRangeAngle takes nothing returns boolean
    local real array x
    local real array y
    local unit array u
        set u[1]= GetFilterUnit()
        set u[0]= udg_TempUnit[0]
        set x[0]= GetUnitX(u[0])
        set y[0]= GetUnitY(u[0])
        set x[1]= GetUnitX(u[1])
        set y[1]= GetUnitY(u[1])
        set y[2]= bj_RADTODEG * Atan2(y[1]-y[0], x[1]-x[0])
        set y[3]= udg_TempReal[0]
        return y[2] > y[3] - 60 and y[2] < y[3] + 60 and IsUnitEnemy(u[1], GetOwningPlayer(u[0])) and GetWidgetLife(u[1]) > 0
endfunction

function ForcePushDamage takes nothing returns nothing
    local unit array u
    local real array x
    local real array y
        set u[1]= GetEnumUnit()
        set u[0]= udg_TempUnit[0]
        set x[0]= GetUnitX(u[0])
        set y[0]= GetUnitY(u[0])
        set x[1]= GetUnitX(u[1])
        set y[1]= GetUnitY(u[1])
        set y[2]= bj_RADTODEG * Atan2(y[1]-y[0], x[1]-x[0])
        call UnitDamageTarget(u[0], u[1], 10 * GetUnitAbilityLevel(u[0], 'A002'), true, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
        call SaveUnitHandle(udg_ForcePushH, udg_TempInt[0], 0, u[1])
        call SaveReal(udg_ForcePushH, GetHandleId(u[1]), 0, y[2])
        call SaveEffectHandle(udg_ForcePushH, GetHandleId(u[1]), 0, AddSpecialEffectTarget("Abilities\\Spells\\Orc\\EtherealForm\\SpiritWalkerChange.mdl", u[1], "chest"))
endfunction

function ForcePushDestroyEffects takes nothing returns nothing
    call DestroyEffect(LoadEffectHandle(udg_ForcePushH, udg_TempInt[0], 0))
endfunction

function ForcePushGroupMove takes nothing returns nothing
    local unit u = GetEnumUnit()
    local integer ID = GetHandleId(u)
    local real array x
    local real array y
        call BJDebugMsg("test1")        //This message isn't displayed
        set x[0] = GetUnitX(u)
        set y[0] = GetUnitY(u)
        call BJDebugMsg("test2")
        set x[1] = x[0] + udg_TempReal[0] * Cos(LoadReal(udg_ForcePushH, ID, 0)* bj_DEGTORAD)
        set y[1] = y[0] + udg_TempReal[0] * Sin(LoadReal(udg_ForcePushH, ID, 0)* bj_DEGTORAD)
        call BJDebugMsg("test3")
        call SetUnitX(u, x[1])
        call SetUnitY(u, y[1])
        call BJDebugMsg("test4")
endfunction

function ForcePushTimerCallback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer ID = GetHandleId(t)
    local unit u = LoadUnitHandle(udg_ForcePushH, ID, 0)
    local real array x
    local real array y
        if LoadReal(udg_ForcePushH, ID, 2) < LoadReal(udg_ForcePushH, ID, 1) then
            set udg_TempInt[0] = ID
            set udg_TempReal[0] = (10*LoadInteger(udg_ForcePushH, ID, 0)) * (1.001-LoadReal(udg_ForcePushH, ID, 2)/LoadReal(udg_ForcePushH, ID, 1))
            call BJDebugMsg(I2S(CountUnitsInGroup(LoadGroupHandle(udg_ForcePushH, ID, 0))))         //Can't Load this damn unitgroup :O (units in group = 0)
            call ForGroup(LoadGroupHandle(udg_ForcePushH, ID, 3), function ForcePushGroupMove)      //Of course the same problem
            call SaveReal(udg_ForcePushH, ID, 2, LoadReal(udg_ForcePushH, ID, 2)+udg_TempReal[0])
        else
            call ForGroup(LoadGroupHandle(udg_ForcePushH, ID, 0), function ForcePushDestroyEffects)
            call DestroyGroup(LoadGroupHandle(udg_ForcePushH, ID, 0))
            call DestroyTimer(t)
            call FlushChildHashtable(udg_ForcePushH, ID)
        endif    
endfunction

function ForcePushActions takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local real array x
    local real array y
    local group g = CreateGroup()
    local timer t = CreateTimer()
    local location l = GetSpellTargetLoc()
        set x[1] = GetUnitX(u)
        set y[1] = GetUnitY(u)
        set x[0] = GetLocationX(l)
        set y[0] = GetLocationY(l)
        call RemoveLocation(l)
        set l = null
        set udg_TempUnit[0] = u
        set udg_TempReal[0] = bj_RADTODEG * Atan2(y[0]-y[1], x[0]-x[1])
        call GroupEnumUnitsInRange(g, x[0], y[0], 800, Condition(function ForcePushInRangeAngle))
        set udg_TempInt[0]=GetHandleId(t)
        
        call SaveGroupHandle(udg_ForcePushH, udg_TempInt[0], 0, CreateGroup())      //important
        call GroupAddGroup(g, LoadGroupHandle(udg_ForcePushH, udg_TempInt[0], 0))   //important
        
        call ForGroup(g, function ForcePushDamage)
        call SaveReal(udg_ForcePushH, udg_TempInt[0], 2, 0)
        call SaveReal(udg_ForcePushH, udg_TempInt[0], 1, GetUnitAbilityLevel(u, 'A002')*80)
        call SaveInteger(udg_ForcePushH, udg_TempInt[0], 0, GetUnitAbilityLevel(u, 'A002'))
        call TimerStart(t, 0.03, true, function ForcePushTimerCallback)
        set u = null
endfunction

//===========================================================================
function InitTrig_ForcePush takes nothing returns nothing
    set gg_trg_ForcePush = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ForcePush, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_ForcePush, function ForcePushActions )
    call TriggerAddCondition(gg_trg_ForcePush, Condition(function ForcePushConditions))
endfunction

Here is the whole trigger, I only wanted to spare you so much text ;)

If you are about to save a unit group in a hashtable, prefer some global group (udg_ prefixed), don't create it upon saving it to the hashtable.

do you mean like that?

JASS:
        call SaveGroupHandle(udg_ForcePushH, udg_TempInt[0], 0, g)

or like that

JASS:
        call GroupAddGroup(g, udg_TempGroup)
        call SaveGroupHandle(udg_ForcePushH, udg_TempInt[0], 0, udg_TempGroup)

But in the end, none of them works :(

but thanks anyway :D
 
Thanks, I didn't know this function ;)
I hate locations :D
Is there an additional function for GetLocationZ() ??
 
Status
Not open for further replies.
Back
Top