View Single Post
07-19-14, 03:05 AM   #8
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Morpheus first go to your interface settings under help/other and enable "show lua errors".
Second hit /reload.

Once you fixed all the tiny Lua errors that are left you will sit at

NoTroll.lua
Lua Code:
  1. local ADDON, engine = ...
  2.  
  3. --NoTroll = engine
  4.  
  5. local db = {
  6.     [2825]   = true, -- Bloodlust
  7.     [32182]  = true, -- Heroism
  8.     [80353]  = true, -- Time Warp
  9.     [13159]  = true, -- Aspect of Fail
  10.     [41450]  = true, -- Blessing of Piss me off
  11.     [73325]  = true, -- Leap of Fail
  12.     [34477]  = true, -- MD
  13.     [20736]  = true, -- Distracting Shot
  14.     [62124]  = true, -- Reckoning * paladin
  15.     [56222]  = true, -- Dark Command
  16.     [49576]  = true, -- Death Grip
  17.     [2649]   = true, -- Generic hunter growl
  18.     [39270]  = true, -- main target growl
  19.     [103128] = true, -- suffering
  20. }
  21.  
  22. local f = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer)
  23.  
  24. -- Main addon logic
  25.  
  26. f:RegisterEvent("PLAYER_LOGIN")
  27. f:SetScript("OnEvent", function(self, event)
  28.     NoTrollDB = NoTrollDB or db
  29.     db = NoTrollDB
  30.     self:UnregisterEvent("PLAYER_LOGIN")
  31.  
  32.     self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  33.     self:SetScript("OnEvent", function(self, event, unit, spellName, _, _, spellID)
  34.         if db[spellID] then
  35.             local name = GetUnitName(unit, false) -- Use true to show the realm name
  36.             print("|cffffff9a[NoTroll]|r", name, "used", spellName)
  37.         end
  38.     end)
  39. end)
  40.  
  41. -- Options panel
  42.  
  43. f:Hide()
  44. f:SetScript("OnShow", function(self)
  45.     local title = self:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
  46.     title:SetPoint("TOPLEFT", 16, -16)
  47.     title:SetText(self.name)
  48.  
  49.     local notes = self:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
  50.     notes:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
  51.     notes:SetPoint("RIGHT", -32, 0)
  52.     notes:SetHeight(32)
  53.     notes:SetJustifyH("LEFT")
  54.     notes:SetJustifyV("TOP")
  55.     notes:SetText(GetAddOnMetadata(ADDON, "Notes"))
  56.  
  57.     local spellNameToID, sortedSpells = {}, {}
  58.     for id in pairs(db) do
  59.         local name = GetSpellInfo(id)
  60.         if name then
  61.             spellNameToID[name] = id
  62.             tinsert(sortedSpells, name)
  63.         end
  64.     end
  65.     sort(sortedSpells)
  66.    
  67.     local boxes = {}
  68.     local breakpoint = 1 + floor(#sortedSpells / 2)
  69.     local function ClickBox(self)
  70.         local checked = not not self:GetChecked()
  71.         PlaySound(checked and "igMainMenuOptionCheckBoxOn" or "igMainmenuOptionCheckBoxOff")
  72.         db[self.id] = checked
  73.     end
  74.  
  75.     for i = 1, #sortedSpells do
  76.         local spell = sortedSpells[i]
  77.        
  78.         local box = CreateFrame("CheckButton", "$parentCheckbox"..i, self, "InterfaceOptionsCheckButtonTemplate")
  79.         box:SetScript("OnClick", ClickBox)
  80.         box.Text:SetText(spell)
  81.         box:SetHitRectInsets(0, -1 * max(box.Text:GetStringWidth(), 100), 0, 0) -- Make whole label clickable instead only the first 100px
  82.         box.id = spellNameToID[spell]
  83.        
  84.         if i == 1 then
  85.             box:SetPoint("TOPLEFT", notes, "BOTTOMLEFT", 0, -16)
  86.         elseif i == breakpoint then
  87.             box:SetPoint("TOPLEFT", notes, "BOTTOM", 0, -16)
  88.         else
  89.             box:SetPoint("TOPLEFT", boxes[i - 1], "BOTTOMLEFT", 0, -8)
  90.         end
  91.        
  92.         boxes[i] = box
  93.     end
  94.    
  95.     function self:refresh()
  96.         for i = 1, #boxes do
  97.             local box = boxes[i]
  98.             box:SetChecked(db[box.id])
  99.         end
  100.     end
  101.    
  102.     self:SetScript("OnShow", nil)
  103.     self:refresh()
  104. end)
  105.  
  106. -- Register the options panel:
  107.  
  108. f.name = GetAddOnMetadata(ADDON, "Title")
  109. InterfaceOptions_AddCategory(f)
  110.  
  111. -- Create a slash command to open the options panel:
  112.  
  113. _G["SLASH_"..ADDON.."1"] = "/notroll"
  114. SlashCmdList[ADDON] = function()
  115.     InterfaceOptionsFrame_OpenToCategory(f)
  116.     InterfaceOptionsFrame_OpenToCategory(f)
  117.     -- It's called twice on purpose, to work around the long-standing
  118.     -- Blizzard bug that opens the options window to the wrong panel
  119.     -- under certain conditions.
  120. end

NoTroll.toc
Code:
## Interface: 50400
## Author: Phanx
## Title: NoTroll
## Notes: I no has do dat!
## SavedVariables: NoTrollDB 

NoTroll.lua
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 07-19-14 at 03:35 AM.
  Reply With Quote