first struct spell not working.

shiFt

Member
Reaction score
8
I got this spell framework from a spell that KingKing helped me make a while ago, so i chopped the struct stuff and tried to make another spell but it doesn't work, and I don't know why. Caster goes invisible, and is able to run through units, damages all units in a small radius around the hero.

JASS:
 scope WW initializer Init

    globals 
        private constant integer SPELL_ID = 'A01X'
        private hashtable ht = InitHashtable()
    endglobals
    
    private struct Data
        unit cs
        real x
        real y
        player p
        real dur
        integer ticks
        integer timeScaleTicks
        timer t
        group g
        real dmg
    endstruct
    
    globals
        private unit U
        private Data D
        private real X
        private real Y
        private integer array TimerData
        private conditionfunc cf
    endglobals
    
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID
    endfunction

    private function Effect2 takes nothing returns boolean
        set U = GetFilterUnit()
        if GetWidgetLife(U) > .405 and IsUnitEnemy(U,D.p) and IsUnitType(U,UNIT_TYPE_STRUCTURE) == false then
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\DevourMagic\\DevourMagicBirthMissile.mdl", U, "chest"))
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Feedback\\SpellBreakerAttack.mdl", U, "chest"))
            call UnitDamageTargetEx(D.cs,U, D.dmg, false, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
        endif
        return false
    endfunction
    
    private function Effects takes nothing returns nothing
        local Data d = LoadInteger(ht,GetHandleId(GetExpiredTimer()),0)
        if d.ticks > 0 then
            set d.ticks = d.ticks - 1
            if d.timeScaleTicks > 0 then
                set d.timeScaleTicks = d.timeScaleTicks - 1
            else
                set d.timeScaleTicks = 10000
            endif
            set d.x = GetUnitX(d.cs)
            set d.y = GetUnitY(d.cs)
            set D = d
            call GroupEnumUnitsInRange(d.g,d.x,d.y,175.,cf)
            return
        endif
        call PauseTimer(d.t)
        call d.destroy()
    endfunction
    
    private function Actions takes nothing returns nothing
        local Data d = Data.create()
        set d.cs = GetTriggerUnit()
        set d.p = GetOwningPlayer(d.cs)
        set d.dur = 4.
        set d.ticks = R2I(d.dur / .05)
        set d.timeScaleTicks = R2I(1. / .05)
        set d.dmg = 60 + ( 10* GetUnitAbilityLevel(d.cs,SPELL_ID))
        if d.t == null then
            set d.t = CreateTimer()
            call SaveInteger(ht,GetHandleId(d.t),0,d)
        endif
        if d.g == null then
            set d.g = CreateGroup()
        endif
        call TimerStart(d.t,.05,true,function Effects)
    endfunction

//---------------------------------------------------------------------------------------------------------
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger(  )
		local integer i = 0
		
		loop
			exitwhen i > 11
			call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
			set i = i + 1
		endloop

		call TriggerAddCondition( t, Condition( function Conditions ) )
		call TriggerAddAction( t, function Actions )
		 set cf = Condition(function Effect2)
		set t = null
	endfunction
    
endscope
 

shiFt

Member
Reaction score
8
edited the first post, got it to work now :),thnx kingking. had to refresh the cs x/y.

How do I make it so that that damage is only dealt once to the picked units?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
->
JASS:
    private function Effect2 takes nothing returns boolean
        set U = GetFilterUnit()
        if GetWidgetLife(U) > .405 and IsUnitEnemy(U,D.p) and not IsUnitInGroup(U,D.g) and IsUnitType(U,UNIT_TYPE_STRUCTURE) == false then
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\DevourMagic\\DevourMagicBirthMissile.mdl", U, "chest"))
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Feedback\\SpellBreakerAttack.mdl", U, "chest"))
            call UnitDamageTargetEx(D.cs,U, D.dmg, false, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
            call GroupAddUnit(D.g,U)
        endif
        return false
    endfunction
 

shiFt

Member
Reaction score
8
I think kings method is not working because it already made the group before this action is called thus to add it to the same group would change nothing.
 

shiFt

Member
Reaction score
8
Still doesnt work, if that clears the group before its made and the if selects units that are not in the group every timer interval it still wouldnt do anything, so confusing
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Use a global group for the enumerations, while adding damaged units to the instance group. This way you never enumerate any units into the group in the struct, you only add them via the GroupAddUnit() call, making it possible to use a IsUnitInGroup() check in the boolexpr.
 

shiFt

Member
Reaction score
8
So im making 2 groups, one global one attached to struct? where do I make the global group, so far ive got, this, its not working but I dont knw where in the code to set the global group.
JASS:
scope WW initializer Init

    globals 
        private constant integer SPELL_ID = 'A01X'
        private hashtable ht = InitHashtable()
    endglobals
    
    private struct Data
        unit cs
        real x
        real y
        player p
        real dur
        integer ticks
        integer timeScaleTicks
        timer t
        group g
        real dmg
    endstruct
    
    globals
        private unit U
        private Data D
        private real X
        private real Y
        private integer array TimerData
        private conditionfunc cf
        private group gg
    endglobals
    
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID
    endfunction

  private function Effect2 takes nothing returns boolean
        set U = GetFilterUnit()
        if GetWidgetLife(U) > .405 and IsUnitEnemy(U,D.p) and not IsUnitInGroup(U,gg) and IsUnitType(U,UNIT_TYPE_STRUCTURE) == false then
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\DevourMagic\\DevourMagicBirthMissile.mdl", U, "chest"))
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Feedback\\SpellBreakerAttack.mdl", U, "chest"))
            call UnitDamageTargetEx(D.cs,U, D.dmg, false, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
            call GroupAddUnit(gg,U)
        endif
        return false
    endfunction
    
    private function Effects takes nothing returns nothing
        local Data d = LoadInteger(ht,GetHandleId(GetExpiredTimer()),0)
        if d.ticks > 0 then
            set d.ticks = d.ticks - 1
            if d.timeScaleTicks > 0 then
                set d.timeScaleTicks = d.timeScaleTicks - 1
            else
                set d.timeScaleTicks = 10000
            endif
            set d.x = GetUnitX(d.cs)
            set d.y = GetUnitY(d.cs)
            set D = d
            call GroupEnumUnitsInRange(d.g,d.x,d.y,175.,cf)
            call GroupEnumUnitsInRange(gg,d.x,d.y,175.,cf)
            return
        endif
       call PauseTimer(d.t)
        call GroupClear(d.g)
        call d.destroy()
    endfunction
    
    private function Actions takes nothing returns nothing
        local Data d = Data.create()
        set d.cs = GetTriggerUnit()
        set d.p = GetOwningPlayer(d.cs)
        set d.dur = 4.
        set d.ticks = R2I(d.dur / .05)
        set d.timeScaleTicks = R2I(1. / .05)
        set d.dmg = (( 60 + ( 10* GetUnitAbilityLevel(d.cs,SPELL_ID)))* 0.05)
        if d.t == null then
            set d.t = CreateTimer()
            call SaveInteger(ht,GetHandleId(d.t),0,d)
        endif
        if d.g == null then
            set d.g = CreateGroup()
            set gg = CreateGroup()
        endif
        call TimerStart(d.t,.05,true,function Effects)
    endfunction

//---------------------------------------------------------------------------------------------------------
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger(  )
		local integer i = 0
		
		loop
			exitwhen i > 11
			call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
			set i = i + 1
		endloop

		call TriggerAddCondition( t, Condition( function Conditions ) )
		call TriggerAddAction( t, function Actions )
		 set cf = Condition(function Effect2)
		set t = null
	endfunction
    
endscope
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
You can just create it the following way:

JASS:
globals
    private group gg = CreateGroup()
endglobals


The thing you're doing wrong now is that you're using the struct group for enumaration, don't do this. Only use the global one for this purpose (note that you clear the group when you call GroupEnumUnits..., so there is no need for any clearing of the global group).

The only calls you should use the struct group for are the following:
- Creating it
- Checking if a unit is in the group already, if they are do not damage them.
- Adding damaged units to the group
- Destroying it at the end of the instance

It also goes without saying that the global group never should be destroyed (and as previously stated, clearing it is not needed).
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top