View Full Version : Adding a timer to an addon
Blackal
16-07-2007, 05:58 PM
Hi Everyone!
Just for a little background, I am creating an addon that will hadle our guild's custom DKP sytem. This addon will need to have a status bar which I have already created. It will also need ot have a 30 second timer that will make the status bar decrease as the time passes.
Does anyone have any ideas how I would go about setting up the timer? I know how to change the status bar value once I've got the timer set up, I just don't know where to look for the timer issue.
Thanks in advance for any help!
Blackal
Jumpy
16-07-2007, 06:39 PM
In your xml ....
<Scripts>
<OnUpdate>
MyAddon_Timer(arg1)
</OnUpdate>
</Scripts>
In your Lua
MA_lasttimecheck = 0
function MyAddon_Timer(elapsed)
MA_lasttimecheck = MA_lasttimecheck + elapsed
if (MA_lasttimecheck >= 30) then
MA_lasttimecheck = 0
-- do stuff here every 30 seconds
-- do stuff here every 30 seconds
end
end
Blackal
16-07-2007, 06:54 PM
Thanks for the quick response! I'll try that later. Do we know ho often OnUpdate fires?
Blackal
16-07-2007, 07:11 PM
I actually found in another thread where you said that.
In your LUA you have a function "YourAddon_OnUpdate();" that is called about 50 times per second when the frame is visible.
Is it always 50 times a second, or does that vary?
Blackal
17-07-2007, 04:34 AM
Ok, I've got how to setup a statusbar to decrease on a timer now. That is for the client addon. What about in the admin addon?
In the addon, the timer will be started and sent to the raid like this: /ddkp start [item].
This will do a SendAddonMessage() to the raid that triggers my timed window to pop up on all the client machines. Each of these will have 5 buttons that the user can choose. When a button is chosen, and SendAddonMessage() is fired from the client with type of "whisper" to the raid leader.
There is no frame in the admin addon, it only has slash commands. I have included a frame, though, to fire an OnLoad and OnEvent. Here is what it looks like:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="DeKPAdmin.lua"/>
<Frame name="DeKPAdmin">
<Scripts>
<OnLoad>
DeKPAdmin_OnLoad();
</OnLoad>
<OnEvent>
ddkp_event(event);
</OnEvent>
</Scripts>
</Frame>
</Ui>
And here is my event handler:
function ddkp_event(event)
if ((event == "ADDON_LOADED") and (arg1 == "DeKPAdmin")) then
DEFAULT_CHAT_FRAME:AddMessage("Defiant Kill Points Admin "..DeKPAdmin_Version.." loaded ! ", 1.0, 0.0, 0.0 );
end;
if ( event == "CHAT_MSG_ADDON" and arg1 == "DeKP" and arg3 == "WHISPER") then
end;
end;
What I want to do is ONLY accept the replys from the clients within the 30 second timer. And once that 30 second timer is up, move on to do the calculations.
Is there a clean, easy, ay to do this?
Thanks in advance for all your help.
Thanks!
Blackal
Jumpy
17-07-2007, 08:00 AM
I actually found in another thread where you said that.
Is it always 50 times a second, or does that vary?
It varies. It happens when the game screen is refreshed (framerate). But the 30 second timer should be accurate enough for your purpose.
Jumpy
17-07-2007, 08:11 AM
What I want to do is ONLY accept the replys from the clients within the 30 second timer. And once that 30 second timer is up, move on to do the calculations.
Is there a clean, easy, ay to do this?
Maybe set a flag when you start the timer, turn off the flag when the timer gets to 30 and in your event handler check to see if the flag is on, and if not then bypass the handler.
Blackal
17-07-2007, 08:57 AM
Maybe set a flag when you start the timer, turn off the flag when the timer gets to 30 and in your event handler check to see if the flag is on, and if not then bypass the handler.
Thanks for the reply, jumpy. I thought of that as well. But I don't have an XML frame in the admin addon that is running the OnUpdate code that the client is running.
Theoretically, though, even the person running the admin addon will also be running the client addon, so I could use a flag variable in the client addon and access that variable from within the admin addon. But I would rather each of them be self contained.
So I guess there are two ways to do it (keep each self contained):
1. Set up a frame in the admin addon that would function the same way as the one in the client addon so that I can keep track of the timer that way. But this way seems bloated since I would already have this same functionality in the client addon).
2. Set up a timer in the event code that without an XML frame that would keep track of the time. (Is this even possible)?
Or lastly, I could just make the admins also install the client and use the flag variable there. That seems the simplest, but I'd like your thoughts on what the best way to go about it is.
And than you so much for all of your help, Jumpy!
Blackal
Blackal
17-07-2007, 10:18 AM
Nevermind! I figured out the answer to my own question! Here are some excerpts from ym code. Thanks again for all the help Jumpy!
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="DeKPAdmin.lua"/>
<Frame name="DeKPAdmin">
<Scripts>
<OnLoad>
DeKPAdmin_OnLoad();
</OnLoad>
<OnEvent>
ddkp_event(event);
</OnEvent>
<OnUpdate>
ddkp_OnUpdate();
</OnUpdate>
</Scripts>
</Frame>
</Ui>
function DeKPAdmin_OnLoad()
SlashCmdList["DeKPAdmin"] = ddkp_cmd;
SLASH_DeKPAdmin1 = "/ddkp";
SLASH_DeKPAdmin2 = "/dedkp";
this:RegisterEvent("ADDON_LOADED");
this:RegisterEvent("VARIABLES_LOADED");
this:RegisterEvent("CHAT_MSG_WHISPER");
this:RegisterEvent("CHAT_MSG_ADDON");
end
function ddkp_cmd(cmd)
if string.sub(string.lower(cmd),1,5) == "start" then
ddkp_start();
return;
elseif string.sub(string.lower(cmd),1,4) == "stop" then
ddkp_stop();
return;
end;
end;
function ddkp_start()
DEFAULT_CHAT_FRAME:AddMessage("Starting Auction...");
ddkp_results = {};
startTime = GetTime();
timer_active = true;
end;
function ddkp_stop()
DEFAULT_CHAT_FRAME:AddMessage("Stopping Auction...");
ddkp_results = {};
timer_active = false;
end;
function ddkp_OnUpdate()
if(timer_active) then
if (math.floor(GetTime()-startTime) >= 30) then
ddkp_stop();
end;
end;
end;
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.