• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Unit array not working

Status
Not open for further replies.
Level 7
Joined
Apr 5, 2011
Messages
245
Here is work code:
JASS:
//========================
//=== SpellSpiritScout ===
//======== v1.000 ========

library SpellSpiritScout requires Assist, Cast, Teams, TimedLife

//=== Settings ===
globals
    private constant integer ABILCODE = 'X108'
    private constant integer SUMMONER = 'd003'
    private constant integer SUMMON_ABILITY = 'X121'
    private constant integer SUMMON_ORDER = 852274
    private constant string ILLUSION_SFX = "SpiritScout.mdl"
    private constant string ILLUSION_SFX_ATTACH_POINT = "origin"
    private constant string EXPLOSION_SFX = "SpiritScoutExplosion.mdl"
//----------------
    private constant real HERO_HUNT_AOE = 600
    private constant real EXPLOSION_AOE = 350
    private constant real ACQUIRE_RANGE = 99999
    private constant real SUMMONER_LIFETIME = 5
//----------------
    private constant unittype SPEC_ILLUSION_UNIT_TYPE = UNIT_TYPE_SAPPER
endglobals
    struct SpellSpiritScout extends array
        private static real array AOE
        private static integer array NUM
        private static real array DURATION
        private static real array SPAWN_TIME
        private static real array DAMAGE
        static if LIBRARY_ManaLoss then
            private static real array MANA_COST
        endif
        private static method onInit takes nothing returns nothing
            set AOE[1] = 800
            set AOE[2] = 750
            set AOE[3] = 700
            set AOE[4] = 650
            set NUM[1] = 1
            set NUM[2] = 5
            set NUM[3] = 6
            set NUM[4] = 6
            set DURATION[1] = 5
            set DURATION[2] = 5
            set DURATION[3] = 5
            set DURATION[4] = 5
            set SPAWN_TIME[1] = .6
            set SPAWN_TIME[2] = .65
            set SPAWN_TIME[3] = .7
            set SPAWN_TIME[4] = .75
            set DAMAGE[1] = 50
            set DAMAGE[2] = 80
            set DAMAGE[3] = 110
            set DAMAGE[4] = 140
            static if LIBRARY_ManaLoss then
                set MANA_COST[1] = 110
                set MANA_COST[2] = 120
                set MANA_COST[3] = 130
                set MANA_COST[4] = 140
            endif
//================
            set scout = scout.create()
        endmethod
        
        private static indexCarrier scout
        private static integer array caster_id
        private static integer array level
        private static real array x
        private static real array y
        private static unit array summoner
        private static integer array count
        private static group array g
        private static timer array t
        
        private static integer workInteger
        private static real workReal
        private static player workPlayer
        private static unit workUnit
        
        private static method summon takes nothing returns nothing
            local timer t = GetExpiredTimer()
            set workInteger = 0
            loop
                exitwhen thistype.t[workInteger] == t //or workInteger == scout.count
                set workInteger = workInteger + 1
            endloop
            /*if workInteger == scout.count then
                call BJDebugMsg("FUCK")
                return
            endif*/
            call IssueTargetOrderById(summoner[workInteger], SUMMON_ORDER, Unit[caster_id[workInteger]])
            set t = null
        endmethod
        
        private static method hunt takes nothing returns nothing
            local unit u = GetEnumUnit()
            set workInteger = GetUnitUserData(u)
            if UnitData.Unit[workInteger] == null then
                set UnitData.Unit[workInteger] = Assist.workUnit
                call IssueTargetOrder(u, "attack", Assist.workUnit)
            endif
            set u = null
        endmethod
        
        static method closestHeroFilter takes nothing returns boolean
            local unit u = GetFilterUnit()
            if IsUnitEnemy(u, workPlayer) and GetWidgetLife(u) > 0 and IsUnitType(u, UNIT_TYPE_HERO) then
                set u = null
                return true
            endif
            set u = null
            return false
        endmethod

        static method onSummonUnit takes nothing returns nothing
            local real a
            local integer i
            set Assist.workUnit = GetSummoningUnit()
            if GetUnitTypeId(Assist.workUnit) == SUMMONER then
                set workInteger = GetUnitUserData(Assist.workUnit)
                set Assist.workUnit = GetTriggerUnit()
                set i = GetUnitUserData(Assist.workUnit)
                set workReal = GetRandomReal(0, AOE[level[workInteger]])
                set a = GetRandomReal(0, 6.283)
                call SetUnitPosition(Assist.workUnit, x[workInteger] + workReal * Cos(a), y[workInteger] + workReal * Sin(a))
                call SetUnitAnimation(Assist.workUnit, "stand")
                call DestroyEffect(AddSpecialEffectTarget(ILLUSION_SFX, Assist.workUnit, ILLUSION_SFX_ATTACH_POINT))
                call SetUnitAcquireRange(Assist.workUnit, ACQUIRE_RANGE)
                call UnitAddType(Assist.workUnit, SPEC_ILLUSION_UNIT_TYPE)
                call GroupAddUnit(g[workInteger], Assist.workUnit)
                call TimedLife.apply(Assist.workUnit, DURATION[level[workInteger]])
                set UnitData.Integer[i] = workInteger
                set UnitData.Unit[i] = null
                if count[workInteger] == NUM[level[workInteger]] then
                    call scout.unregister(workInteger)
                    //set caster[workInteger] = null
                    set summoner[workInteger] = null
                    call PauseTimer(t[workInteger])
                else
                    set count[workInteger] = count[workInteger] + 1
                endif
                //Hero search
                set workPlayer = GetTriggerPlayer()
                set Assist.workUnit = GetClosestUnit(GetUnitX(Assist.workUnit), GetUnitY(Assist.workUnit), HERO_HUNT_AOE, function thistype.closestHeroFilter)
                if Assist.workUnit != null then
                    call ForGroup(g[workInteger], function thistype.hunt)
                endif
            endif
        endmethod
        
        private static method affect takes nothing returns boolean
            set Assist.workUnit = GetFilterUnit()
            call BJDebugMsg("AFFECT")
            if IsUnitEnemy(Assist.workUnit, workPlayer) and GetWidgetLife(Assist.workUnit) > 0 and not IsUnitType(Assist.workUnit, UNIT_TYPE_STRUCTURE) and not IsUnitType(Assist.workUnit, UNIT_TYPE_MAGIC_IMMUNE) then
                call BJDebugMsg("NICE")
                //call DealDamage(caster[workInteger], Assist.workUnit, workReal, MAGIC)
                call DealDamage(summoner[workInteger], Assist.workUnit, 100, MAGIC)
            endif
            return false
        endmethod
        
        static method onUnitDeath takes nothing returns nothing
            local real x
            local real y
            local integer i
            if GetKillingUnit() != null then
                set Assist.workUnit = GetTriggerUnit()
                if IsUnitIllusion(Assist.workUnit) and IsUnitType(Assist.workUnit, SPEC_ILLUSION_UNIT_TYPE) then
                    set x = GetUnitX(Assist.workUnit)
                    set y = GetUnitY(Assist.workUnit)
                    set i = GetUnitUserData(Assist.workUnit)
                    set workInteger = UnitData.Integer[i]
                    call GroupRemoveUnit(g[workInteger], Assist.workUnit)
                    set workReal = DAMAGE[level[workInteger]]
                    set workPlayer = GetTriggerPlayer()
                    set workUnit = Unit[caster_id[workInteger]]
                    call KillUnit(workUnit)
                    call GroupEnumUnitsInRange(Assist.workGroup, x, y, EXPLOSION_AOE, function thistype.affect)
                    call DestroyEffect(AddSpecialEffect(EXPLOSION_SFX, x, y))
                endif
            endif
        endmethod

        static method onSpellEffect takes nothing returns nothing
            if GetSpellAbilityId() == ABILCODE then
                set workInteger = scout.register()
                set summoner[workInteger] = CreateUnit(Teams.headPlayer[TeamPlayer(GetTriggerPlayer())], SUMMONER, 0, 0, 0)
                set Assist.workUnit = GetTriggerUnit()
                set caster_id[workInteger] = GetUnitUserData(Assist.workUnit)
                set level[workInteger] = GetUnitAbilityLevel(Assist.workUnit, ABILCODE)
                set x[workInteger] = GetSpellTargetX()
                set y[workInteger] = GetSpellTargetY()
                call SetUnitUserData(summoner[workInteger], workInteger)
                call UnitApplyTimedLife(summoner[workInteger], 0, SUMMONER_LIFETIME)
                call UnitAddAbility(summoner[workInteger], SUMMON_ABILITY)
                call SetUnitAbilityLevel(summoner[workInteger], SUMMON_ABILITY, level[workInteger])
                if g[workInteger] == null then
                    set g[workInteger] = CreateGroup()
                    set t[workInteger] = CreateTimer()
                else
                    call GroupClear(g[workInteger])
                endif
                set count[workInteger] = 1
                call TimerStart(t[workInteger], SPAWN_TIME[level[workInteger]], true, function thistype.summon)
                //Advanced Research
                static if LIBRARY_SpellAdvancedResearch and LIBRARY_SpellPredatorSpirit then
                    if GetUnitAbilityLevel(Assist.workUnit, SpellAdvancedResearch.abilcode) != 0 then
                        call SpellAdvancedResearch.setPredatorSpirit()
                    endif
                endif
            endif
        endmethod
    endstruct
endlibrary
What I am doing here:
1. I target area
2. Summon illusions
3. Illusions explode upon death
This works!
But WTF, after 2 hours of idiotic debugging when I just replaced everywhere unit array caster by integer array caster_id and caster[x] by Unit[caster_id[x]]. (Using standard indexing) So, this means, unit is changed?? In which place I do it??
:vw_wtf:
 
Status
Not open for further replies.
Top