Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

Author Topic: [Snippet] Timed Effects  (Read 7561 times)

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 986
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • WC3 Models: 25
  • WC3 Tutorials: 13
  • WC3 Tools: 10
  • WC3 Maps: 11
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
[Snippet] Timed Effects
« on: January 09, 2012, 07:03:32 PM »
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  [Select]



How to use it?

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

Example:
Code: jass  [Select]
  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  [Select]
  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  [Select]
  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  [Select]
  1. StartTimedEffect
returns the index of the TimedEffect object and added the
Code: jass  [Select]
  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: April 15, 2012, 09:21:33 AM by moyack »

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

 

[Snippet] Group Units in line, with distance and optional spread-value

Started by rvonsonsnadtzBoard Codes & Snippets

Replies: 5
Views: 11617
Last post March 13, 2013, 06:52:16 PM
by rvonsonsnadtz
[Snippet] Single Player Detector

Started by moyackBoard Codes & Snippets

Replies: 12
Views: 21235
Last post March 13, 2013, 12:48:49 PM
by Magtheridon96
[Snippet] Simple Unit Indexer

Started by moyackBoard Codes & Snippets

Replies: 17
Views: 26150
Last post September 30, 2013, 08:07:19 AM
by moyack
[Snippet] Disable Transmission Skip

Started by PurgeandfireBoard Codes & Snippets

Replies: 2
Views: 8858
Last post July 02, 2013, 01:34:55 PM
by Purgeandfire
[Snippet] Parabolic Function

Started by moyackBoard Codes & Snippets

Replies: 1
Views: 7194
Last post January 13, 2012, 12:11:45 PM
by Magtheridon96
Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!