1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Ride into the sunset with the 32nd Modeling Contest. The contest is optionally paired. Best of luck, people!
    Dismiss Notice
  4. This adventure has come to an end. Congratulate our heroes in the 16th Mini Mapping Contest Results.
    Dismiss Notice
  5. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  6. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Making countdown timers MUI

Discussion in 'World Editor Help Zone' started by Tiche3, May 8, 2010.

  1. Tiche3

    Tiche3

    Joined:
    Jun 25, 2009
    Messages:
    432
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Hey guys, i wanted to ask you how to make Countdown timers MUI, to destroy it after and etc, should i make 10 timers (vars), because array doesn't work on this thing :cry: Waiting for help.

    Tiche3:grin:
     
  2. Noobsmoke

    Noobsmoke

    Joined:
    Nov 20, 2007
    Messages:
    631
    Resources:
    1
    Spells:
    1
    Resources:
    1
    u can use indexes
     
  3. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,237
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    Yea, try making a stack of objects to handle within 1 global timer which is paused and started (but never destroyed)

    Here's an example from my contest submission:

    Code (vJASS):


    scope blast initializer i
        private struct kbDat
            unit pushee
            real degDirection
            integer power
        endstruct
       
        globals
            private constant integer BLASTID='A004'
            private unit tempCaster
            private timer time=CreateTimer()
            private integer dbIndex=-1
            private group grp=CreateGroup()
            private kbDat array kbDB
        endglobals
       
        private function p takes nothing returns nothing
            local integer index=0
            local kbDat tempDat
            local real x
            local real y
            loop
                exitwhen index>dbIndex
                set tempDat=kbDB[index]
                set x=GetUnitX(tempDat.pushee)+tempDat.power*Cos(tempDat.degDirection*bj_DEGTORAD)
                set y=GetUnitY(tempDat.pushee)+tempDat.power*Sin(tempDat.degDirection*bj_DEGTORAD)
                if IsTerrainWalkable(x,y) then
                    call SetUnitX(tempDat.pushee,x)
                    call SetUnitY(tempDat.pushee,y)
                else
                    set tempDat.power=1
                endif
                set tempDat.power=tempDat.power-1
                if tempDat.power<1 then
                    call tempDat.destroy()
                    set kbDB[index]=kbDB[dbIndex]
                    set dbIndex=dbIndex-1
                    if dbIndex==-1 then
                        call PauseTimer(time)
                    endif
                endif
                set index=index+1
            endloop
        endfunction

        private function f takes nothing returns boolean
            local kbDat tempDat
            if IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(tempCaster)) then
                set tempDat=kbDat.create()
                set tempDat.pushee=GetFilterUnit()
                set tempDat.degDirection=bj_RADTODEG*Atan2(GetUnitY(GetFilterUnit())-GetUnitY(tempCaster),GetUnitX(GetFilterUnit())-GetUnitX(tempCaster))
                set tempDat.power=20
                set dbIndex=dbIndex+1
                set kbDB[dbIndex]=tempDat
                if dbIndex==0 then
                    call TimerStart(time,.03,true,function p)
                endif
            endif
            return false
        endfunction
       
        private function c takes nothing returns boolean
            if GetSpellAbilityId()==BLASTID then
                set tempCaster=GetSpellAbilityUnit()
                call GroupEnumUnitsInRange(grp,GetUnitX(GetSpellAbilityUnit()),GetUnitY(GetSpellAbilityUnit()),500,Filter(function f))
            endif
            return false
        endfunction
       
        private function i takes nothing returns nothing
            local trigger t=CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
            call TriggerAddCondition(t,Condition(function c))
        endfunction
    endscope
     
     
  4. Pharaoh_

    Pharaoh_

    Joined:
    Nov 6, 2008
    Messages:
    8,128
    Resources:
    11
    Icons:
    3
    Skins:
    1
    Spells:
    6
    Tutorials:
    1
    Resources:
    11
    Tiche3, since I know you mostly use GUI and Cokemonkey11's way might be too advanced for you, your easiest solutions are:

    • If you are working with low value timers, create a dummy unit and give it an expiration timer. Attach every value the dummy unit should have via hashtables. Example:
    • Trigger
    • Events
      • Map Initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Hashtable = (Last created hashtable)

    • Trigger1
    • Events
      • Unit - A unit starts the effect of an ability
    • Conditions
    • Actions
      • Set Point1 = (Position of (Triggering unit))
      • Unit - Create 1 dummytimer for (Owner of (Triggering unit)) at Point1 facing default building degrees
      • Hashtable - Save 900.00 as (Key(life)) of (Key(Last created unit)) in Hashtable //Hashtable - Save Real
      • Hashtable - Save Handle of (Triggering unit) as (Key(caster)) of (Key(Last created unit)) in Hashtable //Hashtable - Save Unit
      • Unit - Add a 2.00 seconds generic expiration timer to (Last created unit)
      • Custom script: call RemoveLocation (udg_Point1)

    • Trigger2
    • Events
      • Unit - A unit dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to dummytimer
    • Actions
      • Set Unit1 = (Load (Key(caster)) of (Key(Triggering unit)) in Hashtable)
      • Set Real1 = (Load (Key(life)) of (Key(Triggering unit)) in Hashtable)
      • Unit - Set life of Unit1 to ((Life of Unit1) + Real1)
      • Hashtable - Clear all child hashtables of (Key(Triggering unit)) from Hashtable


    This will restore 900.00 hp after 2.00 seconds.

    • If you are working with higher values, e.g. 14 seconds, you can use a periodic event that substracts value.
    • Trigger1
    • Events
      • Unit - A unit starts the effect of an ability
    • Conditions
    • Actions
      • Unit Group - Add (Triggering unit) to TempGroup
      • Hashtable - Save 14 as (Key(timer)) of (Key(Triggering unit)) in Hashtable //Hashtable - Save Integer
      • Trigger - Turn on Trigger2 <gen>

    • Trigger2
    • Events
      • Time - Every 1.00 seconds of game-time
    • Conditions
    • Actions
      • If (All conditions are true) then do (Actions) else do (Actions)
        • If - Conditions
          • (TempGroup is empty) Equal to True
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • Set Integer = (Load (Key(timer)) of (Key(Picked unit)) from Hashtable)
              • If (All conditions are true) then do (Actions) else do (Actions
                • If - Conditions
                  • Integer Not Equal to 0
                • Then - Actions
                  • Hashtable - Save (Integer - 1) as (Key(timer)) of (Key(Picked unit)) in Hashtable
                  • Unit - Set life of (Picked unit) to (((Life of (Picked unit)) + 20.00)
                • Else - Actions
                  • Unit Group - Remove (Picked unit) from TempGroup
                  • Hashtable - Clear all child hashtables of (Key(Picked unit)) from Hashtable


    This one will add 20.00 life to your unit every second, for 14 seconds.

    Disclaimer: The methods mentioned are not better than the solution proposed by Cokemonkey11 and king_drift_alex, it's just the easiest way for someone that uses GUI.
     
  5. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,237
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    Sorry didn't know you were using GUI. If you're trying to make MUI custom spells that use timers you should really learn jass.
     
  6. Tiche3

    Tiche3

    Joined:
    Jun 25, 2009
    Messages:
    432
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Hmm thanks guys, but it's kind of for my hero reviving countdown timers. :) Tell me if you have another way please, because the ones you wrote is for abilities and using groups or so, i don't really get Htables (and believe me i read tuts).
    So yeah, i'll be waiting for further answers :)

    Tiche3:grin:
     
  7. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,237
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    Is this a map where each player has only 1 hero?
     
  8. Tiche3

    Tiche3

    Joined:
    Jun 25, 2009
    Messages:
    432
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Yep, it's a Hero fight map :)
     
  9. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,237
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    Then you can simply make it MPI and not MUI

    Simply make a timer array and timer dialog array, and then refer to each one using their player's ID (0-11)
     
  10. Tiche3

    Tiche3

    Joined:
    Jun 25, 2009
    Messages:
    432
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Could you write the triggers please, because i use an array and it doesnt work.:cry:
     
  11. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,237
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    Could you show us the code you used please? I'd rather explain to you what's wrong with yours and how to fix it than make it for you.
     
  12. Tiche3

    Tiche3

    Joined:
    Jun 25, 2009
    Messages:
    432
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Okay.

    • Hero Revive
      • Events:
        • Unit - A unit Dies
      • Conditions:
        • (Triggering Unit) is A Hero
      • Actions:
        • If (All conditions) are True then (Do actions) else (Do actions)
          • If - Conditions:
            • (Owner of (Triggering Unit)) is Player 2 (Blue)
          • Then - Actions:
            • Countdown Timer - Start Hero_Timer[1] as a One Shot timer that expires in (Real(Level of (Triggering Unit))x2)
            • Countdown Timer - Hide (Last Created Countdown Timer)
            • Countdown Timer - Show (Last Created Countdown Timer) to (Owner of (Triggering Unit))
            • Wait - Wait (Real(Level of (Triggering Unit))x2) seconds
            • Set Revive_Pos[1]=(Position of (Circles[1]))
            • Hero - Revive (Triggering Unit) instantly at Revive_Pos[1] Show revival graphics
            • Countdown Timer - Destroy (Last Created Countdown Timer)
            • Custom script: call RemoveLocation(udg_Revive_Pos[1])


    And on else i do the same with every player.

    Hope for answers ;p:grin:
     
  13. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,221
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
  14. Tiche3

    Tiche3

    Joined:
    Jun 25, 2009
    Messages:
    432
    Resources:
    1
    Spells:
    1
    Resources:
    1
    No this doesn't. My waits don't leak. Hero spawn even if multiple dies at the same moment.
     
  15. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,237
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    Timers need to be created before they can be used.
     
  16. Tiche3

    Tiche3

    Joined:
    Jun 25, 2009
    Messages:
    432
    Resources:
    1
    Spells:
    1
    Resources:
    1
    I'm sorry, i was lazy and wrote it by myself, i'll copy the triggers out of my map directly.:grin: