TheLegend
New Member
- Reaction score
- 10
Solid Action Bars by TheLegend
UPDATED AND FIXED SOME BUGS
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
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