- Joined
- Jul 26, 2008
- Messages
- 1,009
Alright I'm trying to limit the amount of summoned units that result from a spell that summons them upon death of a particular unit being targeted by the spell. However, I'm having some trouble doing it. This is my best failed attempt so far.
It's a lot like a Dark Conversion. I was thinking of using an Integer originally, but then I realized the integer would represent a false number if one of the demons was killed, so I forgoed that route and attempted to save every demon into a group, then count each demon individually by removing them one by one, saving them in a variable, then placing them back in that group by putting them back in by calling the variables they were stored in.
JASS:
globals
hashtable SDHash
group array demonsmaxforSD
endglobals
function Sumd_Timer takes nothing returns nothing
local timer tim = GetExpiredTimer()
local unit caster = LoadUnitHandle(SDHash, GetHandleId(tim), 1)
local unit target = LoadUnitHandle(SDHash, GetHandleId(tim), 2)
local unit temp
local unit array demon
local real damage = LoadReal(SDHash, GetHandleId(tim), 3)
local integer duration = LoadInteger(SDHash, GetHandleId(tim), 4)
local integer x = 1
call SetUnitState(target, UNIT_STATE_LIFE, GetUnitState(target, UNIT_STATE_LIFE) - damage)
if GetUnitState(target, UNIT_STATE_LIFE) >= 1 then
if duration == 10 and (GetUnitTypeId(target) == 'nvlk' or GetUnitTypeId(target) == 'nvlw' or GetUnitTypeId(target) == 'nvil' or GetUnitTypeId(target) == 'nvl2') then
call KillUnit(target)
set demon[1] = CreateUnitAtLoc(GetOwningPlayer(caster), 'hwt2', GetUnitLoc(target), bj_UNIT_FACING )
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl", demon[1], "origin"))
call GroupAddUnit(demonsmaxforSD[GetPlayerId(GetOwningPlayer(caster))], demon[1])
loop
set temp = FirstOfGroup(demonsmaxforSD[GetPlayerId(GetOwningPlayer(caster))])
exitwhen temp == null
set demon[x] = temp
set x = x + 1
if x >= 6 then
call KillUnit(demon[x])
endif
call GroupRemoveUnit(demonsmaxforSD[GetPlayerId(GetOwningPlayer(caster))], temp)
endloop
set x = 0
loop
set x = x + 1
exitwhen demon[x] == null
call GroupAddUnit(demonsmaxforSD[GetPlayerId(GetOwningPlayer(caster))], demon[x])
set demon[x] = null
endloop
call ReleaseTimer(tim)
elseif not ( GetUnitAbilityLevel(target, 'BNdc') > 0 ) then
call BJDebugMsg("Sleep is Off")
call IssueImmediateOrder(caster, "stop")
call ReleaseTimer(tim)
elseif duration == 10 or not ( GetUnitCurrentOrder(caster) == OrderId("magicleash") ) then
call UnitRemoveAbility( GetTriggerUnit(), 'BNdc' )
call ReleaseTimer(tim)
else
call SaveInteger(SDHash, GetHandleId(tim), 4, duration+1)
endif
else
call IssueImmediateOrder(caster, "stop")
call ReleaseTimer(tim)
endif
set caster = null
set target = null
endfunction
function DoActions_Sumd takes nothing returns nothing
local unit target = GetSpellTargetUnit()
local unit caster = GetTriggerUnit()
local unit dummy = CreateUnitAtLoc(GetOwningPlayer(caster), 'e002', GetUnitLoc(target), bj_UNIT_FACING )
local real damage = GetUnitState(target, UNIT_STATE_MAX_LIFE) * 0.01
local timer tim = NewTimer()
call UnitAddAbility( dummy, 'slsd' )
call SetUnitAbilityLevel( dummy, 'slsd', GetUnitAbilityLevel(caster, 'sumd' ))
call IssueTargetOrder( dummy, "sleep", target )
call UnitApplyTimedLife( dummy, 'slsd', 2.0 )
call SaveUnitHandle(SDHash, GetHandleId(tim), 1, caster)
call SaveUnitHandle(SDHash, GetHandleId(tim), 2, target)
call SaveReal(SDHash, GetHandleId(tim), 3, damage)
call SaveInteger(SDHash, GetHandleId(tim), 4, 0)
call TimerStart(tim, 1.0, true, function Sumd_Timer)
set caster = null
set target = null
set dummy = null
endfunction
function IsItsumd takes nothing returns boolean
return GetSpellAbilityId() == 'sumd'
endfunction
//===========================================================================
function InitTrig_SummonDemon takes nothing returns nothing
local trigger Sumd = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(Sumd, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
call TriggerAddCondition(Sumd, Condition(function IsItsumd))
call TriggerAddAction(Sumd, function DoActions_Sumd)
set SDHash = InitHashtable()
endfunction
Last edited: