• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

How do I make this MUI?

Status
Not open for further replies.
Level 2
Joined
Feb 24, 2020
Messages
11
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.

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.
 

Attachments

  • Example.w3m
    17.9 KB · Views: 13
This is in most cases the time it takes until the spells effect starts.
JASS:
BlzGetUnitRealField(GetTriggerUnit(), UNIT_RF_CAST_POINT) + BlzGetAbilityRealLevelField(GetSpellAbility(), ABILITY_RLF_CASTING_TIME, 0)

One should not use GetTriggerUnit() inside the timer callback function.

Reserver handleIds for the Text simpleframes. call them right after the frame creation outside of the GetLocalPlayer() block to not encounter desyncs in mp.
call BlzGetFrameByName("MyBarExText",1)
call BlzGetFrameByName("MyBarText",1)

You should decide for an approach:
Do you want one frameSet created per cast or have one frameset which displays something. The current create one set per cast does not consider the position of already created ones nor destroys the frames when done.
As UI is mostly for the local player I suggest one frameset which displays data for the current local player and it has one timer (for the UI) which updates the UI. You can still have other timers for the unit casting but they don't handle the UI.

One unit can cast only one ability at a time (outside instants which don't have cast times).
You would store active casters, the casted spell and some way to know how much time passed since the casting (could create & start a timer for that. Timer can give remaining and elapsed time). Then when the cast finished/broke you remove it from the active casters.




You should create such posts in which your want people helping with your triggers/code in the Triggers & Scripts section. World Editor Help Zone is more about general world editor help.


Good Luck
 
Level 2
Joined
Feb 24, 2020
Messages
11
Thank you Tasyen.

I was able to solve it thanks to you. Not sure about how efficient it is, but it works.
 
Status
Not open for further replies.
Top