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

Adressing one struct returns another

Status
Not open for further replies.
Some info: I was trying to make a custom-buff system which supports stacking. I made each buff equal two abilities - the one giving the effect (without icon, for example Item Attack Bonus) and the one giving the icon (based on Tornado Slow Aura). It works so far.

I made two buffs to test it - Might (+dmg) and Haste (+as).

However, when I call apply_might() it gives unit haste, and vice-versa.

I double-checked raw ability codes I used on initialization, they're good.

Here's the code.
JASS:
library Apply initializer initialize requires PUI

struct buffData
    integer buffAbility //the actual ability, like Item Armor Bonus
    integer buffPlacer //ability based on 'Slow Aura', used for placing a custom buff
    integer buffIcon //buff, used for quick removing
    
    static method create takes integer A, integer B, integer C returns buffData
    local buffData temp = buffData.allocate()
    set temp.buffAbility = A
    set temp.buffPlacer = B
    set temp.buffIcon = C
    return temp
    endmethod
endstruct

struct customBuff
    unit    buffUnit  //unit recieving all the glorious benefits of the buff, yaay
    buffData info
    
    static method create takes buffData data, unit u returns customBuff
    local customBuff temp = customBuff.allocate()
    set temp.info = data
    set temp.buffUnit = u
    return temp
    endmethod
endstruct




globals
buffData Haste
buffData Might
endglobals

public function initialize takes nothing returns nothing
call Might.create('A00R','B001','C001')
call Haste.create('A00Q','B002','C002')
endfunction


private function basicBuff takes buffData boon, unit target, real time returns nothing
local customBuff data = customBuff.create(boon,target)
call BJDebugMsg(GetAbilityName(boon.buffAbility))

if (GetUnitAbilityLevel (target, boon.buffAbility) < 25) then
    if (GetUnitAbilityLevel (target, boon.buffAbility) == 0) then
        call UnitAddAbility (target, boon.buffAbility)
        call UnitAddAbility (target, boon.buffPlacer)
    else
        call IncUnitAbilityLevel (target, boon.buffAbility)
    endif
    
    call TriggerSleepAction(time)
  
    if (GetUnitAbilityLevel (target, boon.buffAbility) == 1) then
        call UnitRemoveAbility (target, boon.buffAbility)
        call UnitRemoveAbility (target, boon.buffPlacer)
        call UnitRemoveBuffBJ(boon.buffIcon,target)
    else
        call DecUnitAbilityLevel (target, boon.buffAbility)
   endif
endif
endfunction








//public functions
public function Haste takes unit target, real time returns nothing
call BJDebugMsg("haste?")
call basicBuff.execute(Haste,target,time)
endfunction

public function Might takes unit target, real time returns nothing
call BJDebugMsg("might?")
call basicBuff.execute(Might,target,time)
endfunction

endlibrary
 
Status
Not open for further replies.
Top