Title: SuperMacro and LUA functions - warrior Post by: Supp0se77 on December 08, 2017, 05:54:49 am I've been sorting out how to really use SuperMacro well, aka getting into writing some LUA functions. The problem I'm running into, is that I understand how it works, but am not getting the syntax correct.
I want a SHOUT macro, that checks rage, casts Battle Shout if not buffed, and then Demo Shout. The second one that checks for enough rage to Whirlwind first, then Cleave if enough left. Neither of them do anything. No error in my chat log, nor "Not enough rage" message. -- space saver for other functions function MyRage() return UnitMana("player") end function ww() if not OnCooldown("Whirlwind") and MyRage()>25 then cast("Whirlwind") else cast("Cleave") end function warshout() if not buffed("Battle Shout") and MyRage()>10 then cast("Battle Shout") else cast("Demoralizing Shout") end The macro I'm using to call them is "/script ww()" or "/script warshout()" Title: Re: SuperMacro and LUA functions - warrior Post by: Pucchini on December 08, 2017, 12:08:33 pm Hi,
first things first:
Regarding your functions, please have a look at the Vanilla API (http://vanilla-wow.wikia.com/wiki/World_of_Warcraft_API). cast("Whirlwind") is no valid statement, you have to use CastSpellByName (http://vanilla-wow.wikia.com/wiki/API_CastSpellByName)("Whirlwind") OnCooldown("Whirlwind") is no valid statement either, see GetSpellCooldown(spellID, bookType) (http://vanilla-wow.wikia.com/wiki/API_GetSpellCooldown) Problem with this API call is the spellID which is the index of a specific spell in your character specific spellbook. Here's a function that will tell you what index you need to use: Quote -- arg: -- spellName - case sensitive spellname, e.g. "Kick" -- rank - numeric rank value you want to look for -- return: index function findSpellIndex(spellName, rank) i, s, S = 1, "spell", GetSpellName; f=spellName n, r=S(i,"spell") findSpell_spells = { } -- find all the spells and save them in a table repeat if strfind(n,f)~=nil then local spell = { } spell["index"] = i spell["name"] = n spell["rank"] = r tinsert(findSpell_spells, spell) end i=i+1; n, r = S(i,"spell") until n==nil -- if rank is not supplied, find max rank if rank == nil then rank = 0 for _, spell in ipairs(findSpell_spells) do local _, _, currentRank = strfind(spell["rank"], "(%d+)") local currentRank = tonumber(currentRank) if currentRank > rank then rank = spell["rank"] end end end -- now return the spell with the specified rank for _, spell in ipairs(findSpell_spells) do if spell["rank"] == rank then return spell["index"] end end end Quote -- space saver for other functions function MyRage() return UnitMana("player") end Quote function ww() if GetSpellCooldown(findSpellIndex("Whirlwind") , "spell") > 0 and MyRage()>25 then CastSpellByName("Whirlwind") else CastSpellByName("Cleave") end -- this was missing end Finding a player's buffs is pretty ugly in 1.12.1 because UnitBuff(unit, index, filter) (http://vanilla-wow.wikia.com/wiki/API_UnitBuff) doesn't return the exact buff name but the buff's icon :x Quote function battleshoutBuffed() local battleShoutBuffName = "Interface\\Icons\\Ability_Warrior_BattleShout" for i=1, 32 do local name = UnitBuff("player", i) Debug_Message(battleShoutBuffName) Debug_Message(name) if name == battleShoutBuffName then return true end end return false end Quote function warshout() if not battleshoutBuffed() and MyRage()>10 then CastSpellByName("Battle Shout") else CastSpellByName("Demoralizing Shout") end -- this was missing end Title: Re: SuperMacro and LUA functions - warrior Post by: Supp0se77 on December 08, 2017, 05:29:03 pm Much thanks for Link and the insight.
|