Is there something wrong with this code?

chadpiety123

New Member
Reaction score
0
Is there something wrong? It's just supposed to buff every unit in an area including both enemies and allies. I don't get it it won't work.

EDIT: I changed it to this one and added the event, but it still won't work. I used Curse as the base ability of the buff, and blizzard as the base ability of the AoE.

EDIT2: I removed the leaks I knew how to remove and added the creategroup() function. Unfortunately, still not working. It doesn't buff the area at all.

EDIT3: Still not working after optimizing GroupActions and replacing GetTriggerUnit and GetTriggerPlayer

JASS:
scope ExertionDummy
    globals
        private constant integer DUMMYSPELL = 'A000'
        private constant integer MAINSPELL = 'A001'
        private constant integer DUMMYUNIT = 'h003'
        private constant integer TIMEDLIFE = 'BTLF'
        private constant real LIFEDURATION = 1.5
        private constant real AOE = 500
        private constant string DSCOMMAND = "blizzard"
        private constant string MSCOMMAND = "curse"
        
        unit CASTER
    endglobals
    
    function ExertionGroupConditions takes nothing returns boolean
        return IsUnitAliveBJ(GetFilterUnit()) == true
    endfunction
    
    function GroupActions takes nothing returns nothing
        local unit u = GetEnumUnit()
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local unit d = CreateUnit(GetOwningPlayer(CASTER), DUMMYUNIT, x, y, 0)
        
        call UnitApplyTimedLife(d, TIMEDLIFE, LIFEDURATION)
        call UnitAddAbility(d, MAINSPELL)
        call SetUnitAbilityLevel(d, MAINSPELL, GetUnitAbilityLevel(CASTER, DUMMYSPELL))
        call IssueTargetOrder(d, MSCOMMAND, u)
        
        set u = null
        set d = null
    endfunction

    function DummyActions takes nothing returns nothing
        local integer i = 0
        local group g = CreateGroup()
        local unit array uarray
        local real locationX = GetLocationX(GetSpellTargetLoc())
        local real locationY = GetLocationY(GetSpellTargetLoc())
        set CASTER = GetTriggerUnit()
        
        call GroupEnumUnitsInRange(g, locationX, locationY, AOE, Condition(function ExertionGroupConditions))
        call ForGroup(g, function GroupActions)
        call DestroyGroup(g)
        set CASTER = null
    endfunction
    
    function DummyConditions takes nothing returns boolean
        return GetSpellAbilityId() == DUMMYSPELL
    endfunction

    //===========================================================================
 
    function ExertionDummyTrigger takes nothing returns nothing
        local trigger ExertionDummy = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(ExertionDummy, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(ExertionDummy, Condition(function DummyConditions))
        call TriggerAddAction(ExertionDummy, function DummyActions)
    endfunction
endscope
 

cleeezzz

The Undead Ranger.
Reaction score
268
no event

i think your going for the

call TriggerRegisterAnyUnitEventBJ( ExertionDummy, EVENT_PLAYER_UNIT_SPELL_EFFECT )
 

cleeezzz

The Undead Ranger.
Reaction score
268
you didnt initialize group g

set g = CreateGroup()

or if you have GroupUtils,

set g = NewGroup()


dont forget to Destroy/Release it

and just a leak check:
in GroupActions, you didn't null u, UnitLoc leaks location
in DummyActions, you leak a group.

and what is uarray for? you dont use it
 

chadpiety123

New Member
Reaction score
0
Ah I see. I'll try to do it again now.

uarray was for the code before I edited it. I forgot to remove it. I'll just ask again if I need some more help.
 

cleeezzz

The Undead Ranger.
Reaction score
268
k

1. in GroupActions, when you create the unit, there is no Triggering Player
2. in GroupActions, when you set the ability level, there is no triggering unit.

you could store the unit into a global, since everything is instant, it will still be MUI

then you would do

call CreateUnitAtLoc(GetOwningPlayer(GLOBAL_UNIT), DUMMYUNIT, xy, 0)

and

call SetUnitAbilityLevel(GetLastCreatedUnit(), MAINSPELL, GetUnitAbilityLevel(GLOBAL_UNIT, DUMMYSPELL))
 

cleeezzz

The Undead Ranger.
Reaction score
268
since you used ForGroup, the function it calls (in your case, GroupActions), it will no longer have access to functions that relate to your event, such as GetTriggerUnit, if you use GetTriggerUnit in GroupActions, it will return null because there is none.

here is how i would do it.

JASS:
scope ExertionDummy
    globals
        private unit CASTER
        private constant integer DUMMYSPELL = 'A000'
        private constant integer MAINSPELL = 'A001'
        private constant integer DUMMYUNIT = 'h003'
        private constant integer TIMEDLIFE = 'BTLF'
        private constant real LIFEDURATION = 1.5
        private constant real AOE = 500
        private constant string DSCOMMAND = "blizzard"
        private constant string MSCOMMAND = "curse"
    endglobals
    
    function ExertionGroupConditions takes nothing returns boolean
        return IsUnitAliveBJ(GetFilterUnit()) == true
    endfunction
    
    function GroupActions takes nothing returns nothing
        local unit u = GetEnumUnit()
        local location xy = GetUnitLoc(u)
        
        call CreateUnitAtLoc(GetOwningPlayer(CASTER), DUMMYUNIT, xy, 0)
        call UnitApplyTimedLife(GetLastCreatedUnit(), TIMEDLIFE, LIFEDURATION)
        call UnitAddAbility(GetLastCreatedUnit(), MAINSPELL)
        call SetUnitAbilityLevel(GetLastCreatedUnit(), MAINSPELL, GetUnitAbilityLevel(CASTER, DUMMYSPELL))
        call IssueTargetOrder(GetLastCreatedUnit(), MSCOMMAND, u)
        set u = null
        call RemoveLocation(xy)
    endfunction

    function DummyActions takes nothing returns nothing
        local integer i = 0
        local group g = CreateGroup()
        local unit array uarray
        local real locationX = GetLocationX(GetSpellTargetLoc())
        local real locationY = GetLocationY(GetSpellTargetLoc())
        set CASTER = GetTriggerUnit()
        call GroupEnumUnitsInRange(g, locationX, locationY, AOE, Condition(function ExertionGroupConditions))
        call ForGroup(g, function GroupActions)
        call DestroyGroup(g)
    endfunction
    
    function DummyConditions takes nothing returns boolean
        return GetSpellAbilityId() == DUMMYSPELL
    endfunction

    //===========================================================================
 
    function ExertionDummyTrigger takes nothing returns nothing
        local trigger ExertionDummy = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(ExertionDummy, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(ExertionDummy, Condition(function DummyConditions))
        call TriggerAddAction(ExertionDummy, function DummyActions)
    endfunction
endscope


oh and if you want to optimize your GroupActions, i would do this


JASS:
    function GroupActions takes nothing returns nothing
        local unit u = GetEnumUnit()
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local unit d = CreateUnit(GetOwningPlayer(CASTER), DUMMYUNIT, x, y, 0)
        call UnitApplyTimedLife(d, TIMEDLIFE, LIFEDURATION)
        call UnitAddAbility(d, MAINSPELL)
        call SetUnitAbilityLevel(d, MAINSPELL, GetUnitAbilityLevel(CASTER, DUMMYSPELL))
        call IssueTargetOrder(d, MSCOMMAND, u)
        set u = null
        set d = null
    endfunction


x,y are reals so they do not leak, plus they are faster than locations

(im not entirely sure, but if you use CreateUnit, the GetLastCreatedUnit() probably doesn't work, which is why i set it to a variable, "d")
 

chadpiety123

New Member
Reaction score
0
I did all of what you said, and it still doesn't work. I'm lost. Maybe it's with the base ability I'm using, or maybe not?
 

cleeezzz

The Undead Ranger.
Reaction score
268
maybe.

remove locust from the dummy, give it a model, see if it creates, if it does, then click it and try to manual cast

that will probably tell you if something is wrong. also make sure the order strings are right.
 

cleeezzz

The Undead Ranger.
Reaction score
268
hm... i dont see why not.

you sure the dummy is 'h003' ?

oh wth, i know why lol, take a close look (hint, first line)

JASS:
scope ExertionDummy initializer ExertionDummyTrigger
    globals
        private constant integer DUMMYSPELL = 'A000'
        private constant integer MAINSPELL = 'A001'
        private constant integer DUMMYUNIT = 'h003'
        private constant integer TIMEDLIFE = 'BTLF'
        private constant real LIFEDURATION = 1.5
        private constant real AOE = 500
        private constant string DSCOMMAND = "blizzard"
        private constant string MSCOMMAND = "curse"
        
        unit CASTER
    endglobals
    
    function ExertionGroupConditions takes nothing returns boolean
        return IsUnitAliveBJ(GetFilterUnit()) == true
    endfunction
    
    function GroupActions takes nothing returns nothing
        local unit u = GetEnumUnit()
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local unit d = CreateUnit(GetOwningPlayer(CASTER), DUMMYUNIT, x, y, 0)
        
        call UnitApplyTimedLife(d, TIMEDLIFE, LIFEDURATION)
        call UnitAddAbility(d, MAINSPELL)
        call SetUnitAbilityLevel(d, MAINSPELL, GetUnitAbilityLevel(CASTER, DUMMYSPELL))
        call IssueTargetOrder(d, MSCOMMAND, u)
        
        set u = null
        set d = null
    endfunction

    function DummyActions takes nothing returns nothing
        local integer i = 0
        local group g = CreateGroup()
        local unit array uarray
        local real locationX = GetLocationX(GetSpellTargetLoc())
        local real locationY = GetLocationY(GetSpellTargetLoc())
        set CASTER = GetTriggerUnit()
        
        call GroupEnumUnitsInRange(g, locationX, locationY, AOE, Condition(function ExertionGroupConditions))
        call ForGroup(g, function GroupActions)
        call DestroyGroup(g)
        set CASTER = null
    endfunction
    
    function DummyConditions takes nothing returns boolean
        return GetSpellAbilityId() == DUMMYSPELL
    endfunction

    //===========================================================================
 
    function ExertionDummyTrigger takes nothing returns nothing
        local trigger ExertionDummy = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(ExertionDummy, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(ExertionDummy, Condition(function DummyConditions))
        call TriggerAddAction(ExertionDummy, function DummyActions)
    endfunction
endscope


i dont think your trigger was ever initialized.
 

chadpiety123

New Member
Reaction score
0
I'm quite sure, do you mind if I upload the map here? Maybe you could check it personally. I'll be very thankful.
 

Attachments

  • Exertion Code.w3x
    31 KB · Views: 181

cleeezzz

The Undead Ranger.
Reaction score
268
read my post again, i updated.

also, how come you didn't update your wc3 yet? lol

your code wont work in v1.24 because your using TimerUtils which uses H2I, if and when you do update your wc3, remember to update TimerUtils which you can find in wc3c.net
 

chadpiety123

New Member
Reaction score
0
Umm, can you tell me what you meant when you said that the trigger wasn't initialized? Sorry for being such a no-brainer. This is my first Jass code.

And did you change anything in your post? I can't seem to tell.

Thanks again >.<

and with regards to updating... unfortunately, I can't -- in the country where I'm staying, updating your WC means not playing with anybody.
 

cleeezzz

The Undead Ranger.
Reaction score
268
i already gave you a hint, the first line of the code changed O_O

basically, the scope needs to know which function to run when map starts, if it doesn't run ExertionDummyTrigger then the trigger doesn't exist yes? (thats where you create the trigger)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top