Thread Tools Display Modes
05-09-10, 07:43 AM   #1
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Is this correct LUA?

So, I tried to play with some LUA and VFL things again.

Code:
function dscd()
	local divinestormcd, duration, enabled = GetSpellCooldown("Divine Storm");
	if ( divinestormcd > 0 and duration > 1.5) then
		VFL.AdaptiveSchedule(dstas, 0.1, dst);
	end
end;
VFL.AdaptiveSchedule(nil, 0.1, dscd);

function dst()
	local divinestormcd, duration, enabled = GetSpellCooldown("Divine Storm");
	if ( divinestormcd > 0 and duration > 1.5) then
		nil
	else
		print("Divine Storm Ready!") and VFL.AdaptiveUnschedule(dstas);
	end
end;
I want RDX to track my Divine Storm cooldown for me, and this is what I got. (stole most of the script from other sources, and tried to scrap it all together X_X)
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
05-09-10, 08:07 AM   #2
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Tried this, I THINK it's more efficient, or no?

Code:
function dst()
	local divinestormcd, duration, enabled = GetSpellCooldown("Divine Storm");
	if not ( divinestormcd > 0 and duration > 1.5) then
		print("Divine Storm Ready!") and VFL.AdaptiveUnschedule(dstas);
	end
end;

function dscd()
	local divinestormcd, duration, enabled = GetSpellCooldown("Divine Storm");
	if ( divinestormcd > 0 and duration > 1.5) then
		VFL.AdaptiveSchedule(dstas, 0.1, dst);
	end
end;
VFL.AdaptiveSchedule(nil, 0.1, dscd);
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
05-09-10, 09:40 AM   #3
Brainn
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 263
Code:
	if not ( divinestormcd > 0 and duration > 1.5) then
		print("Divine Storm Ready!") and VFL.AdaptiveUnschedule(dstas);
	end
this is not valid lua code.

use this instead:
Code:
	if not ( divinestormcd > 0 and duration > 1.5) then
		print("Divine Storm Ready!");
                VFL.AdaptiveUnschedule(dstas);
	end

i dont think the changes you made in the second post provide any significant performance improvemts, but checking for the cd every 0.1 seconds is a very inefficient way to handle this. there should be some events you can use.
create an anonymous frame and register an event to that frame, then use the OnEvent handler to call your cd-checking function.
check the event-section on wowwiki for a event that suites your needs.
  Reply With Quote
05-10-10, 09:46 AM   #4
Dgrimes
A Black Drake
 
Dgrimes's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 89
With RDX you actually don't need to create any frames to bind custom events.

You would want to use the function
Code:
WoWEvents:Bind("EVENT_NAME", nil, function to call on event);
I tried finding out what the
Code:
 nil
was for but I was unable to determine the functionality of that variable spot.

If you are hooking this into in autoexec you would want to add after the function you are calling to check the argument that was passed through the event and the rest of the code.
__________________
What was is, what will be was.
  Reply With Quote
05-10-10, 10:36 AM   #5
Brainn
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 263
dgrimes is right, you can use WoWEvents:Bind() instead of an anonymous frame to handle your events, im just too used to using frames from the time before RDX supported scripting in the way it does now

for the "nil" part, i dont know if it would work with that in there, but for understanding what it should do in there ill abstract the code a bit:
Code:
if somestuff then 
   do nothing ==> this is the "nil" part
else
   do stuff
end
thats why he used
Code:
if not somestuff then
   do stuff
end
in the second version.
  Reply With Quote
05-10-10, 10:56 AM   #6
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Actually Brainn, I believe he means nil in:

Code:
WoWEvents:Bind("EVENT_NAME", nil, function to call on event);
I think Dg knows what Nil means otherwise :P
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
05-10-10, 11:12 AM   #7
Dgrimes
A Black Drake
 
Dgrimes's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 89
Ok here is the code you can use:
Code:
local function dscd()
   local start, duration, enabled = GetSpellCooldown(53385);

    if (duration > 1.5) and ( start > 0) then
    local timeleft = (start + duration) - GetTime();
    
    VFL.ZMSchedule(timeleft, function() VFL.print("Divine Storm Ready!"); end);
    end
end


WoWEvents:Bind("SPELL_UPDATE_COOLDOWN", nil, dscd);
That should work for you.
__________________
What was is, what will be was.
  Reply With Quote
05-10-10, 09:28 PM   #8
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Originally Posted by Dgrimes View Post
Ok here is the code you can use:
Code:
local function dscd()
   local start, duration, enabled = GetSpellCooldown(53385);

    if (duration > 1.5) and ( start > 0) then
    local timeleft = (start + duration) - GetTime();
    
    VFL.ZMSchedule(timeleft, function() VFL.print("Divine Storm Ready!"); end);
    end
end


WoWEvents:Bind("SPELL_UPDATE_COOLDOWN", nil, dscd);
That should work for you.
Ah, this would work perfectly if not for a little trick.

There's a method to my madness in using an adaptiveschedule, in that regular timers don't work with my 2P T10 retribution, which has a 40% on hit to cause Divine Storm to reset cooldown.

I have no set time that I know when Divine Storm will come back up, so I figured the most efficient way to do this was for it to update as often as possible?

The combat log reports this, "Divine Storm!" when the 2 piece T10 goes off, according to wowhead. http://www.wowhead.com/spell=70769

So maybe it can be done more efficiently with other binds, but I'm not sure.

I wish there was an easy way to do it. x3
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
05-11-10, 02:50 AM   #9
sigg
Featured Artist
 
sigg's Avatar
Featured
Join Date: Aug 2008
Posts: 1,251
Hello

To bind a single function to an event :
WoWEvents:Bind("EVENT_NAME", nil, function() end, "id");

To unbind the function :
WoWEvents:Unbind("id");

To bind a frame (or a table) to an event :
local Obj = createFrame();
Obj.func = function() ... end;
WoWEvents:Bind("EVENT_NAME", Obj, Obj.func, "id");

To unbind a frame (or a table) :
WoWEvents:Unbind("id");

The power of RDX :
RDXEvents (for the Unit Engine) (See UDB file for the list of events)
OmniEvents (for the combat logs)
DesktopEvents (for the desktop change and all)
BossmodsEvents (for the bossmods)
etc ...

Cheers
Sigg
  Reply With Quote

WoWInterface » Featured Projects » OpenRDX » OpenRDX Community » OpenRDX: Community Chat » Is this correct LUA?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off