Hi
I already have another unrelated question up, so if I am not allowed to post another I will remove this one.
I've written this code that creates a casting bar, but if two units cast at the same time it breaks the bar. I am not well versed in vJass at all, so would anyone be able to help me with making this code in to a MUI code? I've also added an example map where there is a casting bar for Flame Strike.
Oh and if anyone knows how to pull the cast time of used spell that would also be amazing, so that I don't have to save them in hashtables.
I already have another unrelated question up, so if I am not allowed to post another I will remove this one.
I've written this code that creates a casting bar, but if two units cast at the same time it breaks the bar. I am not well versed in vJass at all, so would anyone be able to help me with making this code in to a MUI code? I've also added an example map where there is a casting bar for Flame Strike.
JASS:
globals
real array CastTimeAbil[20]
endglobals
function Change takes nothing returns nothing
local unit CastingUnit = GetTriggerUnit()
local integer i=GetSpellAbilityId()
local real r = (1/CastTimeAbil[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))]/0.33)
local framehandle bar = BlzGetFrameByName("MyBarEx",1)
local framehandle bar2 = BlzGetFrameByName("MyBar",1)
local timer CastTimer = GetExpiredTimer()
if (BlzFrameGetValue(bar) < 100) then
if(GetLocalPlayer() != GetOwningPlayer(GetTriggerUnit())) then
call BlzFrameSetValue(bar, BlzFrameGetValue(bar) + r)
call BlzFrameSetText(BlzGetFrameByName("MyBarExText",1), SubString(R2S((100-BlzFrameGetValue(bar))*CastTimeAbil[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))]*0.01),0,3))
endif
else
call BlzFrameSetValue(BlzGetFrameByName("MyBarEx",1),0)
if(GetLocalPlayer() != GetOwningPlayer(CastingUnit)) then
call BlzFrameSetVisible(bar,false)
call BlzFrameSetVisible(bar2,false)
endif
call DestroyTimer(CastTimer)
endif
endfunction
function Trig_Nahkampf_Initialisierung_Actions takes nothing returns nothing
local framehandle bar = BlzCreateSimpleFrame("MyBarEx", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), 1) //Create Bar at createContext 1
local framehandle bar2 = BlzCreateSimpleFrame("MyBar", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), 1) //Create Bar at createContext 1
local unit CastingUnit = GetTriggerUnit()
local integer i=GetSpellAbilityId()
local timer CastTimer = CreateTimer()
set bar = BlzGetFrameByName("MyBarEx",1)
set bar2 = BlzGetFrameByName("MyBar",1)
set CastTimeAbil[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] = 0
set CastTimeAbil[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] = LoadReal(udg_CastHash,i,GetUnitAbilityLevel(CastingUnit,i))
if (CastTimeAbil[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] != 0) then
if(GetLocalPlayer() == GetOwningPlayer(GetTriggerUnit())) then
call BlzFrameSetVisible(bar,true)
call BlzFrameSetVisible(bar2,true)
call BlzFrameSetPoint(bar2, FRAMEPOINT_TOP, bar, FRAMEPOINT_LEFT, -0.02, 0.01)
call BlzFrameSetAbsPoint(bar, FRAMEPOINT_CENTER, 0.475, 0.17) // pos the bar
call BlzFrameSetValue(BlzGetFrameByName("MyBarEx",1),0)
call BlzFrameSetSize(bar, 0.25, 0.02)
call BlzFrameSetSize(bar2, 0.025, 0.025)
call BlzFrameSetValue(bar2, 100)
call BlzFrameSetTexture(bar, "Replaceabletextures\\Teamcolor\\Teamcolor03.blp", 0, true) //change the BarTexture of bar to color red
call BlzFrameSetTexture(bar2, BlzGetAbilityIcon(i), 0, true)
call BlzFrameSetText(BlzGetFrameByName("MyBarExText",1), SubString(R2S(CastTimeAbil[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))]),0,3))
call BlzFrameSetText(BlzGetFrameByName("MyBarText",1), "")
endif
call TimerStart(CastTimer, 0.03, true, function Change)
set CastTimer = null
endif
endfunction
//===========================================================================
function InitTrig_CastingBar takes nothing returns nothing
set gg_trg_CastingBar = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_CastingBar, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
call TriggerAddAction( gg_trg_CastingBar, function Trig_Nahkampf_Initialisierung_Actions )
call LoadToc("war3mapimported\\mybar.toc")
endfunction
Oh and if anyone knows how to pull the cast time of used spell that would also be amazing, so that I don't have to save them in hashtables.