View Single Post
05-16-10, 02:33 AM   #196
upyursh
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 32
Druid Mana Notice Block

Just wrote this up on my blog but thought I'd shared here.



Basically the block will put a message and play a sound (when not on CD) and do apply the following logic;
  • Are we Dead? If Yes Stop, If No Continue
  • Is Smartervate Loaded? If Yes Threshold set to addons, if No use 50%
  • Are we a Druid? If No Stop, If Yes Continue
  • Is Mana less than Threshold? If No Stop, If Yes Play Sound (has internal cooldown) & Continue
  • Are we in Combat? If No Message to Drink, If Yes Continue
  • Is Innervate Available? If Yes Message to Use, If No Continue
  • Is Pot Available? If Yes Message to Use, If No Message to use Smartervate

Code:
    
   -- mana management
    {
        name = "manamgnt", parent = "BoxL",
        anchor_to="TOP", anchor_from="RIGHT",
        y_off = 200,
    
        text={
          string=function()
          
          -- If toon is dead return nil
          if(UnitIsDeadOrGhost("player") == 1) then return nil end

          -- If Smartervate is being used
          if(IsAddOnLoaded("Smartervate")) then
            -- Get Mana Threshold from there
            threshold = Smartervate:GetManaThreshold()
          else
            -- If not 50%
            threshold = 0.5
          end

          -- Options
          gcd = 1.109 -- this may need to be decreased based on GCD changes
          pot = "Crazy Alchemist's Potion"
          sounddelay = 15

          ourUnitClass,  ourUnitEngClass = UnitClass("player");
          if (ourUnitEngClass == 'DRUID') then
          
            current_time = time{year=date("%Y"), month=date("%m"), day=date("%d"), hour=date("%H"), min=date("%M"), sec=date("%S")}
            if(SoundLocked ~= nil and current_time > SoundLocked) then
              SoundLocked = nil
            end
            
            if(SmartervateDelay ~= nil and current_time > SmartervateDelay) then
              SmartervateDelay = nil
            end

            -- Get our Max Mana Pool
            local maxmana = UnitManaMax("player")

            -- Get our current mana
            local currentmana = UnitMana("player")
            
            -- Get our Percentage
            local manaperc = ( currentmana /  maxmana )
            
            -- Get our Mana Threshhold
            local manathreshhold = tonumber(threshold)
            
            if ( manaperc < manathreshhold) then

              if (SoundLocked == nil and UnitAffectingCombat("player") == 1) then
                PlaySound("GAMEHIGHLIGHTFRIENDLYUNIT")
                PlaySoundFile("Sound\\Spells\\PVPFlagTaken.wav")
                SoundLocked = current_time + tonumber(sounddelay) -- only play sound every 20 secs
              end
              
              -- Are we in combat?
              if (UnitAffectingCombat("player") == 1) then
              
                -- Yes! Check Our Innervate
                local start, duration = GetSpellCooldown("Innervate")
                if ( duration <= gcd ) then
                  
                  -- Innervate is available, notice to use it!
                  return "|cffffd700Use Your Innervate|r"
                  
                else
                  
                  -- OMG Innervate is used! Check Our Pot
                  pot_startTime, pot_duration, pot_enable = GetItemCooldown(pot)
                  if ( pot_startTime == 0 and pot_duration == 0 ) then
                  
                    -- Pot is available, Notice to use it!
                    return "|cffffd700Use Your " .. pot .. "|r"
                    
                  else
                  
                    -- No pot either? Notice to trigger Smartervate!
                    return "|cffffd700Use Smartervate!! /smv|r"
                    
                  end
                end
              else
                
                -- Out of combat and below threshhold? have a drink
                return "|cffffd700You're low on mana, have a drinky!|r"
                
              end
  
            else
              return nil
            end
          
          else
            return nil
          end
          
         end, update = 1,
         size=20, shadow=2, font = "Interface\\AddOns\\ArkInventory\\Fonts\\Emblem.ttf",
        }
    }
My full Layout is here;

Code:
lpanels:CreateLayout("UfBar", {
    -- Left mid-section of the box
    {   name = "BoxL",
        anchor_to = "BOTTOM",
        width = 350,        height = 90,
        x_off = -350/2,        y_off = 120,
        gradient = "H",
        bg_color = "CLASS",    gradient_color = "CLASS",
        bg_alpha = 0,        gradient_alpha = 0.2,
    },
    -- Right mid-section
    {   name = "BoxR",
        anchor_to = "BOTTOM",
        width = 350,        height = 90,
        x_off = 350/2,        y_off = 120,
        gradient = "H",
        bg_color = "CLASS",    gradient_color = "CLASS",
        bg_alpha = 0.2,        gradient_alpha = 0.0,
    },
    -- Top Left gradient line
    {   name = "LineTL",
        parent = "BoxL",    anchor_to = "TOP",
        width = "100%",        height = 1,
        gradient = "H",
        bg_color = "CLASS",    gradient_color = "CLASS",
        bg_alpha = 0,        gradient_alpha = 0.8,
    },
    -- Top right line
    {   name = "LineTR",
        parent = "BoxR",    anchor_to = "TOP",
        width = "100%",        height = 1,
        gradient = "H",
        bg_color = "CLASS",    gradient_color = "CLASS",
        bg_alpha = 0.8,        gradient_alpha = 0,
    },
    -- Bottom Left gradient line
    {   name = "LineBL",
        parent = "BoxL",    anchor_to = "BOTTOM",
        width = "100%",        height = 1,
        gradient = "H",
        bg_color = "CLASS",    gradient_color = "CLASS",
        bg_alpha = 0,        gradient_alpha = 0.8,
    },
    -- Bottom right line
    {   name = "LineBR",
        parent = "BoxR",    anchor_to = "BOTTOM",
        width = "100%",        height = 1,
        gradient = "H",
        bg_color = "CLASS",    gradient_color = "CLASS",
        bg_alpha = 0.8,        gradient_alpha = 0,
    },
    
   -- Local Time
    {   name = "LocalTime", parent = "BoxL",
        anchor_to="TOP", anchor_from="RIGHT",
        y_off = -46,
    
        text={
          string=function()
          
          -- clock
          local localtime = format("%.0f",date("%I")) .. "|cffffd700:|r" .. date("%M");
          
          return localtime
         end, update = 1,
         size=22, shadow=2, font = "Interface\\AddOns\\ArkInventory\\Fonts\\Emblem.ttf",
        }
    },

   -- Server Time
    {   name = "ServerTime", parent = "BoxL",
        anchor_to="TOP", anchor_from="RIGHT",
        y_off = -68,
    
        text={
          string=function()
          
          -- clock
          local servertime = GameTime_GetTime(false);
          
          return servertime
         end, update = 1,
         size=10, shadow=2, font = "Interface\\AddOns\\ArkInventory\\Fonts\\Emblem.ttf",
        }
    },
    
   -- FPS
    {   name = "FPS", parent = "BoxL",
        anchor_to="TOP", anchor_from="RIGHT",
        y_off = -48, x_off = -60,
    
        text={
          string=function()
          
          -- fps
          local fps = floor(GetFramerate())
          
          return fps.."|cffffd700FPS|r"
         end, update = 1,
         size=10, shadow=2, font = "Interface\\AddOns\\ArkInventory\\Fonts\\Emblem.ttf",
        }
    },
    
   -- Latency
    {   name = "LATENCY", parent = "BoxL",
        anchor_to="TOP", anchor_from="RIGHT",
        y_off = -48, x_off = 60,
    
        text={
          string=function()
          
          -- latency
          local latency = select(3,GetNetStats())
          
          return latency.."|cffffd700MS|r"
         end, update = 1,
         size=10, shadow=2, font = "Interface\\AddOns\\ArkInventory\\Fonts\\Emblem.ttf",
        }
    },
    
   -- Memory
    {   name = "Membory", parent = "BoxL",
        anchor_to="TOP", anchor_from="RIGHT",
        y_off = -48, x_off = -120,
    
        text={
          string=function()
          
          -- memory
          local memory = 0
          UpdateAddOnMemoryUsage()
          for i = 1, GetNumAddOns() do
          if IsAddOnLoaded(i) then
          memory = memory + GetAddOnMemoryUsage(i)
          end
          end
          local memory = format("%.1f", memory/1024)
          
          return memory.."|cffffd700MB|r"
         end, update = 1,
         size=10, shadow=2, font = "Interface\\AddOns\\ArkInventory\\Fonts\\Emblem.ttf",
        }
    },
    
   -- durability
    {   name = "durability", parent = "BoxL",
        anchor_to="TOP", anchor_from="RIGHT",
        y_off = -48, x_off = 120,
    
        text={
          string=function()
          
          -- durability
          local durability = 100
          for i = 1, 11 do
          if GetInventoryItemDurability(i) ~= nil then
          local dur, max = GetInventoryItemDurability(i)
          local perc = dur / max * 100
          if perc < durability then durability = floor(perc) end
          end
          end
          
          return durability.."|cffffd700%|r"
         end, update = 1,
         size=10, shadow=2, font = "Interface\\AddOns\\ArkInventory\\Fonts\\Emblem.ttf",
        }
    },
	
   -- haste
    {   name = "haste", parent = "BoxL",
        anchor_to="TOP", anchor_from="RIGHT",
        y_off = 60, x_off = 80,
    
        text={
          string=function()
          
          -- haste
          local haste = GetCombatRating(20)
          return "|cffffd700"..haste.."|rHST"
		  
         end, update = 1,
         size=10, shadow=2, font = "Interface\\AddOns\\ArkInventory\\Fonts\\Emblem.ttf",
        }
    },
	
   -- mp5
    {   name = "mp5", parent = "BoxL",
        anchor_to="TOP", anchor_from="RIGHT",
        y_off = 60, x_off = -80,
    
        text={
          string=function()
          
          -- mp5
          local  mp5, mp5ic = GetManaRegen()
		  mp5 = string.format("%.0f", mp5*5)
		  mp5ic = string.format("%.0f",mp5ic*5)
		  
		  if ( UnitAffectingCombat("player") == 1) then
        return "|cffffd700"..mp5ic.."|rMP5"
		  else
		    return "|cffffd700"..mp5.."|rMP5"
		  end
		  
         end, update = 1,
         size=10, shadow=2, font = "Interface\\AddOns\\ArkInventory\\Fonts\\Emblem.ttf",
        }
    },
	
   -- spellpower
    {   name = "spellpower", parent = "BoxL",
        anchor_to="TOP", anchor_from="RIGHT",
        y_off = 60,
    
        text={
          string=function()
          
          -- spellpower
          local  spellpower = GetSpellBonusHealing();
          return spellpower.."|cffffd700SP|r"
		  
         end, update = 1,
         size=10, shadow=2, font = "Interface\\AddOns\\ArkInventory\\Fonts\\Emblem.ttf",
        }
    },
    
   -- mana management
    {
        name = "manamgnt", parent = "BoxL",
        anchor_to="TOP", anchor_from="RIGHT",
        y_off = 200,
    
        text={
          string=function()
          
          -- If toon is dead return nil
          if(UnitIsDeadOrGhost("player") == 1) then return nil end

          -- If Smartervate is being used
          if(IsAddOnLoaded("Smartervate")) then
            -- Get Mana Threshold from there
            threshold = Smartervate:GetManaThreshold()
          else
            -- If not 50%
            threshold = 0.5
          end

          -- Options
          gcd = 1.109 -- this may need to be decreased based on GCD changes
          pot = "Crazy Alchemist's Potion"
          sounddelay = 15

          ourUnitClass,  ourUnitEngClass = UnitClass("player");
          if (ourUnitEngClass == 'DRUID') then
          
            current_time = time{year=date("%Y"), month=date("%m"), day=date("%d"), hour=date("%H"), min=date("%M"), sec=date("%S")}
            if(SoundLocked ~= nil and current_time > SoundLocked) then
              SoundLocked = nil
            end
            
            if(SmartervateDelay ~= nil and current_time > SmartervateDelay) then
              SmartervateDelay = nil
            end

            -- Get our Max Mana Pool
            local maxmana = UnitManaMax("player")

            -- Get our current mana
            local currentmana = UnitMana("player")
            
            -- Get our Percentage
            local manaperc = ( currentmana /  maxmana )
            
            -- Get our Mana Threshhold
            local manathreshhold = tonumber(threshold)
            
            if ( manaperc < manathreshhold) then

              if (SoundLocked == nil and UnitAffectingCombat("player") == 1) then
                PlaySound("GAMEHIGHLIGHTFRIENDLYUNIT")
                PlaySoundFile("Sound\\Spells\\PVPFlagTaken.wav")
                SoundLocked = current_time + tonumber(sounddelay) -- only play sound every 20 secs
              end
              
              -- Are we in combat?
              if (UnitAffectingCombat("player") == 1) then
              
                -- Yes! Check Our Innervate
                local start, duration = GetSpellCooldown("Innervate")
                if ( duration <= gcd ) then
                  
                  -- Innervate is available, notice to use it!
                  return "|cffffd700Use Your Innervate|r"
                  
                else
                  
                  -- OMG Innervate is used! Check Our Pot
                  pot_startTime, pot_duration, pot_enable = GetItemCooldown(pot)
                  if ( pot_startTime == 0 and pot_duration == 0 ) then
                  
                    -- Pot is available, Notice to use it!
                    return "|cffffd700Use Your " .. pot .. "|r"
                    
                  else
                  
                    -- No pot either? Notice to trigger Smartervate!
                    return "|cffffd700Use Smartervate!! /smv|r"
                    
                  end
                end
              else
                
                -- Out of combat and below threshhold? have a drink
                return "|cffffd700You're low on mana, have a drinky!|r"
                
              end
  
            else
              return nil
            end
          
          else
            return nil
          end
          
         end, update = 1,
         size=20, shadow=2, font = "Interface\\AddOns\\ArkInventory\\Fonts\\Emblem.ttf",
        }
    }
    
}); lpanels:ApplyLayout(nil, "UfBar")

Last edited by upyursh : 05-16-10 at 02:37 AM.
  Reply With Quote