Hi,
first things first:
- Use quotes to separate code in your thread replies
- Use proper code formatting
- Define functions with very tightly scoped names, e.g. by prefixing them. SuperMacro will insert these functions into the global WoW Interface namespace and you can override stuff easily.
- Same goes for variables! Use as much local variables as possible, otherwise prefix them.
Regarding your functions, please have a look at the
Vanilla API .
cast("Whirlwind") is no valid statement, you have to use
CastSpellByName("Whirlwind")
OnCooldown("Whirlwind") is no valid statement either, see
GetSpellCooldown(spellID, bookType)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:
-- 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
-- space saver for other functions
function MyRage()
return UnitMana("player")
end
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) doesn't return the exact buff name but the buff's icon :x
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
function warshout()
if not battleshoutBuffed() and MyRage()>10 then
CastSpellByName("Battle Shout")
else
CastSpellByName("Demoralizing Shout")
end -- this was missing
end