I use a dialog in my custom ability training system to "forget" abilities. This leaks hard, i do not know how to fix the leaks. Here's the code of my triggers.
This one is responsible for dialog creation:
and this one for catching the click on a button:
i have one more question. if i need to show this to 8 players, do i need arrays for 8 dialogs and 33 (4 options + "cancel") dialog buttons or 1 variable for a dialog and 5 variables for options are enough?
This one is responsible for dialog creation:
JASS:
function Trig_ForgetAbility_Conditions takes nothing returns boolean
if ( not ( GetItemTypeId(GetSoldItem()) == 'I017' ) ) then
return false
endif
return true
endfunction
function Trig_ForgetAbility_Actions takes nothing returns nothing
local integer i=0
local integer j=GetPlayerId(GetOwningPlayer(GetBuyingUnit()))
set udg_Dialog[j]=DialogCreate()
call DialogClear(udg_Dialog[j])
call DialogSetMessage(udg_Dialog[j],"Decrease level:")
loop
exitwhen i==5
if i<=3 then
if udg_AB_SYS_HeroSkills[(j*4)+i]!=0 then
set udg_DialogButton[(j*4)+i]=DialogAddButton(udg_Dialog[j],GetObjectName(udg_AB_SYS_HeroSkills[(j*4)+i]),0)
endif
endif
if i==4 then
set udg_DialogButton[33]=DialogAddButton(udg_Dialog[j],"Cancel",0)
endif
set i=i+1
endloop
call TriggerRegisterDialogEvent( gg_trg_ForgetAbilityButtonClick, udg_Dialog[j] ) //sys doesnt work properly w/o that
call RemoveItem(GetSoldItem())
call DialogDisplay(Player(j),udg_Dialog[j],true)
endfunction
function InitTrig_ForgetAbility takes nothing returns nothing
set gg_trg_ForgetAbility = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_ForgetAbility, EVENT_PLAYER_UNIT_SELL_ITEM )
call TriggerAddCondition( gg_trg_ForgetAbility, Condition( function Trig_ForgetAbility_Conditions ) )
call TriggerAddAction( gg_trg_ForgetAbility, function Trig_ForgetAbility_Actions )
endfunction
JASS:
function Trig_ForgetAbilityButtonClick_Actions takes nothing returns nothing
local button b=GetClickedButton()
local integer i=0
local integer j
local integer q=0
loop
exitwhen i>7
set j=0
loop
exitwhen j>4
if b==udg_DialogButton[(i*4)+j] then
set q=GetUnitAbilityLevel(udg_Hero[i],udg_AB_SYS_HeroSkills[(i*4)+j])
if q>1 then
call SetUnitAbilityLevel(udg_Hero[i],udg_AB_SYS_HeroSkills[(i*4)+j],q-1)
else
call UnitRemoveAbility(udg_Hero[i],udg_AB_SYS_HeroSkills[(i*4)+j])
set udg_AB_SYS_HeroSkills[(i*4)+j]=0
endif
set q=0
loop
exitwhen q>900
if udg_AB_SYS_HeroSkills[(i*4)+j]==udg_AB_SYS_ABI[q] then
call SetPlayerState(Player(i),PLAYER_STATE_RESOURCE_LUMBER,GetPlayerState(Player(i),PLAYER_STATE_RESOURCE_LUMBER)+2)
set q=900
endif
set q=q+1
endloop
call DialogDestroy(udg_Dialog[i])
set udg_Dialog[i]=null
endif
set j=j+1
endloop
set i=i+1
endloop
set b=null
endfunction
function InitTrig_ForgetAbilityButtonClick takes nothing returns nothing
local integer i=0
set gg_trg_ForgetAbilityButtonClick = CreateTrigger( )
loop
exitwhen i>7
call TriggerRegisterDialogEvent( gg_trg_ForgetAbilityButtonClick, udg_Dialog[i] )
set i=i+1
endloop
call TriggerAddAction( gg_trg_ForgetAbilityButtonClick, function Trig_ForgetAbilityButtonClick_Actions )
endfunction