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

[vJASS] Help with enumeration function

Status
Not open for further replies.
Level 2
Joined
Aug 11, 2009
Messages
22
Hello, I tried to create a simple trigger but ran into a problem. Apparently my "function Targets" or "function Enum" isn't right, I don't know why though (new to JASS and vJASS). It doesn't use the global unit U and therefore no units pass the check.

JASS:
scope IllusoryAssault initializer Init

//===============SETUP================

    globals
        private constant integer SPELL_ID = 'A000'
        private constant integer DUMMY_ID = 'h000'
        private constant integer DMG_DUMMY_ID = 'h001'
        private constant string SFX = "Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl"
        private constant damagetype D_TYPE = DAMAGE_TYPE_NORMAL
        private constant attacktype A_TYPE = ATTACK_TYPE_SIEGE
    endglobals
    
    
    private function AoE takes nothing returns real
    
        return 200.
    endfunction
    
    private function Damage takes integer lvl, integer hstr returns real
    
        return (lvl * 300. + 2. * hstr + 150.)/4
    endfunction
    
!!!    private function Targets takes unit target, unit U returns boolean
    
        return (GetWidgetLife(target) > 0.405) and (IsUnitAlly(target, GetOwningPlayer(U)) == false)
    endfunction    
    
//==============SETUP ENDS============    
    
    globals
        private hashtable Hash
        private group Group
        private unit U
    endglobals
    

!!!    private function Enum takes nothing returns boolean
        
        return Targets(GetFilterUnit(), U)
    endfunction
    
    
    private function Conditions takes nothing returns boolean
    
        return GetSpellAbilityId() == SPELL_ID 
    endfunction
    
        
    private function Timer2 takes nothing returns nothing
    
        local timer t2 = GetExpiredTimer()
        local unit u = LoadUnitHandle(Hash, GetHandleId(t2), 0)
        local real x = LoadReal(Hash, GetHandleId(t2), 1)
        local real y = LoadReal(Hash, GetHandleId(t2), 2)
        local real r = LoadReal(Hash, GetHandleId(t2), 3)
        local integer i
        local real dmg
        local unit fog
        local unit d
        
        call BJDebugMsg(R2S(r))
        call DestroyEffect(AddSpecialEffect(SFX, x, y))
        set U = u
        call BJDebugMsg(GetUnitName(U))
        call GroupEnumUnitsInRange(Group, x, y, AoE, Condition(function Enum))
        set i = CountUnitsInGroup(Group)
        if (i > 0) then
            call BJDebugMsg(I2S(i))
            set dmg = r / i 
            call BJDebugMsg(R2S(dmg))
            call CreateUnit(GetOwningPlayer(u), 'hfoo', x, y, 0.)
            set d = GetLastCreatedUnit()
            loop
                set fog = FirstOfGroup(Group)
                exitwhen (fog == null)
                call UnitDamageTarget(u, fog, dmg, false, false, ATTACK_TYPE_SIEGE, DAMAGE_TYPE_NORMAL, null)
                call GroupRemoveUnit(Group, fog)
            endloop
        endif
        
        call DestroyTimer(t2)
        set t2 = null
        set u = null
    endfunction
    
    
    private function Timer1 takes nothing returns nothing
    
        local timer t = GetExpiredTimer()
        local unit u = LoadUnitHandle(Hash, GetHandleId(t), 0)
        
        call SetUnitTimeScale(u, 1.)
        call SetUnitFlyHeight(u, 0., 1000.)
        
        call DestroyTimer(t)
        set t = null
        set u = null
    endfunction
    
    
    private function Actions takes nothing returns nothing
        
        local unit u = GetTriggerUnit()
        local integer lvl = GetUnitAbilityLevel(u, SPELL_ID)
        local integer hstr = GetHeroStr(u, true)
        local timer t = CreateTimer()
        local timer t2 = CreateTimer()
        
        call UnitAddAbility(u, 'Arav')
        call UnitRemoveAbility(u, 'Arav')
        call SaveUnitHandle(Hash, GetHandleId(t), 0, u)
        call SaveUnitHandle(Hash, GetHandleId(t2), 0, u)
        call SaveReal(Hash, GetHandleId(t2), 1, GetSpellTargetX())
        call SaveReal(Hash, GetHandleId(t2), 2, GetSpellTargetY())
        call SaveReal(Hash, GetHandleId(t2), 3, Damage(lvl, hstr))
        call SetUnitTimeScale(u, 0.2)
        call SetUnitFlyHeight(u, 300., 200.)
        call TimerStart(t, 1.3, false, function Timer1)
        call TimerStart(t2, 1.8, false, function Timer2)
        
        set u = null
        set t = null
        set t2 = null
    endfunction
    

    private function Init takes nothing returns nothing
        local trigger RecklessAssaultTrg = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(RecklessAssaultTrg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition(RecklessAssaultTrg, Condition( function Conditions ) )
        call TriggerAddAction( RecklessAssaultTrg, function Actions )
        
        //setting globals
        set Hash = InitHashtable()
        set Group = CreateGroup()
        
        //preloading effects
        call Preload(SFX)
        
        
                
        
    endfunction    
    
    
endscope
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Also store GetOwningPlayer(u) in a variable.
You are calling it (as for now) every time on the enumeration.

Just go directly into the loop (after the enumeration) and do an if statement inside it.
Create another group on which you will deal the damage.
If the unit from group1 is an enemy etc, then add it to the other group and increase i by 1.

About why U didnt work, idk.
However, try to avoid multiple variables with the same name.
 
Status
Not open for further replies.
Top