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

[vJass] Buff not found?

Status
Not open for further replies.
Level 13
Joined
Mar 16, 2008
Messages
941
[Solved] [vJass] Buff not found?

Oh, well... the problem isn't realy vJass related, but the code is written in vJass so I thought the prefix fits :p

I'm creating a spell at the moment that should do this:
Channeling manadrain that stuns the target. Damage brakes the stun/channeling. I decided to base it on shakle because the mana drain is better to do with triggers then the stun.
JASS:
//Damage detection in JustifySystems
scope Nethercage initializer InitCage

    public keyword cage
    
    globals
        private constant integer SpellId = 'A000'
        private constant integer BuffId = 'B003'
        
        private constant real PERIOD = 0.1
        private constant real DrainStart = 40.
        private constant real DrainAdd = 30.
        
        private timer Tim
        private integer StructCount = 0        
        private cage array Caged
    endglobals
    
    public struct cage
        unit caster
        unit target
        integer level
        
        static method create takes nothing returns cage
            local cage dat = cage.allocate()
            
            set dat.caster = GetTriggerUnit()
            set dat.target = GetSpellTargetUnit()
            set dat.level = GetUnitAbilityLevel(dat.caster, SpellId)
            
            if StructCount == 0 then
                set Tim = AllocateTimer()
                call TimerStart(Tim, PERIOD, true, function cage.drain)
            endif
            set StructCount = StructCount+1
            
            return dat
        endmethod
        
        static method drain takes nothing returns nothing
            local cage dat
            local real burn
            local real tr
            local integer i = 0
            
            loop
                exitwhen i >= StructCount
                set dat = Caged[i]
                
                call BJDebugMsg(I2S(GetUnitAbilityLevel(dat.target, BuffId)))
                if GetUnitAbilityLevel(dat.target, BuffId) > 0 then
                    set tr = GetUnitState(dat.target, UNIT_STATE_MANA)
                    set burn = PERIOD*(DrainStart+(dat.level-1)*DrainAdd)
                    if tr < burn then
                        set burn = tr
                    endif
                    call SetUnitState(dat.target, UNIT_STATE_MANA, tr-burn)
                    call SetUnitState(dat.caster, UNIT_STATE_MANA, GetUnitState(dat.caster, UNIT_STATE_MANA)+burn)
                    set i = i+1
                else
                    //call dat.destroy()
                    //set StructCount = StructCount-1
                    //set Caged[i] = Caged[StructCount]
                endif
                //Avoids endless loop in this tests
                set i = i+1
            endloop
        endmethod
        
        static method remove takes unit target returns nothing
            local cage dat
            local integer i
            
            if GetUnitAbilityLevel(target, BuffId) > 0 then
                set i = 0
                loop
                    exitwhen i >= StructCount
                    set dat = Caged[i]
                    call BJDebugMsg(GetUnitName(dat.target))
                    if target == dat.target then
                        call BJDebugMsg(GetUnitName(dat.caster))
                        call IssueImmediateOrder(dat.caster, "stop")
                    endif
                    set i = i+1
                endloop
            endif            
        endmethod
        
        method onDestroy takes nothing returns nothing
            set .caster = null
            set .target = null
        endmethod
        
    endstruct

    private function IsSpell takes nothing returns boolean
        return GetSpellAbilityId() == SpellId
    endfunction

    private function InitCage takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
            exitwhen i >= 16
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, ReturnTrue)
            set i = i+1
        endloop
        call TriggerAddCondition(t, Condition(function IsSpell))
        call TriggerAddAction(t, function cage.create)
        
        set t = null
    endfunction

endscope

Okay, that is the main script. The DebugMessage showing the buff level always returns 0, and the remove function never works (called in a damage detection system used by the entire map).

Now you'd say: wrong id...
56858025ad9.jpg
84682127bk5.jpg

67770330un6.jpg
72688981xe2.jpg


In addition, the buff with the id B003 is the only buff on the unit and creates a special effect that is unique for it.

I can't find the damn bug, help me pls^^

Justify
 
Last edited:
Level 13
Joined
Mar 16, 2008
Messages
941
Yes I'm 100% sure... the buff is visible and the unique special effect (the blue pentagram from here) is shown correctly.
EDIT: Perfect -.- ... RemoveBuff(dat.target, BuffId) doesn't work. He realy doesn't seem to "know" the buff although I can see it oO what the hell...?
 
Last edited:
Level 13
Joined
Mar 16, 2008
Messages
941
Ok, this map should include everything you need.
The only important trigger is "Nethercage"... the others are systems I use in my map and are used by this spell.
Type -test to damage all sorceres (and yourself :p only 10^^)
Btw, yes I know that I didn't restore the timer in this version :p forgot that line in the onDestroy xD
 

Attachments

  • BugFix.w3x
    48.5 KB · Views: 40
Last edited:
Status
Not open for further replies.
Top