• 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.

[JASS] Game Cache Problem

Status
Not open for further replies.
Level 4
Joined
Sep 21, 2004
Messages
110
I cant get these stupid game caches working. Its for an Omni Drain spell im doing. I tried two ways of game caching that I've seen in the past. Here's both:

Number 1:
JASS:
function Trig_Omni_Drain_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00K' ) ) then
        return false
    endif
    return true
endfunction

function Drain_End_Cond takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'e004' ) ) then
        return false
    endif
    return true
endfunction

function Drain_End_Acts takes nothing returns nothing
    local unit u1 = I2U(GetLinkedInteger(GetTriggeringTrigger(),"u1"))
    local unit u2 = I2U(GetLinkedInteger(GetTriggeringTrigger(),"u2"))
    local unit u3 = I2U(GetLinkedInteger(GetTriggeringTrigger(),"u3"))
    local unit u4 = I2U(GetLinkedInteger(GetTriggeringTrigger(),"u4"))
    local unit u5 = I2U(GetLinkedInteger(GetTriggeringTrigger(),"u5"))
    local unit ta1 = I2U(GetLinkedInteger(GetTriggeringTrigger(),"ta1"))
    local unit ta2 = I2U(GetLinkedInteger(GetTriggeringTrigger(),"ta2"))
    local unit ta3 = I2U(GetLinkedInteger(GetTriggeringTrigger(),"ta3"))
    local unit ta4 = I2U(GetLinkedInteger(GetTriggeringTrigger(),"ta4"))
    local unit ta5 = I2U(GetLinkedInteger(GetTriggeringTrigger(),"ta5"))
    if (GetTriggerUnit() == u1) then
    call GroupRemoveUnitSimple( ta1, udg_DrainGroup )
    endif
    if (GetTriggerUnit() == u2) then
    call GroupRemoveUnitSimple( ta2, udg_DrainGroup )
    endif
    if (GetTriggerUnit() == u3) then
    call GroupRemoveUnitSimple( ta3, udg_DrainGroup )
    endif
    if (GetTriggerUnit() == u4) then
    call GroupRemoveUnitSimple( ta4, udg_DrainGroup )
    endif
    if (GetTriggerUnit() == u5) then
    call GroupRemoveUnitSimple( ta5, udg_DrainGroup )
    endif
    set u1 = null
    set u2 = null
    set u3 = null
    set u4 = null
    set u5 = null
    set ta1 = null
    set ta2 = null
    set ta3 = null
    set ta4 = null
    set ta5 = null
endfunction

function Drain_Alive takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction

function Drain_Buff takes nothing returns boolean
    return ( UnitHasBuffBJ(GetFilterUnit(), 'Bdtl') == false )
endfunction

function Drain_Enemy takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) == true )
endfunction

function Drain_Check2 takes nothing returns boolean
    return GetBooleanAnd( Drain_Buff(), Drain_Alive() )
endfunction

function Drain_Check1 takes nothing returns boolean
    return GetBooleanAnd( Drain_Check2(), Drain_Enemy() )
endfunction

function Drain_Add_Unit takes nothing returns nothing
    call GroupAddUnitSimple(GetEnumUnit(),udg_DrainGroup)
endfunction

function Trig_Omni_Drain_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local integer level = ( GetUnitAbilityLevelSwapped(GetSpellAbilityId(), caster))
    local real drain = (((I2R(level)*8.0)+8.0)/2.0)
    local real heal
    local trigger t = CreateTrigger()
    local trigger s = CreateTrigger()
    local unit array targets
    local unit target = GetSpellTargetUnit()
    local real face = ( GetUnitFacing(caster))

    local unit array u
    local integer x = 1
    
    call TriggerRegisterUnitEvent(s,caster,EVENT_UNIT_SPELL_ENDCAST)
    call CreateNUnitsAtLoc( 1, 'e004', GetOwningPlayer(caster), GetUnitLoc(caster), bj_UNIT_FACING )
    call IssueTargetOrderBJ( GetLastCreatedUnit(), "drain", target )
    set u[1] = GetLastCreatedUnit()
    call ForGroupBJ( GetUnitsInRangeOfLocMatching(600.00, GetUnitLoc(caster), Condition(function Drain_Check1)), function Drain_Add_Unit )
  
    loop
        exitwhen x > 4
        set targets[x] = FirstOfGroup(udg_DrainGroup)
        call GroupRemoveUnitSimple(targets[x],udg_DrainGroup)
        set x = x+1
    endloop
    call GroupClear( udg_DrainGroup )
    call GroupAddUnitSimple(target,udg_DrainGroup)
    if (targets[1] != null) then
    call GroupAddUnitSimple(targets[1],udg_DrainGroup)
    call CreateNUnitsAtLoc( 1, 'e004', GetOwningPlayer(caster), GetUnitLoc(caster), bj_UNIT_FACING )
    call IssueTargetOrderBJ( GetLastCreatedUnit(), "drain", targets[1] )
    set u[2] = GetLastCreatedUnit()
    endif
    if (targets[2] != null) then
    call GroupAddUnitSimple(targets[2],udg_DrainGroup)
    call CreateNUnitsAtLoc( 1, 'e004', GetOwningPlayer(caster), GetUnitLoc(caster), bj_UNIT_FACING )
    call IssueTargetOrderBJ( GetLastCreatedUnit(), "drain", targets[2] )
    set u[3] = GetLastCreatedUnit()
    endif
    if (targets[3] != null) then
    call GroupAddUnitSimple(targets[3],udg_DrainGroup)
    call CreateNUnitsAtLoc( 1, 'e004', GetOwningPlayer(caster), GetUnitLoc(caster), bj_UNIT_FACING )
    call IssueTargetOrderBJ( GetLastCreatedUnit(), "drain", targets[3] )
    set u[4] = GetLastCreatedUnit()
    endif
    if (targets[4] != null) then
    call GroupAddUnitSimple(targets[4],udg_DrainGroup)
    call CreateNUnitsAtLoc( 1, 'e004', GetOwningPlayer(caster), GetUnitLoc(caster), bj_UNIT_FACING )
    call IssueTargetOrderBJ( GetLastCreatedUnit(), "drain", targets[4] )
    set u[5] = GetLastCreatedUnit()
    endif

    call StoreHandle(t,u[1],"u1")
    call StoreHandle(t,u[2],"u2")
    call StoreHandle(t,u[3],"u3")
    call StoreHandle(t,u[4],"u4")
    call StoreHandle(t,u[5],"u5")
    call StoreHandle(t,targets[1],"ta1")
    call StoreHandle(t,targets[2],"ta2")
    call StoreHandle(t,targets[3],"ta3")
    call StoreHandle(t,targets[4],"ta4")
    call StoreHandle(t,targets[5],"ta5")
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_ENDCAST )
    call TriggerAddCondition( t, Condition( function Drain_End_Cond ) )
    call TriggerAddAction( t, function Drain_End_Acts )

    loop
        exitwhen GetTriggerEvalCount(s)>0
        set heal = (drain*(CountUnitsInGroup(udg_DrainGroup)))
        call SetUnitLifeBJ(caster,( GetUnitStateSwap(UNIT_STATE_LIFE,caster)+(drain*(heal))))
        call DisplayTextToForce( GetPlayersAll(), R2S(heal) )
        set x = 1
        loop
        exitwhen x>6
        exitwhen GetTriggerEvalCount(s)>0
        call TriggerSleepAction(0.01)
        set x = x+1
        endloop
    endloop

    set x = 1
    loop
        exitwhen x > 5
        call RemoveUnit( u[x] )
        set u[x] = null
        set targets[x] = null
        set x = x+1
    endloop
    call GroupClear( udg_DrainGroup )
    set caster = null
    set target = null
    call DestroyTrigger(s)
    call DestroyTrigger(t)
endfunction

//===========================================================================
function InitTrig_Omni_Drain takes nothing returns nothing
    set gg_trg_Omni_Drain = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Omni_Drain, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Omni_Drain, Condition( function Trig_Omni_Drain_Conditions ) )
    call TriggerAddAction( gg_trg_Omni_Drain, function Trig_Omni_Drain_Actions )
