System Solid Action Bars (not completed)

TheLegend

New Member
Reaction score
10
Solid Action Bars by TheLegend

UPDATED AND FIXED SOME BUGS
JASS:

/*TheLegends Solid Bar system*/
//The system needs NewGen only
/*Features*/
//-By using call SolidBar_barcreate(unit,time,color) the user can create timed bars to represent the channel time, 
// cast time, build time and much nore in no time and leakless. unit- you can refer to any unit. time- just 
// not smaller than 0.1. colors are red, green, blue, black and white
//-Designed to work for multiple units, players and timed stuff
//-The bar is attached to the unit so it moves with it
//-The bars that represent channeled spells and spell cast time will be removed if the unit moves (green and red)
//-The bar is solid
//-The system doesnt leak anything
// IN THE TEST VERSION USE ESCAPE TO START A RANDOM BAR
// IMPLEMENTATION - JUST THIS INTO YOUR MAP
library SolidBar initializer ACDInit
globals
    private integer totaldata = 0               //an index for the total number of bars
    private integer barlength = 100             //I took the length of 100 to make it look better
    private integer fixlength = 5               //This is a tricky one, it makes the bar look more smooth
    private integer destroyedindex              //The index of a destroyed bar, used later
    private real period = 0.1                   //If the period is shorter the bars execute faster so when an unit is moving the bar doesnt jump
                                                //Should be 0.03 - 0.1  -  At 0.1 the bar wont flicker but at 0.03 it will not jump
endglobals
struct bar
    integer index = 0                           //Index of the bar
    unit caster = null                          //The unit that uses it
    real casttime = 0                           //The current time of the bar left
    real casttimetotal = 0                      //The total time of the bar
    real casterx
    real castery
    integer R = 100
    integer G = 100
    integer B = 100
    string type
    method oncreate takes nothing returns nothing
        set totaldata = totaldata + 1
        set this.index = totaldata              //Indexes this bar
        set casterx = GetUnitX(caster)          //This will be used to stop the bars later
        set castery = GetUnitY(caster)
        //The next if sets the color
        if type == "red" then                   //Bars that represent attack cast time and attack channel spells
            set R = 100
            set G = 10
            set B = 10
        elseif type == "blue" then              //Bars that represent researches
            set R = 10
            set G = 10
            set B = 100
        elseif type == "green" then             //Bars that represent healing cast time and healing channel spells
            set R = 10
            set G = 100
            set B = 10
        elseif type == "black" then             //Bars that represent curse or health decrease spells
            set R = 100
            set G = 100
            set B = 100
        endif
    endmethod
    //The oncreate wouldnt execute on the normal creation of the struct so i had to call it later
endstruct
globals
    private bar array data                     //The array of bars
endglobals
private function ondestroydo takes nothing returns nothing
        local integer desync = 1               //A locator of the desynced/deleted bar
        local bar d
        local integer deleted = 0              //This is used just to rearray the bars so that there are no gaps
        loop
            exitwhen desync > totaldata + 1
            set d = data[desync]
            set data[desync - deleted] = data[desync]   //If a bar was deleted the bars after him get moved back one spot
            set d.index = d.index - deleted             //Treir index represents their spot in the array
            if desync == destroyedindex then            //checks if the loop found the deleted bar
                set deleted = 1
                set d.index = 0
                set d.caster = null
                set d.casttime = 0
                call d.destroy()
                set totaldata = totaldata - 1           //nulls all values of the bar and removes it
            endif
            set desync = desync + 1
        endloop
        set desync = 0
        set deleted = 0
        set destroyedindex = 0
endfunction
private function bardestroycheck takes integer bartocheck returns boolean
    local bar checked = data[bartocheck]
    return (checked.type == "green" or checked.type == "red") and GetUnitX(checked.caster) != checked.casterx and GetUnitY(checked.caster) != checked.castery
endfunction
private function timeactions takes nothing returns nothing
    local integer timeactionindex = 0
    local string text
    local integer stringlength
    local bar timeactiondata
    loop
        exitwhen timeactionindex >= totaldata
        set timeactionindex = timeactionindex + 1
        set timeactiondata = data[timeactionindex]
        set timeactiondata.casttime = timeactiondata.casttime - period
        if timeactiondata.casttime > 0 and not bardestroycheck(timeactionindex) then
            set stringlength = R2I(barlength * timeactiondata.casttime / timeactiondata.casttimetotal)
            set text = ""             //I still have that problems with the bars look but it looks nice
            loop                      //To determine how long the bar is in this period
                exitwhen stringlength <= 0
                set text = text + "|"
                set stringlength = stringlength - 1
            endloop
            call CreateTextTagUnitBJ(text,timeactiondata.caster,10,10,timeactiondata.R,timeactiondata.G,timeactiondata.B,50)
            call SetTextTagPermanent(bj_lastCreatedTextTag, false)
            call SetTextTagLifespan(bj_lastCreatedTextTag, period)
            set stringlength = R2I(barlength * timeactiondata.casttime / timeactiondata.casttimetotal) - fixlength
            set text = " "            //This loop makes the bar solid. The blanco is 1.5x the length of | so it makes these | fill the gaps
            loop
                exitwhen stringlength <= 0
                set text = text + "|"
                set stringlength = stringlength - 1
            endloop
            //If you find a way to remove the two "|" in front of the bar pls tell me
            call CreateTextTagUnitBJ(text,timeactiondata.caster,10,10,timeactiondata.R,timeactiondata.G,timeactiondata.B,50)
            call SetTextTagPermanent(bj_lastCreatedTextTag, false)
            call SetTextTagLifespan(bj_lastCreatedTextTag, period)
            set stringlength = 0
        else
            set destroyedindex = timeactiondata.index
            if destroyedindex != 0 then    //IDK why but it keept deleting bar indexed 0 after all others were deleted so i blocked it
                call DisplayTextToPlayer(GetOwningPlayer(timeactiondata.caster),0,0,"Ended a timed ability")
                call ondestroydo()
            endif
        endif
    endloop
    set text = null
    set timeactionindex = 0
endfunction
public function barcreate takes unit cast, real time, string color returns nothing
    local bar new = bar.create()           //Creates a new bar
    set new.caster = cast                  //Sets the caster of the bar
    set new.type = color
    set new.casttime = time                //The time left of casting
    set new.casttimetotal = time           //The total time of cast
    call new.oncreate()                    //Since it wont call it on the .create() had to do it this way
    set data[totaldata] = new              //Stores the new bar
    call DisplayTextToPlayer(GetOwningPlayer(cast),0,0,"Started a timed ability, time " + R2S(new.casttime))
endfunction
function ACDInit takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(t,period)
    call TriggerAddAction(t,function timeactions)
endfunction
endlibrary

Here is the new test map, to start a bar press escape. Youll have to manually change the color in the test trigger
View attachment SBS.w3x
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
i would use T32 instead of your own timer, the interval is very low and that would remove the "jumping" issue, the both the human mind and computers register visual information much faster than 10 times a second thats why it seems choppy

also, remove your BJ's (the ones in red) they can be replaced with what they encapsule, ie:

JASS:
function LoadUnitHandleBJ takes integer parent, integer child, hashtable h returns unit
    call LoadUnitHandle(h, child, parent)
endfunction


so [ljass]call LoadUnitHandleBJ(1, 10, bj_lastCreatedHashtable)[/ljass] should be: [ljass]call LoadUnitHandle(bj_lastCreatedHashtable, 10, 1)[/ljass]
it just skips that extra step

EDIT:

you should probably also improve your documentation, get rid of all those ///////'s lol

it would also be good to add order recognition so if a unit moves while casting it can destroy the bar (as an option)
 

TheLegend

New Member
Reaction score
10
ok thanx for the feedback but there is still one minor problem. If you tested the map you could see that the bars are solid except for their start. it goes like || and then solid. I tried everything but couldn't remove those two |. As for the T32 and my timer comment, I wanted to make a system that wouldn't need any other snippet or library, that would operate alone because I hate when i copy a system and read in the library that it requires T32 of AIDS or something like that. The last comment about destroying the bar, that is hard to do since there are more types of abilities as you know and the player cant "locate" the right bar in the array. I wanted to add different bar colors for different ability types RED - ATTACK CHANNEL; GREEN - HEAL CHANNEL; BLUE - RESEARCH; and so on
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
drop the size to ~7 to get rid of that | |, then make it longer if you want
and the reason why systems require other systems is to make themselves more efficient, without T32 this wont be as efficient as it will be with, simply because with t32 it allows 1 timer for all high frequency periodic timed events
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
you could just save the strings for each using a string version of the type as an integer, like so:
[ljass]set StringVar['healing'] = "|cff00ff00"[/ljass]

dont quote me on that tho, thats spitballing on speculation
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
set fixlenght 4 and set the initial text to make bar solid from " " to "."
You removed 1 bar!
 

TheLegend

New Member
Reaction score
10
improving the lib, brb

EDIT:
i hit a wall...
JASS:
private function bardestroycheck takes integer bartocheck returns boolean
    local bar checked = data[bartocheck]
    return (checked.type == "green" or checked.type == "red") and GetUnitX(checked.caster) != checked.casterx and GetUnitY(checked.caster) != checked.castery
endfunction

returns false only when the color isnt green or red. The checked.casterx and checked.caster y are declared in the oncreate module as GetUnitX(caster) and GetUnitY(caster)

EDIT:
FOUND AND FIXED IT, WILL UPLOAD AFTER TESTING
 

TheLegend

New Member
Reaction score
10
UPLOADED
Still couldn't fix the solid bar bug cause if i change the bar size it wouldn't show up at all. The jumping bug will be fixed later, if i reduce the period the bar starts flickering but doesn't jump
Oh and the code is less red xD
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
to stop the flickering you increase the duration, ie:
every texttag you use to create the bar lasts 0.04 seconds, but you refresh it every 0.03
the bar size stops showing up at like 7 or 8 or something, its just the way they do the math for size, which is kinda retarded, basically to set the size, you do this: set Z offset of texttag = (size * (0.23 / 100)) or something to that effect, but when you get to below 10 the way it does the math winds up at a 0.00 and it just gos agro on you and shows nothing

i made a gui system like this a long time ago for my old rpg, im thinking about re-doing that
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
also, it would be WAY more efficient to have a single base string with all the |s already and use a substring to set 2 variables to a piece of it, then put them together in the display

EDIT:
sorry for double post, i was reading the code and forgot i posted here a sec ago
 

TheLegend

New Member
Reaction score
10
y but if i set a greater duration than the period the bars will overlap and i wont have an transparent bar
EDIT
should i change or add anything else, pls comment
 

Deaod

Member
Reaction score
6
So, what does this library bring to the table, other than a new interface for things that are already possible within existing systems, which, by the way, are more efficient and rather feature-complete? Why does this library have to exist?
 

TheLegend

New Member
Reaction score
10
good question :)
This library is a standalone library, that means you dont "need" any other lib than this one so it shortens your code a lot and doesnt need any model, dummy or whatever. Its easy to operate with and can be modified. You can easily add new colors in the oncreate method. Some loading bars can move with the unit when it moves while others are canceled and the number of bars that can operate at a moment is over 6000 (max number of members of an array). The system wont leak and its quite short when you delete all my comments :). Why choose this? Idk, maybe there is a shorter bar system somewhere but this was a brainwaved idea, i just figured it out and made it within minutes
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top