- Joined
- Jan 9, 2005
- Messages
- 2,127
I'm trying to make a spell that counts up the number of summoned units and staggers their index backwards when the limit is reached or when summoned unit dies, kinda like how Carrion Beetles work, except with wards. But it doesn't work as intended - the limit on summoned units seems to 'increase' if I already have the maximum amount of units (Most likely that 1 ward is getting left behind when I cycle through the wards, but I not very familiar with this method)
Also I'm using 2D arrays.
Also I'm using 2D arrays.
JASS:
library SummonLimit initializer init
globals
private trigger HL_onLearn = CreateTrigger()
private trigger HL_onRetrain = CreateTrigger()
private trigger HL_onSummon = CreateTrigger()
private trigger HL_onDeath = CreateTrigger()
private integer array Maximum
private integer array CurrentNumber
private integer array OrderIndex
private unit array Minion
private unit array Summoner
private integer array Vision_Abil
private integer array TrueSight_Abil
private boolean array IsExcluded
endglobals
/*======== ACTIONS ========*/
//onLearn
function Trig_HiddenLantern_onLearn takes nothing returns boolean
local unit source = null
local integer id = 0
local integer Level = 0
if GetLearnedSkill() == 'Afhl' then
set source = GetTriggerUnit()
set id = GetUnitUserData(source)
set Level = GetUnitAbilityLevel(source, 'Afhl')
set Maximum[id] = Level + 1
call BJDebugMsg(I2S(Maximum[id]))
if Level == 1 then
set Vision_Abil[id] = 'Als1'
set TrueSight_Abil[id] = 'Ats1'
elseif Level == 2 then
set Vision_Abil[id] = 'Als2'
set TrueSight_Abil[id] = 'Ats2'
elseif Level == 3 then
set Vision_Abil[id] = 'Als3'
set TrueSight_Abil[id] = 'Ats3'
endif
set source = null
endif
return false
endfunction
//onRetrain
function Trig_HiddenLantern_onRetrain takes nothing returns boolean
local unit source = null
local integer id = 0
local integer WHid = 0 //WH for Width and Height
local integer iLoop = 0
if GetItemTypeId(GetManipulatedItem()) == 'tret' and GetUnitAbilityLevel(GetTriggerUnit(), 'Afhl') > 0 then
set source = GetTriggerUnit()
set id = GetUnitUserData(source)
loop
exitwhen iLoop > CurrentNumber[id]
set iLoop = iLoop + 1
set WHid = id * Maximum[id] + iLoop
call UnitApplyTimedLife(Minion[WHid], 'BTLF', 0.01)
set Minion[WHid] = null
endloop
set Maximum[id] = 0
set CurrentNumber[id] = 0
set source = null
endif
return false
endfunction
//onSummon
function Trig_HiddenLantern_onSummon takes nothing returns boolean
local unit ward = GetTriggerUnit()
local integer id = 0
local integer WHid = 0
local integer iLoop = 0
if GetUnitTypeId(ward) == 'ffln' then
set id = GetUnitUserData(GetSummoningUnit())
call UnitAddAbility(ward, Vision_Abil[id])
call UnitAddAbility(ward, TrueSight_Abil[id])
if CurrentNumber[id] < Maximum[id] then
set CurrentNumber[id] = CurrentNumber[id] + 1
set WHid = id * Maximum[id] + CurrentNumber[id]
set Minion[WHid] = ward
//set OrderIndex[id] = OrderIndex[id] + 1
//set OrderIndex[WHid] = OrderIndex[id]
else
set WHid = id * Maximum[id] + 1
call UnitApplyTimedLife(Minion[WHid], 'BTLF', 0.01)
set Minion[WHid] = null
set Summoner[GetUnitUserData(Minion[WHid])] = null
set IsExcluded[GetUnitUserData(Minion[WHid])] = true
loop
set iLoop = iLoop + 1
exitwhen iLoop == Maximum[id]
set WHid = id * Maximum[id] + iLoop
set Minion[WHid] = Minion[WHid + 1]
endloop
//set WHid = id * Maximum[id] + Maximum[id]
set Minion[WHid + 1] = ward
endif
set Summoner[GetUnitUserData(ward)] = GetSummoningUnit()
call BJDebugMsg("Max: " + I2S(Maximum[id]))
call BJDebugMsg("CN: " + I2S(CurrentNumber[id]))
endif
set ward = null
return false
endfunction
//onDeath
function Trig_HiddenLantern_onDeath takes nothing returns boolean
local unit ward = null
local integer id = 0
local integer ward_id = 0
local integer WHid = 0
local integer iLoop = 0
local integer NewIndex = 0
call BJDebugMsg("onDeath")
if GetUnitTypeId(GetTriggerUnit()) == 'ffln' then
set ward = GetTriggerUnit()
set ward_id = GetUnitUserData(ward)
set id = GetUnitUserData(Summoner[ward_id])
if IsExcluded[ward_id] then
set IsExcluded[ward_id] = false
else
loop
set iLoop = iLoop + 1
exitwhen iLoop == CurrentNumber[id]
set WHid = id * Maximum[id] + iLoop
if not UnitAlive(Minion[WHid]) then
set NewIndex = iLoop
loop
set NewIndex = NewIndex + 1
exitwhen NewIndex == CurrentNumber[id]
set WHid = id * Maximum[id] + iLoop
set Minion[WHid] = Minion[WHid + 1]
endloop
endif
endloop
set Summoner[ward_id] = null
set CurrentNumber[id] = CurrentNumber[id] - 1
endif
set ward = null
endif
return false
endfunction
/*======== EVENTS ========*/
//EVENT onLearn
function InitTrig_HL_onLearn takes nothing returns nothing
call TriggerRegisterAnyUnitEventBJ( HL_onLearn, EVENT_PLAYER_HERO_SKILL )
call TriggerAddCondition( HL_onLearn, function Trig_HiddenLantern_onLearn )
endfunction
//EVENT onRetrain
function InitTrig_HL_onRetrain takes nothing returns nothing
call TriggerRegisterAnyUnitEventBJ( HL_onRetrain, EVENT_PLAYER_UNIT_USE_ITEM )
call TriggerAddCondition( HL_onRetrain, function Trig_HiddenLantern_onRetrain )
endfunction
//EVENT onSummon
function InitTrig_HL_onSummon takes nothing returns nothing
call TriggerRegisterAnyUnitEventBJ( HL_onSummon, EVENT_PLAYER_UNIT_SUMMON )
call TriggerAddCondition( HL_onSummon, function Trig_HiddenLantern_onSummon )
endfunction
//EVENT onSummon
function InitTrig_HL_onDeath takes nothing returns nothing
call TriggerRegisterAnyUnitEventBJ( HL_onDeath, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( HL_onDeath, function Trig_HiddenLantern_onDeath )
endfunction
private function init takes nothing returns nothing
call InitTrig_HL_onDeath()
call InitTrig_HL_onRetrain()
call InitTrig_HL_onSummon()
call InitTrig_HL_onLearn()
endfunction
endlibrary