• 🏆 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!

Casting Time System/Snippet

Level 3
Joined
Apr 10, 2007
Messages
23
I made a Snippet for Casting Time:

It creates the Time a Spell is casting At the heroes location.
it is leakless and MPI.

enjoy!

Code:
  • Let Unit Cast
    • Events
      • Unit - A unit Begins casting an ability
      • Unit - A unit Begins channeling an ability
    • Conditions
    • Actions
      • Set Casting[(Player number of (Owner of (Casting unit)))] = 0.00
      • Set Casting_Unit_Loc[(Player number of (Owner of (Casting unit)))] = (Position of (Casting unit))
      • Set Casting_Time[(Player number of (Owner of (Casting unit)))] = True
  • Casting Time
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Casting_Time[(Integer A)] Equal to True
            • Then - Actions
              • Set Casting[(Integer A)] = (Casting[(Integer A)] + 0.01)
              • Floating Text - Destroy Casting_Floating_Text[(Integer A)]
              • Floating Text - Create floating text that reads (Casting Time: + (String(Casting[(Integer A)]))) at Casting_Unit_Loc[(Integer A)] with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
              • Set Casting_Floating_Text[(Integer A)] = (Last created floating text)
            • Else - Actions
  • Stop Unit Cast
    • Events
      • Unit - A unit Stops casting an ability
      • Unit - A unit Finishes casting an ability
    • Conditions
    • Actions
      • Set Casting_Time[(Player number of (Owner of (Casting unit)))] = False
      • Floating Text - Destroy Casting_Floating_Text[(Player number of (Owner of (Casting unit)))]
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Casting unit)) Equal to (Player((Integer A)))
            • Then - Actions
              • Custom script: call RemoveLocation (udg_Casting_Unit_Loc[GetForLoopIndexA()])
            • Else - Actions
 

Attachments

  • Casting time system.w3x
    17.2 KB · Views: 48
Last edited by a moderator:
Level 6
Joined
Sep 5, 2007
Messages
264
There are more efficient ways of doing this...

I'm not picking here, but there are better ways to achieve the same effect:

If you use JASS and the handle var attachment system (many different ones are out there), then you could avoid destroying the text-tag per cycle and just edit the text, then destroy it at the end.

Use a timer instead of a trigger they are faster, and they can't skip.
EG: 0.01 second trigger, with 0.04 seconds passing in between frames (in the case of lag), the trigger will only trigger once per frame, so it will skip. A timer can trigger many times per frame.
Try to avoid using 0.01 second loops, 0.03 - 0.05 is usually fast enough, and doesn't lag as much (try having 5 - 10 triggers running at 0.01 seconds and watch the game lag).

Also, using locations is a much slower way to do things... JASS allows you to use co-ordinates(x,y) instead of locations. Co-ordinates are cheaper on memory and are very easy to use once you get the hang of them.

JASS isn't very difficult to learn, it's pretty straight forward. If you want help in this area, I'd be willing to assist.

I know I may have ranted here abit, but I hope I've helped.
 
Top