1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Icon Contest #17 - Poll is up! Vote for the most legendary icon set!
    Dismiss Notice
  3. Choose your favourite retro song at the Music Contest #10 - Poll!
    Dismiss Notice
  4. Join us in our custom games night on Saturday, July 28. If you'd like to create a map for the night, check out the map challenge!
    Dismiss Notice
  5. The results for Texturing Contest #28 are out! Step by to congratulate our winners!
    Dismiss Notice
  6. We've created the Staff Job Openings thread. We're currently in need of icon, video production, and social/multimedia positions to be filled. Thank you!
    Dismiss Notice
  7. Music Contest #10 Retro is out! Join us for some retro/vintage fun!
    Dismiss Notice
  8. Don't be stagnant - embrace change! The time has come to evolve and join the Techtree Contest #12 - Evolution.
    Dismiss Notice
  9. On May 20th a new law about privacy and data processing comes into work in the EU. I am no lawyer and I need help figuring out if we comply and if not, what we must do about it. Please message me if you can provide any assistance. Read more. Ralle
    Dismiss Notice

(System) [vJass] SpellBar - Caster Bar for Spells

Submitted by Anachron
This bundle is marked as approved. It works and satisfies the submission rules.
Hey.

Some time ago I made the CustomBar.
Now I have made a new system, the SpellBar!

It creates SpellProgress bar for your hero skills. Automaticly gets removed on spell finish and/or aborts.

Requires CustomBar and ARGB in order to work.
(Both included)

Please give credits, comments and such.
System request by: corley

Update1: Added more documentation and is now more user friendly.
Script

Code (vJASS):

//*|------------------------------------------------------------------------------------|>
//*| SpellBar v.1.00 |>
//*| by dhk_undead_lord aka Anachron |>
//*| |>
//*| ABOUT: |>
//*| This system provides you with the ability to create RPG cast |>
//*| bars, such as in World of Warcraft. |>
//*| |>
//*| WHAT YOU NEED: |>
//*| You need JassNewGenPack to use this vJASS system. |>
//*| (Download it here: http://www.wc3c.net/showthread.php?goto=newpost&t=90999) |>
//*| |>
//*| STEPS TO IMPORT: |>
//*| I.) Copy this code. |>
//*| II.) Paste it into the head of your map. |>
//*| (Therefor go to the Trigger Editor, select the mapname and paste |>
//*| into the area on the right) |>
//*| III.) Save your map! |>
//*| (With File - Save Map (S) or control + S. DO NOT SAVE WITH SAVE AS!) |>
//*| IV.) You got it! You imported the system. |>
//*| |>
//*| To make sure this system works, you should try a few tests! |>
//*|------------------------------------------------------------------------------------|>
library SpellBar initializer init requires CustomBar

    //=!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#
    //: Change anything below to what you need!
    //=!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#

    //: The customizeable constants.
    //: I hope the names are self-explaining.
    globals
        private constant real TIMER_TICK = 0.03
    endglobals

    //=!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#
    //: I don't recommend changing code below this!
    //=!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#
    globals
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //: System data.
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        private hashtable SpellBarInstances = InitHashtable()
        private trigger SystemTrigger = CreateTrigger()

    endglobals

    public function updateSpellBar takes CustomBar cb returns nothing
        local SpellBar sb = SpellBar(LoadInteger(SpellBarInstances, GetHandleId(cb.target), 0))
        set cb.txtBar.percentage = (sb.elapsed / sb.max) * 100
    endfunction

    public function showCheck takes player owner, player cur returns boolean
        return IsPlayerAlly(owner, cur) or owner == cur
    endfunction

    //: A struct which contains all SpellBar
    //: information we need.
    struct SpellBar
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        //: SpellBar members
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        private CustomBar cb = 0
        public real elapsed = 0.
        public real max = 0.
        public unit han = null

        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        //: Static members
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        private static timer TIMER = CreateTimer()
        private static thistype array INSTANCES[8191]
        private static integer INDEX = 0

        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        //: SpellBar methods
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        private static method drainInst takes thistype this returns boolean
            if .elapsed < .max then
                set .elapsed = .elapsed + TIMER_TICK
                return false
            else
                call .destroy()
                return true
            endif
        endmethod

        private static method drain takes nothing returns nothing
            local integer i = 0

            loop
                exitwhen i >= thistype.INDEX

                if thistype.drainInst(thistype.INSTANCES[i]) then
                    set i = i - 1
                endif

                set i = i + 1
            endloop

            if thistype.INDEX <= 0 then
                call PauseTimer(thistype.TIMER)
            endif
        endmethod

        public static method create takes unit u, integer i, real dur, CustomBar b returns thistype
            local thistype this = thistype.allocate()
            local ARGB left = 0
            local ARGB right = 0
            local CustomBar c = 0

            //: Set variables
            set .han = u
            set .max = dur

            //: Save the CustomBar
            set .cb = b

            set thistype.INSTANCES[.INDEX] = this
            set thistype.INDEX = thistype.INDEX + 1
            if thistype.INDEX == 1 then
                call TimerStart(thistype.TIMER, TIMER_TICK, true, function thistype.drain)
            endif
            call SaveInteger(SpellBarInstances, GetHandleId(u), 0, integer(this))

            return this
        endmethod

        private method onDestroy takes nothing returns nothing
            set thistype.INSTANCES[integer(this)] = thistype.INSTANCES[thistype.INDEX]
            set thistype.INDEX = thistype.INDEX - 1
            call FlushChildHashtable(SpellBarInstances, GetHandleId(.han))
            call .cb.destroy()
        endmethod
    endstruct

//: Handles the SpellBar removing
//: if unit gets an new order while casting.
    private function eventHandler takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer i = GetHandleId(u)
        local integer sbID = LoadInteger(SpellBarInstances, i, 0)
        local SpellBar sb = SpellBar(sbID)

        if sb.han != null then
            call sb.destroy()
        endif
    endfunction

    //: This function now registers any order which is able to
    //: interrupt the spell cast. Default is everything.
    private function init takes nothing returns nothing
        local integer i = 0

        call TriggerAddAction(SystemTrigger, function eventHandler)

        loop
            exitwhen i >= 15

            call TriggerRegisterPlayerUnitEvent(SystemTrigger, Player(i), EVENT_PLAYER_UNIT_ISSUED_ORDER, null)
            call TriggerRegisterPlayerUnitEvent(SystemTrigger, Player(i), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, null)
            call TriggerRegisterPlayerUnitEvent(SystemTrigger, Player(i), EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, null)

            set i = i + 1
        endloop
    endfunction

endlibrary
 



Example

Code (vJASS):

scope SpellBarTest initializer init

    private function newSpellBar takes nothing returns nothing
        local CustomBar c       = 0
        local ARGB      left    = 0
        local ARGB      right   = 0
       
        //: =-------------------=
        //: Initialize CustomBar
        //: =-------------------=
        //: Add Colors
        set left = ARGB.create(255, 8, 74, 16)
        set right = ARGB.create(255, 214, 255, 230)
        //: I Highly suggest to not touch this->
        set c = CustomBar.create(GetTriggerUnit(), CustomBar_iChange.SpellBar_updateSpellBar)
        //: Add a gradient
        call c.txtBar.addGradient(left, right, 1, 25)
        //: Show the CustomBar to this playergroup
        call c.Show(bj_FORCE_ALL_PLAYERS, CustomBar_iShow.SpellBar_showCheck)
        //: Display the CustomBar.
        call c.showCB()
        //: Now change our CustomBar to display the Spellname aswell.
        set c.txtBar.limiterVisible = true
        set c.txtBar.limiterSymbolRight = ""
        set c.txtBar.limiterSymbolLeft = GetObjectName('AHhb') + "\n"
       
        //: Actually creates the SpellBar
        call SpellBar.create(GetTriggerUnit(), 'AHhb', 2.00, c)
    endfunction

    private function holyLightOnly takes nothing returns boolean
        return GetSpellAbilityId() == 'AHhb'
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0

        call TriggerAddAction(t, function newSpellBar)
        call TriggerAddCondition(t, Condition(function holyLightOnly))

        loop
            exitwhen i >= 15

            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_CHANNEL, null)
            set i = i + 1
        endloop

        set t = null
    endfunction

endscope
 





Keywords:
Spell, Bar, Ability, Custom, Awesome, RPG, WoW, World of Warcraft, Role Play Gaming
Contents

Spellbar v.1.01 (Map)

Reviews
Moderator
14:28, 5th Nov 2009 The_Reborn_Devil: The code looks pretty good and there's nothing wrong with this as far as I can see. It's pretty easy to make a SpellBar with your system, but I don't think it's easy enough for everyone. All this is a little...
  1. 14:28, 5th Nov 2009
    The_Reborn_Devil:

    The code looks pretty good and there's nothing wrong with this as far as I can see. It's pretty easy to make a SpellBar with your system, but I don't think it's easy enough for everyone.
    All this is a little much I think for some of our users:
    JASS!!!
    Code (vJASS):
    local CustomBar c = 0
            local ARGB left = 0
            local ARGB right = 0

            //: =-------------------=
            //: Initialize CustomBar
            //: =-------------------=
            //: Add Colors
            set left = ARGB.create(255, 8, 74, 16)
            set right = ARGB.create(255, 214, 255, 230)
            //: I Highly suggest to not touch this->
            set c = CustomBar.create(GetTriggerUnit(), CustomBar_iChange.SpellBar_updateSpellBar)
            //: Add a gradient
            call c.txtBar.addGradient(left, right, 1, 25)
            //: Show the CustomBar to this playergroup
            call c.Show(bj_FORCE_ALL_PLAYERS, CustomBar_iShow.SpellBar_showCheck)
            //: Display the CustomBar.
            call c.showCB()
            //: Now change our CustomBar to display the Spellname aswell.
            set c.txtBar.limiterVisible = true
            set c.txtBar.limiterSymbolRight = ""
            set c.txtBar.limiterSymbolLeft = GetObjectName('AHhb') + "\n"

            //: Actually creates the SpellBar
            call SpellBar.create(GetTriggerUnit(), 'AHhb', 2.00, c)

    Yes, I'm aware of the fact that you need to have a lot of functions to make it as customizable as it its, but it could be easier.

    Status: Approved
    Rating: Recommended

    If you make it even more user-friendly then I will consider giving this the rating "Highly Recommended".
     
  2. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,147
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    BetA release.

    Please report bugs and such.
     
  3. Garra

    Garra

    Joined:
    Dec 9, 2007
    Messages:
    152
    Resources:
    0
    Resources:
    0
    well you need to make it so moving stops the casting
     
  4. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,147
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    It already does.

    Edit: I will soon edit this, so you should check the new version later this day.
    Its getting ALOT easier for GUI users and ALOT more documentation.
     
    Last edited: Nov 3, 2009
  5. The_Witcher

    The_Witcher

    Joined:
    Dec 29, 2008
    Messages:
    229
    Resources:
    13
    Tools:
    1
    Spells:
    12
    Resources:
    13
    no it doesn't!!
    if you order the unit to walk away while he casts using the bar, he isn't following the order and the bar stays active.

    only the STOP order aborts the channeling
     
  6. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,147
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    In my test the walk away did not interrupt the spell cast...?!


    Guys really: If you order them to move / patrol whatever the spell cast continues,
    that is normal. (Such as wc3 spell cast)

    THAT is wc3!
     
    Last edited: Nov 3, 2009
  7. eleljrk

    eleljrk

    Joined:
    Aug 27, 2009
    Messages:
    461
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    The Witcher failed...

    Anachron, good to see you makeing Examples for your custom bars.. Or, i guess it is.. But if it is, you should add it into the main Download. And make it an Extra! :D
     
  8. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,147
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    Update: Added a lot more user friendly documentation and code management.
     
  9. corley

    corley

    Joined:
    Apr 3, 2006
    Messages:
    517
    Resources:
    0
    Resources:
    0
    Hey Anachron, just wanted to say thanks for doing this sytem and changing the documentation to be newb friendly for people like me, and also massive thanks for the tech support :p +rep dude u really do deserve it.
     
  10. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,147
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    Corley has used it in his RPG.

    Here are some examples:
    look.JPG
     
  11. Deaod

    Deaod

    Joined:
    Nov 18, 2007
    Messages:
    804
    Resources:
    12
    Maps:
    1
    Spells:
    11
    Resources:
    12
    Dont let the user do it?

    This is horribly scoped. Why allow a user to change the elapsed member? Or the max member? Or the han member (whatever that one is)?

    Theres no documentation AT ALL. What are the things i can do with it? The example doesnt show everything.

    Also, having the create a CustomBar AND a SpellBar seems horribly complicated. Simplify the API, please.
     
  12. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,147
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    Why not?

    Han = Handle = The actual unit.
    Max and elapsed are also changeable because some effects could just reset the castpoint.

    Its commented. And it really does.

    Those are 2 diffrent things. The spellbar actually has a CustomBar.

    Later you will see why my Librarys are reuseable and yours not. Its mainly because I don't bound librarys to each other, that really sucks.
     
  13. Deaod

    Deaod

    Joined:
    Nov 18, 2007
    Messages:
    804
    Resources:
    12
    Maps:
    1
    Spells:
    11
    Resources:
    12
    Because someone will fuck it up. Hide the low level shit from morons.
    Thats why making the han member private is a good idea. To hell with the option to change the unit casting dynamically. Its not needed and only bloats the library's API.

    Changing the max and elapsed members also isnt needed. Not at all. Its a useless feature.

    And your example doesnt show everything. max, elapsed and han are a good example. Theyre listed nowhere, except in the code, and frankly, noone will look over the code to learn the API. Thats why you document code.

    I freaking know the SpellBar has a CustomBar. You could simplify it by automagically creating a CustomBar inside a SpellBar. Less confusion for the user.
     
  14. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,147
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    I have got a few replies to my system, and for example corley doesn't know lot about jass, but he is learning.

    I will not remove functionality just because one doesn't need it at all. I already used it in an spell manipulator (Unit casts backwards).

    See last.

    The example shows how you can configure an advanced Bar.

    I had it like that at first but I decided to give the user the possibility to create the CustomBar themself, to generate user specialized bars.
     
  15. CHA_Owner

    CHA_Owner

    Joined:
    Feb 11, 2008
    Messages:
    799
    Resources:
    2
    Spells:
    2
    Resources:
    2
    For some reason i can not see the bar!

    - im using windows xp
    - i've tried on 3 different comps. still nothing shows

    can someone please help me figure out why?
     
  16. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,147
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    Which resolution do you use? YOu might have to change the TT_DEFAULT_SIZE to not 7.5 x but 10x and resave it. Happens on small monitors.
     
  17. dragor-X

    dragor-X

    Joined:
    Feb 26, 2008
    Messages:
    173
    Resources:
    0
    Resources:
    0
    Is it possible to make only visible to the player casting the spell??? Would make a big plus :O :D And you could also write Casting over the head of the caster so that ennemies knows that they're casting a spell but they can't see if they're pretty done casting the spell or have just started (hope you understand)

    Just make a boolean and if true then (for the map maker options) it'll allow this.

    In other words: show bar to everybody =>
    FALSE = your current system, showing the bar to everyone, even ennemies
    TRUE = my suggestion, shows the bar to allies only, the ennemies will see ''Casting'' floating text over the Caster.
     
  18. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,147
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    Code (vJASS):

    call c.Show(bj_FORCE_ALL_PLAYERS, CustomBar_iShow.SpellBar_showCheck)
     

    Use your own function here that returns true and use the force of the player you need.

    Well, this is really individual and would blow up the system. Its really easy to add it yourself since this has nothing to do with Bars anymore.
     
  19. CHA_Owner

    CHA_Owner

    Joined:
    Feb 11, 2008
    Messages:
    799
    Resources:
    2
    Spells:
    2
    Resources:
    2
    Your the best i didn't realize how awesome these bars are until i could actually see them.

    +rep and yes now they work fine :thumbs_up: