Thread Tools Display Modes
08-24-15, 06:01 AM   #1
wrathdamage
A Murloc Raider
Join Date: Aug 2015
Posts: 4
Inserting lua into TMW

I am trying to make a code that i can put into a tmw snippet that will calculate starfires and wraths dps/sp
Then use a condition that will show starfire if it does more dps/sp than wrath

so far i have
Code:
sfgeneral = function ()
        name, rank, icon, castTime, minRange, maxRange, spellID = GetSpellInfo(2912);
        sfcasttime = castTime*.001;
        cpower= UnitPower("player", 8);
        edirection = GetEclipseDirection();
        if edirection == "moon" then sffem = (math.max(-100,math.min(100,105*math.sin(math.pi - math.asin(cpower/105) + math.pi/10 * sfcasttime))));
            elseif edirection == "sun" then sffem = (math.max(-100,math.min(100,105*math.sin(math.asin(cpower/105) + math.pi/10 * sfcasttime))));
            else sffem = (math.max(-100,math.min(100,105*math.sin(math.pi - math.asin(cpower/105) + math.pi/10 * sfcasttime))));
        end
        getmas= GetMasteryEffect()+30;
        sfdmg=224.6*(1+(((-1*(sffem))+100)/2/100*getmas)/100)/sfcasttime;
    end
sfgeneral();
print(sfdmg);
wgeneral = function ()
        name, rank, icon, castTime, minRange, maxRange, spellID = GetSpellInfo(5176);
        wcasttime = castTime*.001;
        cpower= UnitPower("player", 8);
        edirection = GetEclipseDirection();
        if edirection == "moon" then wfem = (math.max(-100,math.min(100,105*math.sin(math.pi - math.asin(cpower/105) + math.pi/10 * wcasttime))));
            elseif edirection == "sun" then wfem = (math.max(-100,math.min(100,105*math.sin(math.asin(cpower/105) + math.pi/10 * wcasttime))));
            else wfem = (math.max(-100,math.min(100,105*math.sin(math.pi - math.asin(cpower/105) + math.pi/10 * wcasttime))));
        end
        getmas= GetMasteryEffect()+30;
        wdmg=140.4*(1+(((wfem)+100)/2/100*getmas)/100)/wcasttime;
    end
wgeneral();
print (wdmg);
Which prints the correct dps/sp for both spells when run

But i don't understand how to make variables local and still have access to them
I also dont understand how to define in functions for conditions in TMW.CNDT.Env
as instructed to do so in TMW

Also i expect that my code is flawed as i only just started with lua

If anyone can help me make this work it would mean alot
I am really at a loss with this

Thanks in advance
Mentaur-Defias Brotherhood
  Reply With Quote
08-24-15, 07:08 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
What is TMW? Searching for that on this site yields no results.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-24-15, 07:25 AM   #3
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
TellMeWhen
  Reply With Quote
08-24-15, 07:30 AM   #4
wrathdamage
A Murloc Raider
Join Date: Aug 2015
Posts: 4
Yes TellMeWhen similar to weak auras but i find it more simple to use
http://wow.curseforge.com/addons/tellmewhen/

Last edited by wrathdamage : 08-24-15 at 07:40 AM.
  Reply With Quote
08-24-15, 08:10 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, I can't find any TellMeWhen documentation that looks anything like what you posted, so I don't know what you were looking at, but based on this MMO-Champion thread I'd guess something like this should work:

Code:
function TMW.CNDT.Env.StarfireBetterThanWrath()
	-- Get player info:
	local power = UnitPower("player", 8)
	local direction = GetEclipseDirection()
	local mastery = GetMasteryEffect() + 30

	-- Get spell info:
	local starfireName, _, starfireIcon, starfireCastTime = GetSpellInfo(2912)
	local wrathName, _, wrathIcon, wrathCastTime = GetSpellInfo(5176)
	starfireCastTime = starfireCastTime / 1000
	wrathCastTime = wrathCastTime / 1000

	-- Calculate spell damage:
	local starfire, wrath
	if direction == "moon" then
		starfire = math.max(-100, math.min(100, 105 * math.sin(math.pi - math.asin(power / 105) + math.pi / 10 * starfireCastTime)))
		wrath = math.max(-100, math.min(100, 105 * math.sin(math.pi - math.asin(power / 105) + math.pi / 10 * wrathCastTime)))
	elseif direction == "sun" then
		starfire = math.max(-100, math.min(100, 105 * math.sin(math.asin(power / 105) + math.pi / 10 * starfireCastTime)))
		wrath = math.max(-100, math.min(100, 105 * math.sin(math.asin(power / 105) + math.pi / 10 * wrathCastTime)))
	else
		starfire = math.max(-100, math.min(100, 105 * math.sin(math.pi - math.asin(power / 105) + math.pi / 10 * starfireCastTime)))
		wrath = math.max(-100, math.min(100, 105 * math.sin(math.pi - math.asin(power / 105) + math.pi / 10 * wrathCastTime)))
	end
	starfire = 224.6 * (1 + ((-starfire + 100) / 2 / 100 * mastery) / 100) / starfireCastTime
	wrath = 140.4 * (1 + ((wrath + 100) / 2 / 100 * mastery) / 100) / wrathCastTime
	
	-- Return true if Starfire is better than Wrath:
	return starfire > wrath
end
Then in the options you would add a condition with Type: Lua and this:
Code:
StarfireBetterThanWrath()
Then you'd set it up so if the condition passed, show a Starfire icon, otherwise show a Wrath icon.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-24-15, 08:10 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, I can't find any TellMeWhen documentation that looks anything like what you posted, so I don't know what you were looking at, but based on this MMO-Champion thread I'd guess something like this should work:

Code:
function TMW.CNDT.Env.StarfireBetterThanWrath()
	-- Get player info:
	local power = UnitPower("player", 8)
	local direction = GetEclipseDirection()
	local mastery = GetMasteryEffect() + 30

	-- Get spell info:
	local starfireName, _, starfireIcon, starfireCastTime = GetSpellInfo(2912)
	local wrathName, _, wrathIcon, wrathCastTime = GetSpellInfo(5176)
	starfireCastTime = starfireCastTime / 1000
	wrathCastTime = wrathCastTime / 1000

	-- Calculate spell damage:
	local starfire, wrath
	if direction == "moon" then
		starfire = math.max(-100, math.min(100, 105 * math.sin(math.pi - math.asin(power / 105) + math.pi / 10 * starfireCastTime)))
		wrath = math.max(-100, math.min(100, 105 * math.sin(math.pi - math.asin(power / 105) + math.pi / 10 * wrathCastTime)))
	elseif direction == "sun" then
		starfire = math.max(-100, math.min(100, 105 * math.sin(math.asin(power / 105) + math.pi / 10 * starfireCastTime)))
		wrath = math.max(-100, math.min(100, 105 * math.sin(math.asin(power / 105) + math.pi / 10 * wrathCastTime)))
	else
		starfire = math.max(-100, math.min(100, 105 * math.sin(math.pi - math.asin(power / 105) + math.pi / 10 * starfireCastTime)))
		wrath = math.max(-100, math.min(100, 105 * math.sin(math.pi - math.asin(power / 105) + math.pi / 10 * wrathCastTime)))
	end
	starfire = 224.6 * (1 + ((-starfire + 100) / 2 / 100 * mastery) / 100) / starfireCastTime
	wrath = 140.4 * (1 + ((wrath + 100) / 2 / 100 * mastery) / 100) / wrathCastTime
	
	-- Return true if Starfire is better than Wrath:
	return starfire > wrath
end
Then in the options you would add a condition with Type: Lua and enter this:
Code:
StarfireBetterThanWrath()
Then you'd set it up so if the condition passed, show a Starfire icon, otherwise show a Wrath icon.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-24-15, 11:36 AM   #7
wrathdamage
A Murloc Raider
Join Date: Aug 2015
Posts: 4
My word Phanx you are amazing! It works like a charm.
Thankyou so much.

There are a few things that i didn't take in to consideration.

Lunar and solar empowerment's and empowered moonkin.
But i have altered the code to account for these.

At some point i will try to change it to calculate for different talent specs than mine as i feel this is super useful for most moonkins.

Most moonkins are just trying to land wraths in solar and sf's in lunar but this looses potential dps.

Thanks Phanx

Last edited by wrathdamage : 08-24-15 at 01:08 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Inserting lua into TMW


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