• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Creating a Countdown Timer in Custom Text GUI

Status
Not open for further replies.
Level 18
Joined
Nov 1, 2006
Messages
1,612
I know this is in GUI, but the lot of it is in custom text which is JASS. I am trying to create a Countdown Timer that shows only for one player that countdowns the time until they respawn. It doesn't work though.

Can anyone tell me why? If so, can you help me fix it? It would be appreciated.

  • Events
    • Unit - A unit Dies
  • Conditions
    • ((Triggering unit) is A Hero) Equal to True
    • (Owner of (Killing unit)) Equal to Neutral Hostile
  • Actions
    • Custom script: local unit DeadHero
    • Custom script: local timer RespawnTimer
    • Custom script: local timerdialog Rwindow
    • Custom script: set DeadHero = GetTriggerUnit()
    • Wait 5.00 seconds
    • Advanced - Only for (Owner of (Triggering unit)) play RestorationPotion <gen>
    • Game - Display to (Player group((Owner of (Triggering unit)))) for 15.00 seconds the text: |cffFF0000Respawn:|...
    • Custom script: call StartTimerBJ( RespawnTimer, false, 25.00 )
    • Countdown Timer - Create a timer window for (Last started timer) with title |cff00FF00Respawn I...
    • Custom script: set Rwindow = GetLastCreatedTimerDialogBJ()
    • Countdown Timer - Hide (Last created timer window)
    • Countdown Timer - Show (Last created timer window) for (Owner of (Triggering unit))
    • Wait 25.00 seconds
    • Custom script: call DestroyTimerDialogBJ( Rwindow )
    • Custom script: set Rwindow = null
    • Custom script: set RespawnTimer = null
    • Custom script: call ReviveHeroLoc( DeadHero, GetRectCenter(gg_rct_Death_Knight), true )
    • Custom script: call SetUnitLifePercentBJ( DeadHero, 50.00 )
    • Custom script: call PanCameraToTimedLocForPlayer( GetOwningPlayer(DeadHero), GetRectCenter(gg_rct_Death_Knight), 0 )
    • Custom script: set DeadHero = null
 
Level 11
Joined
Oct 13, 2005
Messages
233
You're attempting to start RespawnTimer when you never created it. You first need to set RespawnTimer to CreateTimer(). You will then need to destroy the timer at the end of the function. I also noticed you're using waits which almost defeats the purpose of having a timer other than just for the window. You also can make quite a few optimizations to your code. I'll name some of the obvious ones:

1. You're able to create a local variable and set it to a value on the same line. You don't need a separate "set variable = <value>" line for DeadHero. You should also set your timer to CreateTimer() when declaring it as well.

2. Since you're using JASS for creating the timer, why not do the same for the timerdialog? It will allow you to get rid of some additional BJ functions. The way to create a timerdialog is like this in JASS:
JASS:
set myTimerDialog = CreateTimerDialog(someTimer)
call TimerDialogSetTitle(myTimerDialog, "Some title")

// Displays it for all players, additionally you can use GetLocalPlayer()
call TimerDialogDisplay(myTimerDialog, true)

// Displays it only for the owner of DeadHero
if GetLocalPlayer() == GetOwningPlayer(DeadHero) then
    call TimerDialogDisplay(myTimerDialog, true)
endif

3. You can easily change your StartTimerBJ function to TimerStart( myTimer, 25.0, false, null) The first argument is the timer, second is the amount of time, then a boolean value for if it should be periodic, and the last value passed is a callback function to be called when it expires. Since you don't want to call another function when the timer expires, you simply put 'null' there.

4. Change DestroyTimerDialogBJ to DestroyTimerDialog. The BJ function simply calls the native and there's no difference in their arguments.

5. If you care for removing memory leaks, you're leaking a location each time you use GetRectCenter.

6. It looks as if you're using WEU with that "advanced" action. How about I show you how it's done without WEU:
JASS:
if GetLocalPlayer() == GetOwningPlayer(DeadHero) then
    // Any code between here is executed only on the owning player of DeadHero's computer
endif
That's basically how it's done in JASS. You just make a custom script line for the if statement. Next you put your GUI statement after that. Finally, you follow up with a custom script endif and you're got the same thing without having to use WEU.
 
Level 18
Joined
Nov 1, 2006
Messages
1,612
2. Since you're using JASS for creating the timer, why not do the same for the timerdialog? It will allow you to get rid of some additional BJ functions. The way to create a timerdialog is like this in JASS:
JASS:
set myTimerDialog = CreateTimerDialog(someTimer)
call TimerDialogSetTitle(myTimerDialog, "Some title")

// Displays it for all players, additionally you can use GetLocalPlayer()
call TimerDialogDisplay(myTimerDialog, true)

// Displays it only for the owner of DeadHero
if GetLocalPlayer() == GetOwningPlayer(DeadHero) then
    call TimerDialogDisplay(myTimerDialog, true)
endif

What is someTimer? Is that my Timer Dialog variable or my Timer variable? And then how would I display it to only the owning player of DeadHero using Custom Text in GUI, not entirely in JASS?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
someTimer would be a timer.

And why don't you use entirely JASS anyways?

And you would do exactly what I he wrote, with "Custom script" tags

  • Custom script: if GetLocalPlayer() == GetOwningPlayer(DeadHero) then
  • Custom script: call TimerDialogDisplay(myTimerDialog,true)
  • Custom script: endif
 
Last edited:
Level 18
Joined
Nov 1, 2006
Messages
1,612
You wrote? Wait... are you and wyrmlord the same person? I'm confused.

Other than that, I got it to work! So thank you guys for the help. The reason I am not using JASS is because I'm still confused on how some things work, but I think soon enough (if I continue to mod WC3) I will become much better with it. I have been learning a lot lately.

THIS is how it looks now:

  • HandicapRespawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • (Owner of (Killing unit)) Equal to Neutral Hostile
    • Actions
      • Custom script: local unit DeadHero = GetTriggerUnit()
      • Custom script: local timer RespawnTimer = CreateTimer()
      • Custom script: local timerdialog TimerWindow = CreateTimerDialog(RespawnTimer)
      • Custom script: local location TempPoint = GetRectCenter(gg_rct_Death_Knight)
      • Wait 5.00 seconds
      • Advanced - Only for (Owner of (Triggering unit)) play RestorationPotion <gen>
      • Game - Display to (Player group((Owner of (Triggering unit)))) for 15.00 seconds the text: |cffFF0000Respawn:|...
      • Custom script: call TimerStart(RespawnTimer, 25.00, false, null)
      • Custom script: call TimerDialogSetTitle(TimerWindow, "|cff00FF00Respawn In:|r")
      • Custom script: if GetLocalPlayer() == GetOwningPlayer(DeadHero) then
      • Custom script: call TimerDialogDisplay(TimerWindow, true)
      • Custom script: endif
      • Wait 25.00 seconds
      • Custom script: call DestroyTimerDialog(TimerWindow)
      • Custom script: set TimerWindow = null
      • Custom script: call ReviveHeroLoc( DeadHero, GetRectCenter(gg_rct_Death_Knight), true )
      • Custom script: call SetUnitLifePercentBJ( DeadHero, 50.00 )
      • Custom script: call PanCameraToTimedLocForPlayer( GetOwningPlayer(DeadHero), GetRectCenter(gg_rct_Death_Knight), 0 )
      • Custom script: call RemoveLocation(TempPoint)
      • Custom script: set TempPoint = null
      • Custom script: set DeadHero = null
:razz:
 
Level 18
Joined
Nov 1, 2006
Messages
1,612
  • Seconds1
    • Events
      • Time - Every 120.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Player 1 (Red)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Architect
            • Then - Actions
              • Custom script: local location HeroPos = GetUnitLoc(GetEnumUnit())
              • Player - Add 10 to Player 1 (Red) Current gold
              • Advanced - Only for (Owner of (Picked unit)) play ReceiveGold <gen>
              • Custom script: call CreateTextTag( "+10 gold", HeroPos), 0, 8.00, 90.00, 90.00, 15.00, 0 )
              • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
              • Floating Text - Change the fading age of (Last created floating text) to 2.00 seconds
              • Floating Text - Change (Last created floating text): Disable permanence
              • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
              • Custom script: call RemoveLocation(HeroPos)
              • Custom script: set HeroPos = null
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is A Hero) Equal to True
                  • (Unit-type of (Picked unit)) Not equal to Architect
                • Then - Actions
                  • Custom script: local location HeroPos = GetUnitLoc(GetEnumUnit())
                  • Player - Add 5 to Player 1 (Red) Current gold
                  • Advanced - Only for (Owner of (Picked unit)) play ReceiveGold <gen>
                  • Custom script: call CreateTextTag( "+5 gold", HeroPos), 0, 8.00, 90.00, 90.00, 15.00, 0 )
                  • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
                  • Floating Text - Change the fading age of (Last created floating text) to 2.00 seconds
                  • Floating Text - Change (Last created floating text): Disable permanence
                  • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
                  • Custom script: call RemoveLocation(HeroPos)
                  • Custom script: set HeroPos = null
                • Else - Actions
Then why doesn't this work?
 
Last edited:
Level 18
Joined
Nov 1, 2006
Messages
1,612
okay that seems to have gotten the first problem, except now it says

Expected end of line
Expected end of line

for each of the two lines where the floating text is created.

This is how the code looks:

  • Seconds1
    • Events
      • Time - Every 120.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Player 1 (Red)) and do (Actions)
        • Loop - Actions
          • Custom script: local location HeroPos = GetUnitLoc(GetEnumUnit())
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Architect
            • Then - Actions
              • Player - Add 10 to Player 1 (Red) Current gold
              • Advanced - Only for (Owner of (Picked unit)) play ReceiveGold <gen>
              • Custom script: call CreateTextTag( "+10 gold", HeroPos), 0, 8.00, 90.00, 90.00, 15.00, 0 )
              • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
              • Floating Text - Change the fading age of (Last created floating text) to 2.00 seconds
              • Floating Text - Change (Last created floating text): Disable permanence
              • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
              • Custom script: call RemoveLocation(HeroPos)
              • Custom script: set HeroPos = null
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is A Hero) Equal to True
                  • (Unit-type of (Picked unit)) Not equal to Architect
                • Then - Actions
                  • Player - Add 5 to Player 1 (Red) Current gold
                  • Advanced - Only for (Owner of (Picked unit)) play ReceiveGold <gen>
                  • Custom script: call CreateTextTag( "+5 gold", HeroPos), 0, 8.00, 90.00, 90.00, 15.00, 0 )
                  • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
                  • Floating Text - Change the fading age of (Last created floating text) to 2.00 seconds
                  • Floating Text - Change (Last created floating text): Disable permanence
                  • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
                  • Custom script: call RemoveLocation(HeroPos)
                  • Custom script: set HeroPos = null
                • Else - Actions
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
you have an extra bracket after HeroPos in your CreateTextTag functions.

By the way, you can move most of those actions out of the If.

EDIT: as for the invalid no. of parameters on CreateTextTag, here's your answer.

JASS:
function PercentToInt takes real percentage, integer max returns integer
    local integer result = R2I(percentage * I2R(max) * 0.01)

    if (result < 0) then
        set result = 0
    elseif (result > max) then
        set result = max
    endif

    return result
endfunction

function PercentTo255 takes real percentage returns integer
    return PercentToInt(percentage, 255)
endfunction

function TextTagSize2Height takes real size returns real
    return size * 0.023 / 10
endfunction

function SetTextTagColorBJ takes texttag tt, real red, real green, real blue, real transparency returns nothing
    call SetTextTagColor(tt, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction

function SetTextTagPosBJ takes texttag tt, location loc, real zOffset returns nothing
    call SetTextTagPos(tt, GetLocationX(loc), GetLocationY(loc), zOffset)
endfunction

function SetTextTagTextBJ takes texttag tt, string s, real size returns nothing
    local real textHeight = TextTagSize2Height(size)

    call SetTextTagText(tt, s, textHeight)
endfunction

function CreateTextTagLocBJ takes string s, location loc, real zOffset, real size, real red, real green, real blue, real transparency returns texttag
    set bj_lastCreatedTextTag = CreateTextTag()
    call SetTextTagTextBJ(bj_lastCreatedTextTag, s, size)
    call SetTextTagPosBJ(bj_lastCreatedTextTag, loc, zOffset)
    call SetTextTagColorBJ(bj_lastCreatedTextTag, red, green, blue, transparency)

    return bj_lastCreatedTextTag
endfunction
 
Last edited:
Level 18
Joined
Nov 1, 2006
Messages
1,612
Purple... :hohum:... that's all way over my head. I have to do all of that to create a floating text? I don't understand. and I'm using Custom script, not complete JASS for this. I'm guessing that this part--

JASS:
function CreateTextTagLocBJ takes string s, location loc, real zOffset, real size, real red, real green, real blue, real transparency returns texttag
    set bj_lastCreatedTextTag = CreateTextTag()
    call SetTextTagTextBJ(bj_lastCreatedTextTag, s, size)
    call SetTextTagPosBJ(bj_lastCreatedTextTag, loc, zOffset)
    call SetTextTagColorBJ(bj_lastCreatedTextTag, red, green, blue, transparency)

    return bj_lastCreatedTextTag
endfunction


is all that I need to create the Floating Text, by the looks of it, but I don't understand then what all the functions before it were for? were they just different ways of doing it? :con: If that is the way to do it then where do I type the stuff to customize it?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Those were all the functions it uses.

Basically, by interpreting that, you can work out which natives you need to use.

(things that I posted there that go from a function... to an endfunction should not be used for efficiency reasons)

K, this translates from;

call CreateTextTagLocBJ(s,loc,zOffset,size,red,green,blue,transparency)

to

JASS:
local texttag tt = CreateTextTag()
call SetTextTagText(tt,s,size*.023/10)
call SetTextTagPos(tt,GetLocationX(loc),GetLocationY(loc),zOffset)
call SetTextTagColor(tt,<red val - 0 to 255>,<green val - 0 to 255>,<blue val - 0 to 255>,<alpha val - 0 to 255>)
 
Status
Not open for further replies.
Top