endfunction

Numer 2:
JASS:
function HandleToInt takes handle h returns integer
    return h
    return 0
endfunction
function IntToHandle takes integer i returns handle
    return i
    return null
endfunction

function DrainCache takes nothing returns gamecache
    return InitGameCache("draincache")
endfunction

function Trig_Omni_Drain_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00K' ) ) then
        return false
    endif
    return true
endfunction

function Drain_End_Cond takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'e004' ) ) then
        return false
    endif
    return true
endfunction

function Drain_End_Acts takes nothing returns nothing
    local gamecache gc = DrainCache()
    local unit u1 = I2U(GetLinkedInteger(gc,"u1"))
    local unit u2 = I2U(GetLinkedInteger(gc,"u2"))
    local unit u3 = I2U(GetLinkedInteger(gc,"u3"))
    local unit u4 = I2U(GetLinkedInteger(gc,"u4"))
    local unit u5 = I2U(GetLinkedInteger(gc,"u5"))
    local unit ta2 = I2U(GetLinkedInteger(gc,"ta2"))
    local unit ta3 = I2U(GetLinkedInteger(gc,"ta3"))
    local unit ta4 = I2U(GetLinkedInteger(gc,"ta4"))
    local unit ta5 = I2U(GetLinkedInteger(gc,"ta5"))
    local unit target = I2U(GetLinkedInteger(gc,"target"))
    if (GetTriggerUnit() == u1) then
    call GroupRemoveUnitSimple( target, udg_DrainGroup )
    endif
    if (GetTriggerUnit() == u2) then
    call GroupRemoveUnitSimple( ta2, udg_DrainGroup )
    endif
    if (GetTriggerUnit() == u3) then
    call GroupRemoveUnitSimple( ta3, udg_DrainGroup )
    endif
    if (GetTriggerUnit() == u4) then
    call GroupRemoveUnitSimple( ta4, udg_DrainGroup )
    endif
    if (GetTriggerUnit() == u5) then
    call GroupRemoveUnitSimple( ta5, udg_DrainGroup )
    endif
    set u1 = null
    set u2 = null
    set u3 = null
    set u4 = null
    set u5 = null
    set target = null
    set ta2 = null
    set ta3 = null
    set ta4 = null
    set ta5 = null
endfunction

function Drain_Alive takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction

function Drain_Buff takes nothing returns boolean
    return ( UnitHasBuffBJ(GetFilterUnit(), 'Bdtl') == false )
endfunction

function Drain_Enemy takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) == true )
endfunction

function Drain_Check2 takes nothing returns boolean
    return GetBooleanAnd( Drain_Buff(), Drain_Alive() )
endfunction

function Drain_Check1 takes nothing returns boolean
    return GetBooleanAnd( Drain_Check2(), Drain_Enemy() )
endfunction

function Drain_Add_Unit takes nothing returns nothing
    call GroupAddUnitSimple(GetEnumUnit(),udg_DrainGroup)
endfunction

function Trig_Omni_Drain_Actions takes nothing returns nothing
    local gamecache gc = DrainCache()
    local unit caster = GetTriggerUnit()
    local integer level = ( GetUnitAbilityLevelSwapped(GetSpellAbilityId(), caster))
    local real drain = (((I2R(level)*8.0)+8.0)/2.0)
    local real heal
    local trigger t = CreateTrigger()
    local trigger s = CreateTrigger()
    local unit array targets
    local unit target = GetSpellTargetUnit()
    local real face = ( GetUnitFacing(caster))

    local unit array u
    local integer x = 1
    
    call TriggerRegisterUnitEvent(s,caster,EVENT_UNIT_SPELL_ENDCAST)
    call CreateNUnitsAtLoc( 1, 'e004', GetOwningPlayer(caster), GetUnitLoc(caster), bj_UNIT_FACING )
    call IssueTargetOrderBJ( GetLastCreatedUnit(), "drain", target )
    set u[1] = GetLastCreatedUnit()
    call ForGroupBJ( GetUnitsInRangeOfLocMatching(600.00, GetUnitLoc(caster), Condition(function Drain_Check1)), function Drain_Add_Unit )
  
    loop
        exitwhen x > 4
        set targets[x] = FirstOfGroup(udg_DrainGroup)
        call GroupRemoveUnitSimple(targets[x],udg_DrainGroup)
        set x = x+1
    endloop
    call GroupClear( udg_DrainGroup )
    call GroupAddUnitSimple(target,udg_DrainGroup)
    if (targets[1] != null) then
    call GroupAddUnitSimple(targets[1],udg_DrainGroup)
    call CreateNUnitsAtLoc( 1, 'e004', GetOwningPlayer(caster), GetUnitLoc(caster), bj_UNIT_FACING )
    call IssueTargetOrderBJ( GetLastCreatedUnit(), "drain", targets[1] )
    set u[2] = GetLastCreatedUnit()
    endif
    if (targets[2] != null) then
    call GroupAddUnitSimple(targets[2],udg_DrainGroup)
    call CreateNUnitsAtLoc( 1, 'e004', GetOwningPlayer(caster), GetUnitLoc(caster), bj_UNIT_FACING )
    call IssueTargetOrderBJ( GetLastCreatedUnit(), "drain", targets[2] )
    set u[3] = GetLastCreatedUnit()
    endif
    if (targets[3] != null) then
    call GroupAddUnitSimple(targets[3],udg_DrainGroup)
    call CreateNUnitsAtLoc( 1, 'e004', GetOwningPlayer(caster), GetUnitLoc(caster), bj_UNIT_FACING )
    call IssueTargetOrderBJ( GetLastCreatedUnit(), "drain", targets[3] )
    set u[4] = GetLastCreatedUnit()
    endif
    if (targets[4] != null) then
    call GroupAddUnitSimple(targets[4],udg_DrainGroup)
    call CreateNUnitsAtLoc( 1, 'e004', GetOwningPlayer(caster), GetUnitLoc(caster), bj_UNIT_FACING )
    call IssueTargetOrderBJ( GetLastCreatedUnit(), "drain", targets[4] )
    set u[5] = GetLastCreatedUnit()
    endif

    call StoreHandle(gc,target,"target")
    call StoreHandle(gc,u[1],"u1")
    call StoreHandle(gc,u[2],"u2")
    call StoreHandle(gc,u[3],"u3")
    call StoreHandle(gc,u[4],"u4")
    call StoreHandle(gc,u[5],"u5")
    call StoreHandle(gc,targets[2],"ta2")
    call StoreHandle(gc,targets[3],"ta3")
    call StoreHandle(gc,targets[4],"ta4")
    call StoreHandle(gc,targets[5],"ta5")
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_ENDCAST )
    call TriggerAddCondition( t, Condition( function Drain_End_Cond ) )
    call TriggerAddAction( t, function Drain_End_Acts )

    loop
        exitwhen GetTriggerEvalCount(s)>0
        set heal = (drain*(CountUnitsInGroup(udg_DrainGroup)))
        call SetUnitLifeBJ(caster,( GetUnitStateSwap(UNIT_STATE_LIFE,caster)+(drain*(heal))))
        call DisplayTextToForce( GetPlayersAll(), R2S(heal) )
        set x = 1
        loop
        exitwhen x>6
        exitwhen GetTriggerEvalCount(s)>0
        call TriggerSleepAction(0.01)
        set x = x+1
        endloop
    endloop

    set x = 1
    loop
        exitwhen x > 5
        call RemoveUnit( u[x] )
        set u[x] = null
        set targets[x] = null
        set x = x+1
    endloop
    call GroupClear( udg_DrainGroup )
    set caster = null
    set target = null
    call DestroyTrigger(s)
    call DestroyTrigger(t)
endfunction

//===========================================================================
function InitTrig_Omni_Drain takes nothing returns nothing
    set gg_trg_Omni_Drain = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Omni_Drain, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Omni_Drain, Condition( function Trig_Omni_Drain_Conditions ) )
    call TriggerAddAction( gg_trg_Omni_Drain, function Trig_Omni_Drain_Actions )
endfunction
JASS:
JASS:
 
Status
Not open for further replies.
Top