• 🏆 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!

Handle IDs

Status
Not open for further replies.
How can I do this code MUI and leakless?
JASS:
function WaterHealingSpirit_Group takes nothing returns nothing
if IsUnitAlly(GetEnumUnit(),GetOwningPlayer(udg_WaterFurySpirit[4])) then
call SetUnitState(GetEnumUnit(),ConvertUnitState(2),GetUnitState(GetEnumUnit(),ConvertUnitState(2))+15*GetUnitAbilityLevel(LoadUnitHandle(udg_Hashtable,1,24),0x41303156))
endif
endfunction

function HealSharick_Conditions takes nothing returns boolean
return GetUnitState(udg_WaterFurySpirit[4],UNIT_STATE_LIFE )>0.00
endfunction

function HealSharick_Actions takes nothing returns nothing
local location l=GetUnitLoc(udg_WaterFurySpirit[4])
local group g=GetUnitsInRangeOfLocAll(500.,l)
call RemoveLocation(l)
set l=null
call ForGroup(g,function WaterHealingSpirit_Group)
call DestroyGroup(g)
set g=null
call SetUnitAnimation(udg_WaterFurySpirit[4],"attack")
call IssueImmediateOrderById(udg_WaterFurySpirit[5],852526)
endfunction

function WaterHealingSpirit_Conditions takes nothing returns boolean
return GetSpellAbilityId()==0x41303156
endfunction

function WaterHealingSpirit_Actions takes nothing returns nothing
local real x=GetLocationX(GetSpellTargetLoc())
local real y=GetLocationY(GetSpellTargetLoc())
local unit healcaster=GetSpellAbilityUnit()
local real s=.2*(GetUnitAbilityLevel(healcaster,0x41303156))+.6
local trigger HealSharick=CreateTrigger()
call TriggerRegisterTimerEventPeriodic(HealSharick,3)
call TriggerAddCondition(HealSharick,Condition(function HealSharick_Conditions))
call TriggerAddAction(HealSharick,function HealSharick_Actions)
call EnableTrigger(HealSharick)
call SaveUnitHandle(udg_Hashtable,1,24,healcaster)
set udg_WaterFurySpirit[5]=CreateUnit(GetOwningPlayer(healcaster),0x6E303051,x,y,GetUnitFacing(healcaster))
set udg_WaterFurySpirit[4]=CreateUnit(GetOwningPlayer(healcaster),0x6E303050,x,y,GetUnitFacing(healcaster))
call SetUnitAnimation(udg_WaterFurySpirit[4],"birth" )
call QueueUnitAnimation(udg_WaterFurySpirit[4],"stand")
call SetUnitScale(udg_WaterFurySpirit[4],s,s,s) 
call SetUnitVertexColor(udg_WaterFurySpirit[4], 100, 100, 100, 90)
call IssueTargetOrderById(udg_WaterFurySpirit[5],852486,udg_WaterFurySpirit[4])
call SetUnitInvulnerable(udg_WaterFurySpirit[4],true)
call TriggerSleepAction(0.50)
call SetUnitInvulnerable(udg_WaterFurySpirit[4],false )
call SetUnitAbilityLevel(udg_WaterFurySpirit[5],0x4130314E,GetUnitAbilityLevel(healcaster,0x41303156))
//call SetUnitAbilityLevel(udg_WaterFurySpirit[4],0x4130314D,GetUnitAbilityLevel(healcaster,0x41303156))
if udg_WaterSpiritsMight==true then
if GetUnitAbilityLevel(healcaster,0x41303154)==1 then
call UnitAddAbility(udg_WaterFurySpirit[4],0x41303150)
elseif GetUnitAbilityLevel(healcaster,0x41303154)==2 then
call UnitAddAbility(udg_WaterFurySpirit[4],0x41303151)
elseif GetUnitAbilityLevel(healcaster,0x41303154)==3 then
call UnitAddAbility(udg_WaterFurySpirit[4],0x41303153)
else
call UnitAddAbility(udg_WaterFurySpirit[4],0x41303152)
endif
endif
call TriggerSleepAction(14.5)
call SetUnitInvulnerable(udg_WaterFurySpirit[4],true )
call SetUnitAnimation(udg_WaterFurySpirit[4],"death")
call RemoveUnit(udg_WaterFurySpirit[5])
call DestroyTrigger(HealSharick)
set HealSharick=null
call UnitRemoveAbility(udg_WaterFurySpirit[4],0x4130314D)
call TriggerSleepAction(1.5)
call RemoveUnit(udg_WaterFurySpirit[4])
endfunction

//===========================================================================
function InitTrig_WaterHealingSpirit takes nothing returns nothing
local trigger WaterHealingSpirit = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(WaterHealingSpirit,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(WaterHealingSpirit,Condition( function WaterHealingSpirit_Conditions))
call TriggerAddAction(WaterHealingSpirit,function WaterHealingSpirit_Actions)
set WaterHealingSpirit=null
endfunction
The local triggers are confusing me...:sad:
 
Level 6
Joined
Mar 22, 2009
Messages
276
Do not use waits, use timers instead. Timers are also used in making loops MUI by storing data into its HandleId..

I had that kind of problem a while ago and was solved.
Check my thread and see the solutions that I got there. HERE
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
The Triggers & Scripts forum at least. And you could start by using the tab key once in awhile.

This here is a lot easier to read:
JASS:
function WaterHealingSpirit_Group takes nothing returns nothing
    if IsUnitAlly(GetEnumUnit(),GetOwningPlayer(udg_WaterFurySpirit[4])) then
        call SetUnitState(GetEnumUnit(),ConvertUnitState(2),GetUnitState(GetEnumUnit(),ConvertUnitState(2))+15*GetUnitAbilityLevel(LoadUnitHandle(udg_Hashtable,1,24),0x41303156))
    endif
endfunction

function HealSharick_Conditions takes nothing returns boolean
    return GetUnitState(udg_WaterFurySpirit[4],UNIT_STATE_LIFE )>0.00
endfunction

function HealSharick_Actions takes nothing returns nothing
    local location l=GetUnitLoc(udg_WaterFurySpirit[4])
    local group g=GetUnitsInRangeOfLocAll(500.,l)
    
    call RemoveLocation(l)
    set l=null
    call ForGroup(g,function WaterHealingSpirit_Group)
    call DestroyGroup(g)
    set g=null
    
    call SetUnitAnimation(udg_WaterFurySpirit[4],"attack")
    call IssueImmediateOrderById(udg_WaterFurySpirit[5],852526)
endfunction

function WaterHealingSpirit_Conditions takes nothing returns boolean
    return GetSpellAbilityId()==0x41303156
endfunction

function WaterHealingSpirit_Actions takes nothing returns nothing
    local real x=GetSpellTargetX()  //GetLocationX(GetSpellTargetLoc())     < when you reference "GetSpellTargetLoc()" it creates a location
    local real y=GetSpellTargetY()  //GetLocationY(GetSpellTargetLoc())     handle which you must remove, so it needs to be set as a variable.
    local unit healcaster=GetSpellAbilityUnit()                         //  < it doesn't really matter though since you don't need to use a location,
    local real s=.2*(GetUnitAbilityLevel(healcaster,0x41303156))+.6     //  you can just use the "GetSpellTargetX/Y" functions since you use x/y anyway.
    local trigger HealSharick=CreateTrigger()
    
    call TriggerRegisterTimerEventPeriodic(HealSharick,3)
    call TriggerAddCondition(HealSharick,Condition(function HealSharick_Conditions))
    call TriggerAddAction(HealSharick,function HealSharick_Actions)
    call EnableTrigger(HealSharick)
    call SaveUnitHandle(udg_Hashtable,1,24,healcaster)
    
    set udg_WaterFurySpirit[5]=CreateUnit(GetOwningPlayer(healcaster),0x6E303051,x,y,GetUnitFacing(healcaster))
    set udg_WaterFurySpirit[4]=CreateUnit(GetOwningPlayer(healcaster),0x6E303050,x,y,GetUnitFacing(healcaster))
    
    call SetUnitAnimation(udg_WaterFurySpirit[4],"birth" )
    call QueueUnitAnimation(udg_WaterFurySpirit[4],"stand")
    call SetUnitScale(udg_WaterFurySpirit[4],s,s,s) 
    call SetUnitVertexColor(udg_WaterFurySpirit[4], 100, 100, 100, 90)
    call IssueTargetOrderById(udg_WaterFurySpirit[5],852486,udg_WaterFurySpirit[4])
    call SetUnitInvulnerable(udg_WaterFurySpirit[4],true)
    
    call TriggerSleepAction(0.50)
    
    call SetUnitInvulnerable(udg_WaterFurySpirit[4],false )
    call SetUnitAbilityLevel(udg_WaterFurySpirit[5],0x4130314E,GetUnitAbilityLevel(healcaster,0x41303156))
    //call SetUnitAbilityLevel(udg_WaterFurySpirit[4],0x4130314D,GetUnitAbilityLevel(healcaster,0x41303156))
    if udg_WaterSpiritsMight==true then
        if GetUnitAbilityLevel(healcaster,0x41303154)==1 then
            call UnitAddAbility(udg_WaterFurySpirit[4],0x41303150)
        elseif GetUnitAbilityLevel(healcaster,0x41303154)==2 then
            call UnitAddAbility(udg_WaterFurySpirit[4],0x41303151)
        elseif GetUnitAbilityLevel(healcaster,0x41303154)==3 then
            call UnitAddAbility(udg_WaterFurySpirit[4],0x41303153)
        else
            call UnitAddAbility(udg_WaterFurySpirit[4],0x41303152)
        endif
    endif
    
    call TriggerSleepAction(14.5)
    
    call SetUnitInvulnerable(udg_WaterFurySpirit[4],true )
    call SetUnitAnimation(udg_WaterFurySpirit[4],"death")
    call RemoveUnit(udg_WaterFurySpirit[5])
    
    call DestroyTrigger(HealSharick)
    set HealSharick=null
    //you need to set 'healcaster' to null also
    set healcaster=null
    
    call UnitRemoveAbility(udg_WaterFurySpirit[4],0x4130314D)
    
    call TriggerSleepAction(1.5)
    call RemoveUnit(udg_WaterFurySpirit[4])
endfunction

//===========================================================================
function InitTrig_WaterHealingSpirit takes nothing returns nothing
    local trigger WaterHealingSpirit = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(WaterHealingSpirit,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(WaterHealingSpirit,Condition( function WaterHealingSpirit_Conditions))
    call TriggerAddAction(WaterHealingSpirit,function WaterHealingSpirit_Actions)
    set WaterHealingSpirit=null
endfunction

When you reference GetSpellTargetLoc() it creates a location handle that you must remove after, so it would have to be stored as a variable (local location loc=GetSpellTargetLoc()) but since you are using x and y coordinates you can just use the functions GetSpellTargetX() and GetSpellTargetY(). I corrected these errors in your script.

--I found a function that's a blizzard native and isn't highlighted by The Hive Workshop's JASS syntax.
 
Status
Not open for further replies.
Top