August 03, 2021, 08:33:09 am
Welcome, Guest. Please login or register.
148779 Posts in 18102 Topics- by 34170 Members - Latest Member: anthonymitchell
Pages: [1]
  Print  
Author Topic: SuperMacro and LUA functions - warrior  (Read 7619 times)
Newbie
*
Posts: 2
View Profile Email
« 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()"
Logged
Full Member
***
Posts: 341
View Profile
« Reply #1 on: December 08, 2017, 12:08:33 pm »

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:

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) 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
« Last Edit: December 08, 2017, 12:58:14 pm by Pucchini » Logged

https://i.imgur.com/0k94nIv.jpg
^Hi Chess, legit THC earned with the EPGP loot distribution system. Not by half-assed DKP with lootcounciled KT loot ;-)

Rogue CL of <Chaos>
chaosvg.shivtr.com
Newbie
*
Posts: 2
View Profile Email
« Reply #2 on: December 08, 2017, 05:29:03 pm »

Much thanks for Link and the insight.
Logged
Pages: [1]
  Print  
 
Jump to: