• Runes of Magic Addons
  • Runes of Magic
  • Average Rating:

  • Your Rating

  • Share
  • Report Abuse

Timed Functions

 

Project Updated:
Files Updated: Thu, Jul 23 2009
Supports Game Version: Unknown
Category: Libraries, and Development Tools
Tags:

[Edit Tags]

Project Manager: Maroot
Additional Authors: No additional authors
Current Version: TimedFunctionsLib v0.11
License: GNU Affero General Public License version 3 (AGPLv
Development Site: CurseForge
Avg Daily DL (last 30 days): 2
Downloads Total: 389
Favorites: 0
Comments: 6
  • Curse Giveaways
  • Alganon

    Alganon

    Alganon Open Beta Key Giveaway Alganon is an upcoming fantasy-based MMORPG that allows thousands of people to play together in a virtual world that features a rich history dominated by commanding deities...

    Get Key

  • Contests
  • About Timed Functions
  •  

Current Version: 0.11

[Info]

Timed Functions is an Library / Development tool to aid in adding time-able functions to Runes of Magic. Rather then creating your own "timer" frames and setting up all your necessary functions and timer specific variables for a couple of simple functions you may want to fire at specific times, you can use this tool to simplify the amount of work you have to do. It also serves as a great addition to complex addon's that need a few timer functions.

[How To: Install]
The library is loaded to the current environment (_G) as a table with name "TimedFunctions".
There are two ways to load this module, the first way requires some work by you to make sure the module is loaded before usage.

The First Way: As an Independent AddOn (version 0.10 and lower)
Just copy the folder 'TimedFunctions' to RoM's 'interface\addons' folder.
Because addon's load at different times, there is a chance this library will not load before your addon does, which will break your addon so it is a good idea to check for the timer module before using it. The best way to use the timer module, and stop any possible breakage due to the module not being loaded before your addon, is to have the addon check for the timer module in the 'OnEvent' function of your addon, if it uses any events that is. An example would be something like:

local timer_loaded = false;

function UberAddon_OnEvent(this, event, arg1, arg2, arg3, arg4, arg5, arg6)
     if (not timer_loaded) then
          if (TimedFunctions) then
               timer1 = TimedFunctions:new("UberAddon");
               timer1:RegisterTimedFunction(UberAddon_Timer, 0.500);
               timer_loaded = true;
          end
     end

     -- do other event related stuff

end

Or something similar; so long as you DO NOT try to use the library before it is loaded.

The Second Way: As a Module (Recommended - version 0.11 and higher)

This way is only valid for versions 0.11 and higher, use the first way for older versions.

To use this module the second way you must include the timer module with your addon, and point to the module through your .toc file before you load any of your addon files. You can place the 'TimedFunctions.lua' file either in your addons path directly, or in a separate folder in the same path as your addon, for instance an 'inc' folder. You do not need, and it is recommended that you do not include at all, the two files 'TimedFunctions.toc' & 'TimedFunctions.xml' with the timer module when loading it the Second way.

An example without placing the module in a separate folder:

## Author: Dood
## Tester: N/A
## Title: Killer Dood Addon
## Version : 0.0.1

TimedFunctions.lua

UberDood.lua
UberDood.xml

An example with placing the module in a separate 'inc' folder:

## Author: Dood
## Tester: N/A
## Title: Killer Dood Addon
## Version : 0.0.1

inc/TimedFunctions.lua

UberDood.lua
UberDood.xml

[How To: API]
There are 5 API's you need to be aware of in order to use the library, however the bold are adequate, these are:

:new ([string]);

  • Creates a new timer object of name 'string'. String can be any name, use a prefix of your addon's name or the full name of your addon for instance. If you choose not to pass a string argument then a random object name will be used. This function returns a table with the below functions:

:RegisterTimedFunction (function [, wait [, repeat [, arguments]]]);

  • Registers a function to be fired on the optional wait time, that can be optionally repeated multiple times, with optional arguments. 'function' must be a function, it is preferable to register functions that are local in nature to your addon. As soon as you register a function it starts the timer object so there is no need to start it as it is already running. RegisterTimedFunction returns two methods that pause the current timer object, return the state of the current timer object, or restart it, these are:

:pause (["state"]);

  • Pauses the current timed function. If you provide the :pause() functions with the optional string "state" it will return the current state of the function. Use this to check whether the function has been paused or not either by it having expired its repeats, or because you paused it at some point.

:restart ([ wait [, repeat [, arguments]]]);

  • Restarts a paused function, or a function that has finished its repeat cycle. The optional arguments 'wait' and 'repeat' are used to change the respective options. If you do not include these then the original values you used when you first registered the function are used.
  • 'wait' must be a positive number from '0.100' and higher, note that integer values represent seconds while decimal values represent hundredths of seconds. So for example 0.100 is 100ths of a second and 60 is 60 seconds or 1 minute. The default wait time is 1 second.
  • 'repeat' must be a positive integer value of 1 or higher, negative numbers larger then -1 are converted to positive integers while decimal values represent infinity as does -1. -1 is default.
  • 'arguments' can be of any type, but be aware that they are static and do not change from the time of registration. You MUST include 'wait', and 'repeat' if you want to pass any arguments to your function.

:RemoveTimedFunction (object);

  • Removes all registered functions from the timer if 'object' is a function, or if 'object' is the returned object from 'RegisterTimedFunction' then it removes only that timer object. 'object' must be the function you registered with RegisterTimedFunction, or the object returned from RegisterTimedFunction. RemoveTimedFunction returns 'true' if success or 'false' otherwise.

[Examples]

local huh = "what?";
local function DoSomething(...)
     for i=1,10 do
          DEFAULT_CHAT_FRAME:AddMessage("Doing something this many bloody times now "..tostring(i));
     end
end

local tf = TimedFunctions:new("UberSkillzAddon");
local timer1 = tf:RegisterTimedFunction(DoSomething, 5);		-- do every 5 seconds
local timer2 = tf:RegisterTimedFunction(DoSomething, 0.500, 2);		-- do every half second and repeat 2 times

if (timer2:pause("state")) then print("I'm paused"); end               -- Checks the state of the timer

local timer3 = tf:RegisterTimedFunction(DoSomething, 60, -1, "blah", {"blah"}, huh); -- do every minute, repeat forever and use these 3 arguments
timer3:pause();                                                         -- pauses the timer

tf:RemoveTimedFunction(DoSomething);			    	        -- Remove all of the functions 'DoSomething' in the timer instance "UberSkillzAddon"

tf:RemoveTimedFunction(timer1);                                         -- Removes timer1 object from the timer instance "UberSkillzAddon"
  • Downloads (6)
  •  
File Name Release Type Game Version Downloads Date
Addon Curse.com Beta 2.3.3 0 9/29/2008
  File Name Release Type Game Version Downloads Date  
  Timed Functions TimedFunctionsLib v0.11 Release Unknown 222 7/23/2009
  Timed Functions TimedFunctionsLib Release Unknown 22 7/22/2009
  Timed Functions TimedFunctionsLib Release 1825 46 7/15/2009
  Timed Functions TimedFunctionsLib Release 1825 45 7/10/2009
  Timed Functions TimedFunctionsLib Release 1825 23 7/10/2009
  • Comments

Add Comment  

Add

You need to login or register to post.

Benefits of Registration

  • Interact with hundreds of thousands of other gamers on an open social network.
  • Post your stories, news, images, videos, and other content to share.
  • Create a network with your fellow gamers or join an existing one.
  • Gain reputation for everything you do.
  • TBTFayna said

    Thanks so much for writing this library! I just implemented it to finish up my first simple addon. I'm happy to credit you in the toc if you would like. I left your code as-is so your credited anyway but if you would like the extra add, let me know!

    Reply Report Permalink
  • wjteach said

    looks nice. but for us noobs, could you please consider adding a GUI? in the meantime, where do i insert code? in the .lua? and if yes, where?
    tks

    Reply Report Permalink
  • Maroot said

    I thought about adding a GUI, but this module is designed with the addon scripter in mind. In order for a person to use this module with any degree of success they need to already know how to code in Lua; they need to already have written some functions in Lua that they wish to have on a timer.

    This is a development tool that aids in automating certain aspects of addon's functions.

    Adding a GUI won't remove the need to know how to code in Lua and write working functions from scratch, you'll still have to write code.

    So in other words it doesn't really cater to the 'noob'. A GUI would just add to the overhead of the module, which is meant to be used by addon's as a timer class that has very little overhead. Rather then developers using a module that has a whole bunch of other functions that they may not want to use when all they wish for is a timer class, they can use this one.

    Reply Report Permalink
  • trojan99 said

    could you expand on the arguments? for example could the following be true?
    local timer1 = tf:RegisterTimedFunction(cast Poison, 600.000, 6);
    meaning the rogue buff for poison, assuming u have poison in your inventory, be cast every 10 minutes for 6 repetitions?
    and assuming that to be correct syntax, to restart that argument i would use:
    restart (local timer1);

    again, assuming the above to be correct, how would i manipulate that to include static hotbar items such as potions? or can this addon avoid the limitations of the autoheal addons and simply use inventory as long as im specific about the item name?
    local timer2 = tf:RegisterTimedFunction(use Basic Heal Potion, 60.000, -1);

    again, assuming the above to b correct, in what way would i use the 'if' variable to state something like if health = 50% then execute, otherwise ignore

    thank u for ur time, look forward to installing this

    Reply Report Permalink
  • Maroot said

    If we are assuming the syntax is correct here, then yes, that could be true. You can cast poison every 10 minutes 6 times, or use a heal potion.

    You can pretty much do what ever you desire with-in the limitations of the available API's from RoM. Once you create a timer object with the :new() method, then register a function you want to be on a timer, at that point the timer is started and running. You don't need to restart it unless the function had repeats and they expired, or you physically stop the timer.

    To check your toons health percentage you need the use of two API's; UnitHealth() & UnitMaxHealth().

    Divide the UnitHealth by the UnitMaxHealth and/or times it by 100 to get your percent of health remaining. eg.

    local function GetHealthPercentage(toon)
    return math.floor((UnitHealth(toon) / UnitMaxHealth(toon)) * 100) or -1;
    end

    where 'toon' is a string of like "player", "target", "targettarget", etc etc. If you wanted to check the health of your toon, and heal yourself at 50% health using a bag item, you'd have to create a function to do all that, and then assign it to a timer object so it runs when ever you want it to run. for example:

    local timer1 = TimedFunctions:new("healmeh_plox");

    local function CheckHealth()
    if (GetHealthPercentage("player") <= 50) then
    UseItem("Basic Health Potion");
    return;
    end
    end

    if (timer1) then
    timer1:RegisterTimedFunction(CheckHealth, 600, 6);
    end

    That is pretty much all you'd need for a heal-meh type do-dad.

    It is all about what you have your functions doing, you can use bag items, eat, drink, cast, what ever you want, so long as you know the games API's that perform the actions you want them to...

    Hope that helped answer your questions with out throwing to much 'huh' in there? =)

    Reply Report Permalink
  • Maroot said

    German localization translations are done, thanks goes to Samtrion for the translations.

    Reply Report Permalink
  • Some german Translation be usefully pls.

    Reply Report Permalink
  • Maroot said

    I am currently trying to find an interpreter who knows both English and German well enough to translate. Thanks for your input.

    Reply Report Permalink
  • Maroot said

    Any questions feel free to ask, please leave a comment if you find this useful. Also, please let me know of any issues or additions you'd like to see, thanks!

    Reply Report Permalink
  • 1 page(s)
  • Similar Addons
  •  

Average downloads per day

  1. 293 StatRating Tooltip, Bags & Inventory...
  2. 133 AddonManager Map & Minimap, and Development...
  3. 25 BossHelperMod Quests & Leveling, Libraries...
  4. 20 DevTools Libraries, and Development...
  5. 19 ABugCatcher Development Tools, Chat &...