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

[Solved] GroupEnumUnitsInRange half working

Status
Not open for further replies.
Level 6
Joined
Jan 13, 2013
Messages
129
Alright so when I was using GroupEnumUnitsInRange everything was fine. Suddenly new triggers utilizing it won't work UNTIL a trigger that was previously written, such as Blizzzard, is called. I don't understand at all whats happening.

Edit: Also my current work around is making a unit cast blizzard at the start of the map and get removed afterward. It works in any player slot (0-11) however it doesn't work in neutral slots. So weird.
vJASS:
//TESH.scrollpos=20
//TESH.alwaysfold=0
scope SelfDestruct initializer Init

globals
    private constant integer ABILID = 'A0IN'
endglobals

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ABILID
endfunction

private function Actions takes nothing returns nothing
	local unit hero
	local unit target
    local unit u = null
	local group g = CreateGroup()
	set hero = GetTriggerUnit()
	set target = GetSpellTargetUnit()
	call GroupEnumUnitsInRange(g,GetUnitX(target),GetUnitY(target),220,Condition(function EnemyAliveFilter))
    loop
            set u = FirstOfGroup(g)
            exitwhen u == null
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Weapons\\FireBallMissile\\FireBallMissile.mdl",u,"chest"))
            call Damage_Spell(hero,u,GetUnitAbilityLevel(hero,ABILID)*GetUnitState(target,UNIT_STATE_MAX_LIFE)*0.04+GetHeroInt(hero,true)*0.4)
            call GroupRemoveUnit(g,u)
   endloop
    call DestroyGroup(g)
    set g = null
endfunction

private function Init takes nothing returns nothing
    local trigger Trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(Trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(Trig,Condition(function Conditions))
    call TriggerAddAction(Trig,function Actions)
endfunction

endscope

vJASS:
//TESH.scrollpos=20
//TESH.alwaysfold=0
scope SelfDestruct initializer Init

globals
    private constant integer ABILID = 'A0IN'
endglobals

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ABILID
endfunction

private function Actions takes nothing returns nothing
	local unit hero
	local unit target
    local unit u = null
	set hero = GetTriggerUnit()
	set target = GetSpellTargetUnit()
	call GroupEnumUnitsInRange(G2,GetUnitX(target),GetUnitY(target),220,Condition(function EnemyAliveFilter))
    loop
            set u = FirstOfGroup(G2)
            exitwhen u == null
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Weapons\\FireBallMissile\\FireBallMissile.mdl",u,"chest"))
            call Damage_Spell(hero,u,GetUnitAbilityLevel(hero,ABILID)*GetUnitState(target,UNIT_STATE_MAX_LIFE)*0.04+GetHeroInt(hero,true)*0.4)
            call GroupRemoveUnit(G2,u)
   endloop
endfunction

private function Init takes nothing returns nothing
    local trigger Trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(Trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(Trig,Condition(function Conditions))
    call TriggerAddAction(Trig,function Actions)
endfunction

endscope

vJASS:
//TESH.scrollpos=20
//TESH.alwaysfold=0
scope Blizzzard initializer Init

globals
    private constant integer ABILID = 'A0HU'
    private constant string PROJID = "Blizzzard"
endglobals

private function RemoveBlizzzDummy takes unit dummy returns nothing
    call TriggerSleepAction(10)
    call RemoveUnit(dummy)
endfunction

private function HitConditions takes nothing returns boolean
    return Projectile_Id == PROJID
endfunction

private function HitActions takes nothing returns nothing
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Weapons\\LichMissile\\LichMissile.mdl",Projectile_HitUnit,"chest"))
    call Damage_Spell(Projectile_Source,Projectile_HitUnit,GetUnitAbilityLevel(Projectile_Source,ABILID)*5+GetHeroAgi(Projectile_Source,true)*0.15)
endfunction

private struct Data
    unit caster
    unit blizzard
    integer waves
    integer ticks
endstruct

private function Core takes nothing returns boolean
    local Data d = TT_GetData()
    local Projectile p
	local integer b
    local unit u = null
	local unit dummy = d.blizzard
		call UnitAddAbility(dummy,'A0HV')	
		call IssuePointOrderLoc(dummy,"blizzard",GetUnitLoc(dummy))
    if d.ticks > 0 and d.waves > 0 then
        set P = GetOwningPlayer(d.caster)
	
        call GroupEnumUnitsInRange(G2,GetUnitX(d.blizzard),GetUnitY(d.blizzard),200,Condition(function EnemyAliveFilter))
        if CountUnitsInGroup(G2) > 0 then
			set b = d.waves
			loop
				exitwhen b == 0
//				call IssuePointOrderLoc(dummy,"blizzard",GetUnitLoc(dummy))
				    loop
						set u = FirstOfGroup(G2)
						exitwhen u == null
						set p = Projectile.create()
						call p.ProjectileSetId(PROJID)
						call p.ProjectileSetModel("Abilities\\Weapons\\LichMissile\\LichMissile.mdl",255,255,255,255,0.8)
						call p.ProjectileTargetHoming(d.caster,GetUnitX(d.blizzard),GetUnitY(d.blizzard),20,u,22)
						call GroupRemoveUnit(G2,u)
					endloop
	
				set b = b - 1
			endloop
        endif
    else
		set dummy = null
	    call RemoveBlizzzDummy.execute(dummy)
        call RemoveUnit(d.blizzard)
        call d.destroy()
        return true
    endif
//	call IssuePointOrderLoc(dummy,"blizzard",GetUnitLoc(dummy))	
    set d.ticks = d.ticks - 1
    return false
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ABILID
endfunction

private function Actions takes nothing returns nothing
    local Data d = Data.create()
    local unit caster = GetTriggerUnit()
    set d.caster = caster
    set d.blizzard = CreateUnit(Player(bj_PLAYER_NEUTRAL_VICTIM),'dumy',GetSpellTargetX(),GetSpellTargetY(),GetRandomReal(0,360))
//    set d.blizzard = CreateUnit(GetOwningPlayer(caster),'dumy',GetSpellTargetX(),GetSpellTargetY(),GetRandomReal(0,360))
    set d.waves = R2I(1+(GetHeroInt(caster,true))*0.1)
    set d.ticks = R2I(1+(GetHeroInt(caster,true))*0.1)
    call TT_StartEx(function Core,d,1)
    set caster = null
endfunction

private function Init takes nothing returns nothing
    local trigger Trig = CreateTrigger()
    local trigger Hit = CreateTrigger()
    call TriggerRegisterEventProjectileHit(Hit)
    call TriggerAddCondition(Hit,Condition(function HitConditions))
    call TriggerAddAction(Hit,function HitActions)
    call TriggerRegisterAnyUnitEventBJ(Trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(Trig,Condition(function Conditions))
    call TriggerAddAction(Trig,function Actions)
endfunction

endscope
 
Last edited:
Level 11
Joined
Dec 19, 2012
Messages
411
Within "Blizzard" trigger, your trigger event is call TriggerRegisterEventProjectileHit(Hit)

Within "SelfDestruct" trigger, your group looping action have call Damage_Spell()

I'm suspecting call Damage_Spell() triggers the event of call TriggerRegisterEventProjectileHit(Hit). You are using both same group, which is G2, overwrite the unit data in G2. Try to create another group variable and use it in "Blizzard" trigger and see is problem resolve.
 
Level 6
Joined
Jan 13, 2013
Messages
129
call Damage_Spell() should not trigger call TriggerRegisterEventProjectileHit(Hit) as they are completely different systems and work together fine in other triggers or in the blizzard trigger itself. To clarify the Blizzard trigger works PERFECTLY, its the others that do not, that is until Blizzard is called once.

Edit: Jeez this bug is happening with another skill and another trigger now. This one won't work until another one that uses GetUnitX is called.
vJASS:
//TESH.scrollpos=0
//TESH.alwaysfold=0
//! runtextmacro BuffType("SippinPinaColadas")
    //! runtextmacro SetBuffName("Sippin' Piña colada")
    //! runtextmacro SetBuffAlignment("POSITIVE")
    //! runtextmacro SetBuffTooltip("Off the coast of Hellwaii.")
    //! runtextmacro SetBuffIcon("ReplaceableTextures\\CommandButtons\\BTNMartini.blp")
//! runtextmacro BuffStruct()
    unit caster
    unit target
    integer abilId
    effect sfx
	real ux
	real uy
    method onCreate takes nothing returns nothing
        set this.abilId = BuffAbilId
        set this.caster = BuffCaster
        set this.target = BuffTarget
		set this.ux = GetUnitX(BuffTarget)
		set this.uy = GetUnitY(BuffTarget)
    endmethod
    method onApply takes nothing returns nothing
        call SetUnitPosition(this.caster,GetRectCenterX(gg_rct_PersonalHell),GetRectCenterY(gg_rct_PersonalHell))
    endmethod
    method onRemove takes nothing returns nothing
        call SetUnitPosition(this.caster,this.ux,this.uy)
    endmethod
//! runtextmacro EndBuff()
vJASS:
//TESH.scrollpos=0
//TESH.alwaysfold=0
//! runtextmacro DurationBuff("SippinPinaColadas")
scope Hell initializer Init

globals
    private constant integer ABILID = 'A0IS'
	private constant integer FOUNTAIN = 'n00H'
endglobals

function DestroyColadas takes BuffStruct whatBuff returns nothing
    if whatBuff.getType()==SippinPinaColadas.typeid then
        call whatBuff.setUnit(null)
    endif
endfunction

private function unConditions takes nothing returns boolean
    return OrderId2String(GetIssuedOrderId()) == "manashieldoff" and GetUnitAbilityLevel(GetTriggerUnit(),ABILID) > 0
endfunction

private function unActions takes nothing returns nothing
	local unit caster = GetTriggerUnit()
    call BuffList[caster].forEachBuff(BUFF_ALIGNMENT_POSITIVE, DestroyColadas)
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ABILID
endfunction

private function Actions takes nothing returns nothing
	local unit caster = GetTriggerUnit()
	call AddBuffSippinPinaColadas(caster,caster,GetUnitAbilityLevel(caster,ABILID)*6,false)
endfunction

private function SConditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == FOUNTAIN and GetOwningPlayer(GetTriggerUnit()) == Player(PLAYER_NEUTRAL_PASSIVE)
endfunction

private function SActions takes nothing returns nothing
	call SetUnitOwner(GetTriggerUnit(),GetTriggerPlayer(),false)
endfunction

private function DConditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == FOUNTAIN and GetTriggerPlayer() == GetOwningPlayer(GetTriggerUnit())
endfunction

private function DActions takes nothing returns nothing
	call SetUnitOwner(GetTriggerUnit(),Player(PLAYER_NEUTRAL_PASSIVE),false)
endfunction

private function Init takes nothing returns nothing
    local trigger Select = CreateTrigger()
	local trigger Trig = CreateTrigger()
	local trigger Trig3 = CreateTrigger()
	local trigger Unselect = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(Select,EVENT_PLAYER_UNIT_SELECTED)
    call TriggerAddCondition(Select,Condition(function SConditions))
    call TriggerAddAction(Select,function SActions)
    call TriggerRegisterAnyUnitEventBJ(Unselect,EVENT_PLAYER_UNIT_SELECTED)
    call TriggerAddCondition(Unselect,Condition(function DConditions))
    call TriggerAddAction(Unselect,function DActions)
    call TriggerRegisterAnyUnitEventBJ(Trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerRegisterAnyUnitEventBJ(Trig3,EVENT_PLAYER_UNIT_ISSUED_ORDER)
    call TriggerAddCondition(Trig,Condition(function Conditions))
    call TriggerAddAction(Trig,function Actions)
    call TriggerAddCondition(Trig3,Condition(function unConditions))
    call TriggerAddAction(Trig3,function unActions)
endfunction

endscope

vJASS:
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope Mortality initializer Init

globals
    private constant integer ABILID = 'A07P'
endglobals

private function Conditions2 takes nothing returns boolean
    return GetSpellAbilityId() == ABILID
endfunction

private function Actions2 takes nothing returns nothing
    local integer i = GetPlayerTypedUnitCount(GetTriggerPlayer(),"Twistclaw",false,false)
    local unit target = GetSpellTargetUnit()
    local unit caster = GetTriggerUnit()
	local unit summon
	if BoilingBlood.isOn(target) then
		call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl",target,"chest"))
		set summon = CreateUnit(GetOwningPlayer(caster),'h027',GetUnitX(target),GetUnitY(target),GetUnitFacing(caster))
		call Status[summon].modHealthBonus(R2I(2.5*GetHeroInt(caster,true)+45*GetUnitAbilityLevel(caster,ABILID)))
        call Status[summon].modDamageBonus(R2I(0.12*GetHeroStr(caster,true)+2*GetUnitAbilityLevel(caster,ABILID)))
        call Status[summon].modHealthRegenBonus(R2I(0.02*GetHeroAgi(caster,true)+1*GetUnitAbilityLevel(caster,ABILID)))
		call UnitApplyTimedLife(summon,'BTLF',100.00)
	endif
	call Damage_Spell(caster,target,GetUnitState(caster,UNIT_STATE_MAX_LIFE)*0.15)
    set target = null
    set caster = null
endfunction

private function Conditions takes nothing returns boolean
    return GetUnitTypeId(GetSummonedUnit()) == 'h06L'
endfunction

private function Actions takes nothing returns nothing
    local integer i = GetPlayerTypedUnitCount(GetTriggerPlayer(),"Twistclaw",false,false)
    local unit summon
    local unit caster = GetSummoningUnit()
    loop
        exitwhen i >= 6
        set summon = CreateUnit(GetOwningPlayer(caster),'h026',GetUnitX(GetSummonedUnit()),GetUnitY(GetSummonedUnit()),GetUnitFacing(caster))
        call Status[summon].modHealthBonus(R2I(1*GetHeroInt(caster,true)+45*GetUnitAbilityLevel(caster,ABILID)))
        call Status[summon].modDamageBonus(R2I(0.08*GetHeroStr(caster,true)+2*GetUnitAbilityLevel(caster,ABILID)))
        call Status[summon].modArmorBonus(R2I(0.02*GetHeroAgi(caster,true)+1*GetUnitAbilityLevel(caster,ABILID)))
        call UnitApplyTimedLife(summon,'BTLF',100.00)
        set i = i + 1
    endloop
    set summon = null
    set caster = null
endfunction

private function Init takes nothing returns nothing
    local trigger Trig = CreateTrigger()
	local trigger Trig2 = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(Trig,EVENT_PLAYER_UNIT_SUMMON)
    call TriggerAddCondition(Trig,Condition(function Conditions))
    call TriggerAddAction(Trig,function Actions)
    call TriggerRegisterAnyUnitEventBJ(Trig2,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(Trig2,Condition(function Conditions2))
    call TriggerAddAction(Trig2,function Actions2)
endfunction

endscope

I'm starting to think some data in this map is corrupted.
Edit: Oh god its even worse than I thought, the first one only functions after if BoilingBlood.ison part fires. I feel like I'm losing my mind.
 
Last edited:
Level 6
Joined
Jan 13, 2013
Messages
129
Okay so I tried one more attempt at fixing this before uploading it and huzzah, I was just coding sloppily. After correctly setting values for the projectile system and buff systems on each ability they work (albeit still requiring the blizzard fix). I'm fine with leaving the blizzard fix in place for now and just trying to get better at coding. Thank you for trying to help out.
 
Level 7
Joined
Oct 19, 2015
Messages
286
Really? You're fine with leaving that "fix"? Even though it's not a fix at all and the map is not going to work correctly once you try it in multiplayer?

I'm guessing your problem is in your custom EnemyAliveFilter function. I can't say this for certain since you didn't post the function, but I'm guessing you need to add set P = GetOwningPlayer( hero ) before doing the group enum, like you do in the Blizzard trigger.
 
Status
Not open for further replies.
Top