wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > - Submit a resource -
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 01-27-2012, 05:17 PM   #1
Bills
User
 
Join Date: Jan 2012
Posts: 3

Bills has little to show at this moment (0)

Default [System] Buff Generator

Buff Generator version 3.1.7

This system allows rapid and easy buff development.



System code:
Collapse JASS:
library BuffGen /* v3.1.7.0
************************************************************************************************
*	 BUFF GENERATOR by Bills
*
*	 This system allows rapid and easy buff development.
*
************************************************************************************************
*
*   */ uses /*
*   
*       */ UnitIndexer /*   hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
*       */ Event /*         hiveworkshop.com/forums/jass-resources-412/snippet-event-186555/
*       */ CTL /*           hiveworkshop.com/forums/jass-resources-412/snippet-constant-timer-loop-32-a-201381/
*       */ TimerUtils /*    hiveworkshop.com/forums/graveyard-418/system-timerutilsex-204500/
*       */ Table /*         hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
*
***************************************************************************************************
*
*    Functions
*
*        function AddBuff takes unit whichUnit, Buff whichBuff, real duration returns boolean
*            - returns true if added the buff
*
*        function RemoveBuff takes unit wichUnit, Buff whichBuff returns boolean
*            - returns true if removed the buff
*
*        function RemoveAllBuffs takes unit wichUnit returns nothing
*            - removes all buffs of unit
*
*        function UnitHasBuff takes unit wichUnit, Buff whichBuff returns boolean
*            - returns true if unit has the buff
*
*        function SetBuffDuration takes unit whichUnit, Buff whichBuff, real duration returns nothing
*            - sets the duration of buff
*
*        function AddBuffDuration takes unit whichUnit, Buff whichBuff, real duration returns nothing
*            - increments the duration of buff
*
*        function GetBuffDuration takes unit whichUnit, Buff whichBuff, real duration returns real
*            - returns the duration of buff
*
*        function CountBuffs takes unit whichUnit returns real
*            - returns de amount of buffs that unit have
*
*******************************************************************************************
*
*   struct Buff extends array
*
*        static Event START
*            - fires when a buff is added
*        static Event FINISH
*            - fires when a buff is removed
*
*        Event Responses
*            - function GetEventBuff takes nothing returns Buff
*            - function GetBuffEventUnit takes nothing returns unit
*            - function GetBuffEventUnitId takes nothing returns integer
*
*        function TriggerRegisterBuffEvent takes trigger t, Event e returns nothing
*            - Jass wrapper of EVENT.registerTrigger(trigger)
*
*        function RegisterBuffEvent takes boolexpr b, Event e returns nothing
*            - Jass wrapper of EVENT.register(boolexpr)
*
*****************************************************************************
*
*    module BuffStruct
*
*        static constant real TIMEOUT = 0.031250000 // useful to method onPeriodic
*
*        static method operator buff takes nothing returns Buff
*            - returns the Buff generated by implementation of this module
*
*        (interface)
*
*            private static constant integer AURAID = 'AURA'
*                (required) - this is a tornado slow aura
*            private static constant integer BUFFID = 'BUFF'
*                (required) - this is the buff of aura
*
*            private method onApply takes nothing returns nothing
*                (optional) - called all times that AddBuff is called
*
*            private method onRemove takes nothing returns nothing
*                (optional) - called all times that RemoveBuff is called
*
*            private method onFinish takes nothing returns nothing
*                (optional) - called only when the buff finish completely your duration
*
*            private method onPeriodic takes nothing returns nothing
*                (optional) - called 32 times per second
*                
*            Notes:
*                - "thistype this" represents the index of buffed unit in all methods above.
*                - If you do not want to use AURAID or/and BUFFID, just set it with 0 (zero).
*
********************************************************************************
*
*    ForEachBuff Modules
*
*        allows the method ForEachBuff takes unit enumUnit returns nothing
*
*        module ForEachBuff
*            - declare local variables here
*        module ForEachBuffLoop
*            - run loop code
*        module ForEachBuffNull
*            - null locals
*        module ForEachBuffEnd
*
*        Exemple of ForEachBuff
*            - struct Test extends array
*                    unit targ
*                    implement ForEachBuff
*                        local unit target=thistype(GetUnitUserData(enumUnit)).targ
*                    implement ForEachBuffLoop
*                        call UnitDamageTarget(enumUnit, target, 50, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
*                        // deals 50 damage on target for each buff on enumUnit
*                    implement ForEachBuffNull
*                        set target=null
*                    implement ForEachBuffEnd
*
*                    static method onCast takes nothing returns boolean
*                        set thistype(GetUnitUserData(GetTriggerUnit())).targ=GetSpellTargetUnit()
*                        call ForEachBuff(GetTriggerUnit())
*                        return false
*                    endmethod
*              endstruct
*
************************************************************************************/
    globals
        private integer total=0 //Buff indexer and counter
        private integer array aid //ability id
        private integer array bid //buff id
        private integer array bc
        private Table array t
        private Event array e
        private integer array ed1 // event data
        private integer array ed2 // other event data
        private boolean ee=true
        private unit eu=null
        private Buff eb=0
    endglobals
    
    private module M
        private static method onInit takes nothing returns nothing
            set START=Event.create()
            set FINISH=Event.create()
        endmethod
    endmodule
    
    struct Buff extends array
        readonly static Event START
        readonly static Event FINISH
        implement M
    endstruct

    private function InitBuff takes integer auraid, integer buffid, code func returns integer
        local integer id=total+1
        set total=id
        set e[id]=Event.create()
        call e[id].register(Filter(func))
        set t[id]=Table.create()
        set aid[id]=auraid
        set bid[id]=buffid
        return id
    endfunction
    
    function UnitHasBuff takes unit u, Buff b returns boolean
        return t[b].boolean[GetUnitUserData(u)]
    endfunction

    function RemoveBuff takes unit u, Buff b returns boolean
        debug if u==null or b<=0 or integer(b)>total then
            debug call BJDebugMsg("[Buff Generator] Error: invalid arguments on RemoveBuff")
            debug return false
        debug endif
        if UnitHasBuff(u,b) then
            set t[b].boolean[GetUnitUserData(u)]=false
            if UnitMakeAbilityPermanent(u,false,aid[b]) then
                call UnitRemoveAbility(u,aid[b])
                call UnitRemoveAbility(u,bid[b])
            endif
            set ed1[b]=GetUnitUserData(u)
            set ed2[b]=2
            call e[b].fire()
            if ee then
                set eu=u
                set eb=b
                call Buff.FINISH.fire()
            endif
            return true
        endif
        return false
    endfunction
    
    function AddBuff takes unit u, Buff b, real dur returns boolean
        local integer i
        debug if u==null or b<=0 or integer(b)>total then
            debug call BJDebugMsg("[Buff Generator] Error: invalid arguments on AddBuff")
            debug return false
        debug endif
        if UnitHasBuff(u,b) then
            call RemoveBuff(u,b)
            call AddBuff(u,b,dur)
        else
            set i=GetUnitUserData(u)
            set t[b].boolean[i]=true
            if UnitAddAbility(u,aid[b]) then
                call UnitMakeAbilityPermanent(u,true,aid[b])
            endif
            set t[b].real[i]=dur
            set ed1[b]=i
            set ed2[b]=1
            call e[b].fire()
            if ee then
                set eu=u
                set eb=b
                call Buff.START.fire()
            endif
            return true
        endif
        return false
    endfunction

    function RemoveAllBuffs takes unit u returns nothing
        local Buff i=total
        loop
            exitwhen i==0
            call RemoveBuff(u,i)
            set i=i-1
        endloop
    endfunction
    
    function SetBuffDuration takes unit u, Buff b, real dur returns nothing
        if UnitHasBuff(u,b) then
            set t[b].real[GetUnitUserData(u)]=dur
            set ed1[b]=GetUnitUserData(u)
            set ed2[b]=3
            call e[b].fire()
        endif
    endfunction

    function GetBuffDuration takes unit u, Buff b returns real
        if UnitHasBuff(u,b) then
            return t[b].real[GetUnitUserData(u)]
        endif
        return 0.
    endfunction

    function AddBuffDuration takes unit u, Buff b, real dur returns nothing
        call SetBuffDuration(u,b,GetBuffDuration(u,b)+dur)
    endfunction
    
    function CountBuffs takes unit u returns integer
        return bc[GetUnitUserData(u)]
    endfunction
    
    function TriggerRegisterBuffEvent takes trigger t, Event e returns nothing
        call e.registerTrigger(t)
    endfunction

    function RegisterBuffEvent takes boolexpr t, Event e returns nothing
        call e.register(t)
    endfunction
    
    function GetBuffEventUnit takes nothing returns unit
        return eu
    endfunction

    function GetBuffEventUnitId takes nothing returns integer
        return GetUnitUserData(eu)
    endfunction
    
    function GetEventBuff takes nothing returns Buff
        return eb
    endfunction
    
    module BuffStruct
        static constant real TIMEOUT=0.031250000
        private static Buff id //id of this buff
        
        static method operator buff takes nothing returns Buff
            return id
        endmethod
        
        static if thistype.onPeriodic.exists then
            private integer index
            private thistype T
            implement CTL
                local real d
            implement CTLExpire
                set d=t[id].real[index]-TIMEOUT
                call thistype(index).onPeriodic()
                if d<=0.00 then
                    call RemoveBuff(GetUnitById(index),id)
                    static if thistype.onFinish.exists then
                        call thistype(index).onFinish()
                    endif
                else
                    set t[id].real[index]=d
                endif
            implement CTLNull
            implement CTLEnd
        else
            private timer T
            private static method exp takes nothing returns nothing
                local integer i=GetTimerData(GetExpiredTimer())
                call RemoveBuff(GetUnitById(i),id)
                static if thistype.onFinish.exists then
                    call thistype(i).onFinish()
                endif
            endmethod
        endif
        
        private static method m takes nothing returns nothing
            local integer i=ed1[id] //unit id
            local integer j=ed2[id] //data
            local thistype this=thistype(i)
            if j==1 then
                static if thistype.onPeriodic.exists then
                    set T=create()
                    set T.index=i
                else
                    set T=NewTimerEx(i)
                    call TimerStart(T,t[id].real[i],false,function thistype.exp)
                endif
                static if thistype.onApply.exists then
                    call onApply()
                endif
                set bc[i]=bc[i]+1
            elseif j==2 then
                static if thistype.onPeriodic.exists then
                    call T.destroy()
                else
                    call ReleaseTimer(T)
                    set T=null
                endif
                static if thistype.onRemove.exists then
                    call onRemove()
                endif
                set bc[i]=bc[i]-1
            elseif j==3 then
                static if not thistype.onPeriodic.exists then
                    set T=NewTimerEx(ReleaseTimer(T))
                    call TimerStart(T,t[id].real[i],false,function thistype.exp)
                endif
            endif
        endmethod

        private static method onInit takes nothing returns nothing
            set id=InitBuff(AURAID,BUFFID,function thistype.m)
        endmethod
    endmodule

    // ForEachBuff Modules
    module ForEachBuff
        static method ForEachBuff takes unit enumUnit returns nothing
            local Buff this=total
    endmodule
    module ForEachBuffLoop
            loop
                exitwhen this==0
                if UnitHasBuff(enumUnit,this) then
    endmodule
    module ForEachBuffNull
                endif
                set this=this-1
            endloop
    endmodule
    module ForEachBuffEnd
        endmethod
    endmodule
endlibrary

Demos

Collapse JASS:
library BuffGenExemple uses BuffGen, Bonus
    /* Bloodlust
    ** Increase attack speed by 100%, when finishs duration apply beserk buff */

    struct Berserk extends array
        private static constant integer AURAID = 'A001'
        private static constant integer BUFFID = 'B001'

        private method onApply takes nothing returns nothing
            call AddUnitBonus(GetUnitById(this),BONUS_ATTACK_SPEED,300)
        endmethod

        private method onRemove takes nothing returns nothing
            call AddUnitBonus(GetUnitById(this),BONUS_ATTACK_SPEED,-300)
        endmethod

        private method onPeriodic takes nothing returns nothing
            //consumes 30 hp per second
            call SetWidgetLife(GetUnitById(this),GetWidgetLife(GetUnitById(this))-(30*TIMEOUT))
        endmethod

        implement BuffStruct
    endstruct

    struct Bloodlust extends array
        private static constant integer AURAID = 'A000' 
        private static constant integer BUFFID = 'B000' 

        private method onApply takes nothing returns nothing 
            call AddUnitBonus(GetUnitById(this),BONUS_ATTACK_SPEED,100)
        endmethod

        private method onRemove takes nothing returns nothing
            call AddUnitBonus(GetUnitById(this),BONUS_ATTACK_SPEED,-100)
        endmethod

        private method onFinish takes nothing returns nothing
            call AddBuff(GetUnitById(this),Berserk.buff,10) // adds berserk for 10 sec.
        endmethod
        
        implement BuffStruct

        // code of spell
        private static method a takes nothing returns boolean
            call AddBuff(GetTriggerUnit(),thistype.buff,10) // adds bloddlust for 10 sec.
            return false
        endmethod

        //initialization
        private static method onInit takes nothing returns nothing
            local trigger t=CreateTrigger()
            call TriggerAddCondition(t, Condition(function thistype.a))
            call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
            set t=null
        endmethod
    endstruct
endlibrary

Exemple of ForEachBuff

Collapse JASS:
struct Exemple extends array
    implement ForEachBuff
    implement ForEachBuffLoop
        // decreases the duration of each buff in 10 seconds
        call AddBuffDuration(enumUnit,this,-10)
    implement ForEachBuffNull
    implement ForEachBuffEnd

    static method onCast takes nothing returns boolean
        call ForEachBuff(GetTriggerUnit())
        return false
    endmethod
endstruct



Important: The TimerUtils used on system is this > hiveworkshop.com/forums/graveyard-418/system-timerutilsex-204500/
Attached Files
File Type: w3x BuffGenerator 3.1.7.w3x (61.9 KB, 22 views)
Bills is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 01-27-2012, 10:42 PM   #2
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Unfortunately, your resource can not be approved as long as it uses libraries that have not gone through our review system and been accepted themselves.
__________________
Anitarf is offline   Reply With Quote
Old 01-27-2012, 11:12 PM   #3
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

Attempting to submit a buff system to Anitarf is like trying to sell snow to Eskimos.
see here: http://www.wc3c.net/showthread.php?t=95521
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.

Last edited by cohadar : 01-27-2012 at 11:13 PM.
cohadar is offline   Reply With Quote
Old 01-29-2012, 02:05 AM   #4
Bills
User
 
Join Date: Jan 2012
Posts: 3

Bills has little to show at this moment (0)

Default

Quote:
Originally Posted by Anitarf
Unfortunately, your resource can not be approved as long as it uses libraries that have not gone through our review system and been accepted themselves.
lol ok
Bills is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 06:53 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services