vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

[Snippet] Timed Effects

moyack · 8511

0 Members and 1 Guest are viewing this topic.

Rating

Average Score - 5 / 5

« Created: August 06, 2018, 08:39:36 AM by moyack »

[Snippet] Timed Effects
on: January 09, 2012, 07:03:32 PM
Category: Execution, Variables
Language: vJASS

Related Topics or Resources



by

Timed Effects
by moyack. 2009-2011
Introduction

So... have you been needing a simple way (or function) to create an effect temporally and don't worry about destroying it? or you're needing that an effect with different animations (birth, stand, death) will show all of them?? if your answer is yes to any of those questions, then you're in the right place.

This script is used in my project Power of Corruption, as you'll see, it's simple as hell.

Just to point out: this library is very useful with effects that have different animations, so using this library with single animation effect will do the same as
Code: jass



How to use it?

Just add an effect as parameter and then you set its duration.

Example:
Code: jass
  1. call StartTimedEffect(AddSpecialEffect(fx, 0., 0.), 2.)


You won't need anything else, the system will care of cleaning the effect properly and recycle the values for you.

The code.

Here we have two flavors, acccording to the timer libraries you could have in your map. Select your best option.

This library requires TimerUtils
Code: jass
  1. //***********************
  2. //*    Timed Effects    *
  3. //*   by moyack. 2011   *
  4. //***********************
  5. //*
  6. //* Requires Jass NewGen Pack and TimerUtils by Various coders
  7. //*    
  8. //* Introduction
  9. //* ============
  10. //*
  11. //* So... have you been needing a simple way (or function) to create an effect temporally
  12. //* and don't worry about destroying it? or you're needing that an effect with different
  13. //* animations (birth, stand, death) will show all of them?? if your answer is yes to any
  14. //* of those questions, then you're in the right place.
  15. //*
  16. //* This script is used in my project Power of Corruption ([url]http://poc.it.cx[/url]), as you'll see,
  17. //* it's simple as hell.
  18. //*
  19. //* Just to point out: this library is very useful with effects that have different
  20. //* animations, so using this library with single animation effect will do the same as
  21. //* call DestroyEffect(AddSpecialEffect(....))
  22. //*
  23. //* How to use it?
  24. //* ==============
  25. //* - Create a trigger with a convenient name (like Timed Effects)
  26. //* - Convert the trigger to custom text
  27. //* - Copy and paste this code and save your map.
  28. //*
  29. //* With all this done, you just have to call the function StartTimedEffect(), and as parameters
  30. //* an effect and a real value which will be the effect duration.
  31. //*
  32. //*   Example: call StartTimedEffect(AddSpecialEffect(fx, 0., 0.), 2.)
  33. //*
  34. //* You won't need anything else, the system will care of cleaning the effect properly
  35. //* and recycle the values for you.
  36.  
  37. library_once TimedEffects requires TimerUtils
  38.  
  39. private struct data
  40.     effect f = null
  41.     timer t
  42.     static method create takes effect f returns data
  43.         local data dt = data.allocate()
  44.         set dt.t = NewTimer()
  45.         set dt.f = f
  46.         call SetTimerData(dt.t, integer(dt))
  47.         return dt
  48.     endmethod
  49. endstruct
  50.  
  51. private function DestroyTimedEffect takes nothing returns nothing
  52.     local data d = data(GetTimerData(GetExpiredTimer()))
  53.     call DestroyEffect(d.f)
  54.     call ReleaseTimer(d.t)
  55.     call d.destroy()
  56. endfunction
  57.  
  58. function StartTimedEffect takes effect f, real dur returns nothing
  59.     local data d = data.create(f)
  60.     call TimerStart(d.t, dur, false, function DestroyTimedEffect)
  61. endfunction
  62.  
  63. endlibrary


This library requires TimedLoop
Code: jass
  1. //***********************
  2. //*    Timed Effects    *
  3. //*   by moyack. 2011   *
  4. //***********************
  5. //*
  6. //* Requires Jass NewGen Pack and TimedLoop by Vexorian
  7. //*    
  8. //* Introduction
  9. //* ============
  10. //*
  11. //* So... have you been needing a simple way (or function) to create an effect temporally
  12. //* and don't worry about destroying it? or you're needing that an effect with different
  13. //* animations (birth, stand, death) will show all of them?? if your answer is yes to any
  14. //* of those questions, then you're in the right place.
  15. //*
  16. //* This script is used in my project Power of Corruption ([url]http://poc.it.cx[/url]), as you'll see,
  17. //* it's simple as hell.
  18. //*
  19. //* Just to point out: this library is very useful with effects that have different
  20. //* animations, so using this library with single animation effect will do the same as
  21. //* call DestroyEffect(AddSpecialEffect(....))
  22. //*
  23. //* How to use it?
  24. //* ==============
  25. //* - Create a trigger with a convenient name (like Timed Effects)
  26. //* - Convert the trigger to custom text
  27. //* - Copy and paste this code and save your map.
  28. //*
  29. //* With all this done, you just have to call the function StartTimedEffect(), and as parameters
  30. //* an effect and a real value which will be the effect duration.
  31. //*
  32. //*   Example: call StartTimedEffect(AddSpecialEffect(fx, 0., 0.), 2.)
  33. //*
  34. //* You won't need anything else, the system will care of cleaning the effect properly
  35. //* and recycle the values for you.
  36.  
  37. library_once TimedEffects requires TimedLoop
  38.  
  39. private struct data
  40.     effect f = null
  41.     real time = 0.
  42.     real dur
  43.    
  44.     private method onTimedLoop takes nothing returns boolean
  45.         set .time = .time + TimedLoop_PERIOD
  46.         if .time > .dur then
  47.             call DestroyEffect(.f)
  48.             return TimedLoop_STOP
  49.         endif
  50.         return TimedLoop_CONTINUE
  51.     endmethod
  52.    
  53.     implement TimedLoop
  54.    
  55.     static method create takes effect f, real t returns thistype
  56.         local thistype dt = thistype.allocate()
  57.         set dt.dur = t
  58.         set dt.f = f
  59.         call dt.startTimedLoop()
  60.         return dt
  61.     endmethod
  62. endstruct
  63.  
  64. function StartTimedEffect takes effect f, real dur returns nothing
  65.     local data d = data.create(f,dur)
  66. endfunction
  67.  
  68. endlibrary

Changelog

 * 1/21/2009: First Release
 * 3/08/2009: Now
Code: jass
  1. StartTimedEffect
returns the index of the TimedEffect object and added the
Code: jass
  1. StopTimedEffect
function so you can stop it manually.
 * 3/20/2009: Simplified more to avoid the .execute call
 * 6/10/2011: Added TimedLoop version
« Last Edit: December 23, 2017, 11:40:27 AM by moyack »



 

Power of Corruption - A Warcraft III altered melee map   Chaos Realm - The world of Game modders and wc3 addicts     WC3JASS.com - The JASS Vault   Jetcraft - A Starcraft II mod