Thread: ABuff System
View Single Post
Old 09-13-2010, 11:42 AM   #193
DanThanh
User
 
DanThanh's Avatar
 
Join Date: Apr 2009
Posts: 137

Submissions (1)

DanThanh has little to show at this moment (7)

Send a message via Yahoo to DanThanh
Default

Thank you. So, i need two buffs for my spell, right?
I tried another way but my game crash when i try to test, can you take a look at my code?
The idea is simple, whenever a unit take damage and has a specific buff of the spell that dealing damage , i apply a poison buff on it for 4 seconds.

Collapse JASS:
scope shadowheart initializer Init


    // CALIBRATION SECTION

    globals
        private aBuffType rexpoison
        private aBuffType display
        private constant integer abiID           = 'A009' //Autocast Spell
        private constant integer bufID           = 'B004' //Buff of Autocast
    endglobals


    
    private function con takes nothing returns boolean
        return GetUnitAbilityLevel(GetTriggerUnit(), bufID) > 0
    endfunction

    private function DisplayCreate takes aBuff eventBuff returns nothing
        call SetUnitVertexColor(eventBuff.target.u, 0, 255, 0, 255)
    endfunction
    private function DisplayCleanup takes aBuff eventBuff returns nothing
        call SetUnitVertexColor(eventBuff.target.u, 255, 255, 255, 255)
    endfunction

    private function Periodic takes aBuff eventBuff returns nothing
        local integer i = GetUnitAbilityLevel(eventBuff.caster, abiID)
        local real damage = 40*i
        call UnitDamageTargetEx(eventBuff.caster, eventBuff.target.u, damage*ABuff_PERIODIC_EVENT_PERIOD, ATTACK_TYPE_HERO, DAMAGE_TYPE_EXTRA, true)
    endfunction
    
    private function Cleanup takes aBuff eventBuff returns nothing
        call ABuffRemove(GetABuffFromUnitByType(eventBuff.target.u, display))
    endfunction
    
    private function act takes nothing returns nothing
        local unit c = GetTriggerDamageSource()
        local unit t = GetTriggerDamageTarget()
        local player p = GetOwningPlayer(c)
        local integer lvl = GetUnitAbilityLevel(c, abiID)
        //Actions
        call UnitRemoveAbility(t, bufID)
        call ABuffApply(display, t, c, 4.0, lvl, 0)
        set c    = null
        set t    = null
        set p    = null
endfunction

    // SPELL INITIALIZATION

    private function Init takes nothing returns nothing
        local trigger trg = CreateTrigger()
        set rexpoison = aBuffType.create()
        set rexpoison.category = ABuff_STACKING
        set rexpoison.countsAsBuff = false
        set rexpoison.eventCleanup = Cleanup
        set rexpoison.eventPeriodic = Periodic
        
        set display = aBuffType.create()
        set display.category = ABuff_REFCOUNT
        set display.ignoreAsBuff = true
        set display.eventCreate = DisplayCreate
        set display.eventCleanup = DisplayCleanup

        call TriggerAddAction(trg, function act)
        call TriggerAddCondition(trg, Condition(function con))
        call TriggerRegisterDamageEvent(trg, 1)
    endfunction

endscope
__________________
DanThanh is offline   Reply With Quote