• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Limit Summoned Unit number

Status
Not open for further replies.
Level 13
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:
plese use hidden tags... anyway you can make an integer which counts the current number of summoned units and save its value into the hashtable. also save the playerID into a variable rather than using a lot of GetPlayerID(GetOwningPlayer(caster))....

and what's the problem with your trigger? you just said that it don't work, but you did not tell what part does not work or whats the basic problem you have with it.
 
Level 13
Joined
Jul 26, 2008
Messages
1,009
Well so far everything on the spell works great except the limitation of the amount of demons summoned from thsi spell.

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.

Sorry about the lack of information/tags. I was in a bit of a hurry when I posted, some details slipped my mind. I'm editing the first post to fix that.

Oh and thanks :D This discussion has given me the idea to use the integer idea, and just make a seperate trigger where that integer is decreased if a demon is killed :D.
 
you should do this

JASS:
globals
    hashtable SDHash = InitHashtable()
    integer MAX = 900
    group array demonsmaxforSD[MAX] // I think that initializes the groups, not sure though but you need to initialize/create groups before you can use them...
endglobals

I think the problem you have is because you just add units to the group variable which you never created.
 
Status
Not open for further replies.
Top