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

[JASS] Setting Ability For Unit

Status
Not open for further replies.
Level 24
Joined
Feb 28, 2007
Messages
3,480
I've made a trigger that runs when the time becomes 6.00. It should change the level of an ability for a non-hero unit, but the level doesn't change. What've I done wrong this time?

JASS:
scope Day initializer Init
    private function TypeFilter takes nothing returns boolean
       return GetUnitTypeId(GetFilterUnit()) == 'n003'
    endfunction
    
    private function Actions takes nothing returns nothing
        local group g = CreateGroup()
        local unit u
        call GroupEnumUnitsOfPlayer(g,Player(0),Condition(function TypeFilter))
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
            call SetUnitAbilityLevel(u,'A004',2)
            call SetUnitAbilityLevel(u,'A00I',2)
            call GroupRemoveUnit(g,u)
        endloop
        call DestroyGroup(g)
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterGameStateEvent(t,GAME_STATE_TIME_OF_DAY,EQUAL,6.)
        call TriggerAddAction(t,function Actions)
    endfunction
endscope
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
That code should work fine. Are you sure you're testing with correct raw ids/player?

Also, this would be an optimized version of that: (Basically made the group enumeration do everything in the filter and changed trigger actions to trigger conditions.)
JASS:
scope Day initializer Init
    globals
        private group g = CreateGroup()
    endglobals
    
    private function TypeFilter takes nothing returns boolean
        local unit u = GetFilterUnit()
        if GetUnitTypeId(u) == 'n003' and GetWidgetLife(u) > 0.405 then
            call SetUnitAbilityLevel(u,'A004',2)
            call SetUnitAbilityLevel(u,'A00I',2)
        endif
        set u = null
        return false       
    endfunction
    
    private function Actions takes nothing returns boolean
        call GroupEnumUnitsOfPlayer(g,Player(0),Condition(function TypeFilter))
        return false
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterGameStateEvent(t,GAME_STATE_TIME_OF_DAY,EQUAL,6.)
        call TriggerAddCondition(t,function Actions)
    endfunction
endscope
 
Level 13
Joined
Jul 26, 2008
Messages
1,009
Looks fine to me too. Check your rawcodes, make sure you're doing the right player (Player 1), then check to make sure no other code is interferring (Check your other code that happens at 6.0). Finally, if nothing has worked, try skipping the time forward at the end of the actions to 6.01. (I suggest condensing all your @ 6.00 code into one for this.)
 
Level 24
Joined
Feb 28, 2007
Messages
3,480
The raw codes are all right (unfortunately).
There is only one trigger that runs when the time of day becomes 6.00 (there is one for 18.00, also).
If you want to set an ability's level to 2, do you set it to 1 or 2 (like Player 1 (Red) is Player(0) in JASS)?
 
Status
Not open for further replies.
Top