Okay, so I'm making a system to display a cast bar underneath the hero model, but I have run into a problem. It simply freezes when I run it. After a 30 second-ish time period, the game unfreezes again and i can see the Debug messages "Loop" and "%" but none of the other ones. I bet I did something overly nubbish. hehe
Anyway, could anybody help me out a bit?
-Thanks in advance
Also, I assume my CastbarData.Wait() function is kind of crappy... How would I go about incorporating a timer instead, I'm not very good with those. =/
Anyway, could anybody help me out a bit?
-Thanks in advance
JASS:
library CastbarDisplaySystemV1
private constant function GetCastbarCharacter takes nothing returns string
return "]"
endfunction
private constant function GetCastbarSize takes nothing returns real
return .01
endfunction
struct CastbarData
unit caster
real totalCastTime
real currentTime = 0
real percentFilled
texttag castbar = CreateTextTag()
string display = ""
string color
// calculate percentage filled
// rounds down to the nereast multiple of 5
method CalculatePercentageFilled takes nothing returns nothing
set this.percentFilled = I2R(R2I(((this.currentTime/this.totalCastTime)*200)/10))
endmethod
// setup the display string
method SetDisplay takes nothing returns nothing
local integer i = 0
// setup the front of the colored portion
set this.display = "|cff" + this.color
// filled castbar
loop
exitwhen i >= this.percentFilled
set this.display = this.display + GetCastbarCharacter()
set i = i + 1
endloop
// end the colored portion
set this.display = this.display + "|r"
// empty castbar
loop
exitwhen i >= 20
set this.display = this.display + GetCastbarCharacter()
set i = i + 1
endloop
endmethod
// Draw the castbar
method Draw takes nothing returns nothing
local real xpos = GetUnitX(this.caster)
local real ypos = GetUnitY(this.caster) - 25.0
call DestroyTextTag(this.castbar)
set this.castbar = CreateTextTag()
call SetTextTagText(this.castbar, this.display, GetCastbarSize())
call SetTextTagPos(this.castbar, xpos, ypos, -15)
call SetTextTagVisibility(this.castbar, false)
call SetTextTagVisibility(this.castbar, not IsUnitFogged(this.caster, GetLocalPlayer()))
endmethod
// wait .1 secs -> increment time
method Wait takes nothing returns nothing
set this.currentTime = this.currentTime + .025
call TriggerSleepAction(.025)
endmethod
endstruct
function CastbarDisplay takes unit caster, real totalCastTime, string color returns nothing
local CastbarData data = CastbarData.create()
local timer t = CreateTimer()
set data.caster = caster
set data.totalCastTime = totalCastTime
set data.color = color
loop
exitwhen data.currentTime >= data.totalCastTime
// calculate the percentage of the bar to be filled
call data.CalculatePercentageFilled()
// set display
call data.SetDisplay()
// draw the castbar
call data.Draw()
// wait and increment time
call data.Wait()
endloop
call DestroyTextTag(data.castbar)
call data.destroy()
endfunction
endlibrary
Also, I assume my CastbarData.Wait() function is kind of crappy... How would I go about incorporating a timer instead, I'm not very good with those. =/
Last edited: