Buff Struct

hgkjfhfdsj

Active Member
Reaction score
55
JASS:
//! runtextmacro BuffType("Cleanse")
    //! runtextmacro SetBuffName("Cleanse")
    //! runtextmacro SetBuffAlignment("POSITIVE")
    //! runtextmacro SetBuffTooltip("This unit is has Cleanse; it regains the mana used to cast the next non-ultimate spell.")
    //! runtextmacro SetBuffIcon("ReplaceableTextures\\CommandButtons\\BTNHeal.blp")
//! runtextmacro BuffStruct()
    private method remove takes thistype b returns nothing
        call b.destroy()
        call BJDebugMsg("remove")
    endmethod
    method onApply takes nothing returns nothing
        call BuffList[.unit].forEachBuff(BUFF_ALIGNMENT_NEGATIVE, .remove)
    endmethod
//! runtextmacro EndBuff()


JASS:
scope Cleanse initializer Init

//! textmacro CLEANSE takes SPELL, MANA1, MANA2, MANA3, MANA4
    private struct CleanseStruct
        unit u
        private static method Action takes nothing returns boolean
            local thistype kt 
            local unit u = GetTriggerUnit()
            local real array add
            if GetSpellAbilityId() == ID and Cleanse.isOn(u) then
                set add[1] = $MANA1$
                set add[2] = $MANA2$
                set add[3] = $MANA3$
                set add[4] = $MANA4$
            
                call SetUnitState(u, UNIT_STATE_MANA, GetUnitState(u, UNIT_STATE_MANA) + add[GetUnitAbilityLevel(u, $SPELL$)])
                call Cleanse(u).setUnit(null) // < --------------------<
            endif
            set u = null
            return false
        endmethod
        private static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_FINISH )
            call TriggerAddCondition( t, Condition(function thistype.Action))
        endmethod
    endstruct
//! endtextmacro

globals
    public constant integer ID = 'A000'
endglobals
private function Conditions takes nothing returns boolean
    local unit target = GetSpellAbilityUnit()
    if GetSpellAbilityId() == ID then
        if Cleanse.isOn(target) == false then
            call Cleanse.create(target)
            set target = null
        endif
    endif
    return false
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Conditions ) )
endfunction
endscope


What the spell does
- regains the mana used to cast the next non-ultimate spell. also removes all negative buffs
- uses textmacro to set mana cost of every spell (need helping optimizing it)
- buff is created on cast; icon shows; heals mana

Problem
syntax error (tried both)
cannot convert unit to integer
JASS:
call Cleanse(u).setUnit(null)
call Cleanse(u).destroy()

this is preventing me from removing buff :(

also which should i use.. setunit(null) or destroy?
 

Executor

I see you
Reaction score
57
I suppose (as BuffStruct uses AIDS) you have to use [].

JASS:
Cleanse[whichUnit]


like here:

JASS:
    method onApply takes nothing returns nothing
        call BuffList[.unit].forEachBuff(BUFF_ALIGNMENT_NEGATIVE, .remove)
    endmethod
 

the Immortal

I know, I know...
Reaction score
51
> you have to use [].
[ljass]Cleanse[whichUnit][/ljass]

This.

Or [ljass]Cleanse(GetUnitId(u))[/ljass] which is essentially the same but inlined.

Parentheses typecast an integer value to a struct instance, while square brackets can do anything depending on the struct (in this case get an unit's corresponding struct instance).


My bad. Was completely off, thinking for AIDS when wrote that...
 

hgkjfhfdsj

Active Member
Reaction score
55
tried
call Cleanse.setUnit(null)
call Cleanse.destroy()
syntax error, cleanse not an array
EDIT
lol
call Cleanse(GetUnitId(u)).setUnit(null)
compiled.. testing results
EDIT1
Double free of type when spammed.
buff not removed
 

Jesus4Lyf

Good Idea™
Reaction score
397
Lol, it hasn't actually been implemented, yet... (getting the instance of a buff for a unit, that is.)

BuffStruct is still officially BETA. One way of doing this is attaching the buff instance to the unit manually, another way is using BuffList and filtering for the buff you want, which is O(n)...

I just haven't had time to work on BuffStruct for a very long time... :(
 
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