Sorry.This code gives the the error which follows.
Code:
-- Disable the addon if the player is not a hunter:
if select(2, UnitClass("player")) ~= "HUNTER" then
return DisableAddOn("EZTrap")
end
------------------------------------------------------------------------
-- Create the base frame:
local EZTrap = CreateFrame("Frame", "EZTrap", UIParent)
EZTrap:SetPoint("CENTER", -1, -144)
EZTrap:SetSize(110, 110)
-- Make it draggable:
EZTrap:EnableMouse(true)
EZTrap:SetMovable(true)
EZTrap:RegisterForDrag("RightButton")
EZTrap:SetScript("OnDragStart", EZTrap.StartMoving)
EZTrap:SetScript("OnDragStop", EZTrap.StopMovingOrSizing)
EZTrap:SetScript("OnHide", EZTrap.StopMovingOrSizing)
-- Add the background:
EZTrap:SetBackdrop({
bgFile = [[Interface\FrameGeneral\UI-Background-Rock]], tile = true, tileSize = 32,
edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]], edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 }
})
------------------------------------------------------------------------
-- Set up a button factory:
local CreateTrapButton
do
-- Share the same event handler function between buttons
-- instead of creating duplicate functions:
local function TrapButton_OnEvent(self, event, ...)
local start, duration = GetSpellCooldown(self.spellID)
if duration > 0 then
self.cooldown:Show()
self.cooldown:SetCooldown(start, duration)
else
self.cooldown:Hide()
end
end
function CreateTrapButton(spellID)
-- Get the name and icon for the specificed spell:
local spellName, _, spellIcon = GetSpellInfo(spellID)
if not spellName then
-- That's not a valid spell ID!
return
end
-- Create the button:
local button = CreateFrame("Button", "$parent"..gsub(spellName, "[^%a]", ""), EZTrap, "SecureActionButtonTemplate")
button:SetSize(30, 30)
-- Set the correct trap spell properties:
button:SetAttribute("type", "spell")
button:SetAttribute("spell", spellName)
button:SetNormalTexture(spellIcon)
button.spellID = spellID
-- Add a cooldown to the button:
local cd = CreateFrame("Cooldown", "$parentCooldown", button, "CooldownFrameTemplate")
cd:SetAllPoints(true)
cd:Hide()
-- Update the cooldown when needed:
button:RegisterEvent("SPELL_UPDATE_COOLDOWN")
button:SetScript("OnEvent", TrapButton_OnEvent)
-- Hand the button back to the calling code:
return button
end
end
------------------------------------------------------------------------
-- Add a button for Freezing Trap:
local Freezing = CreateTrapButton(1499)
Freezing:SetPoint("TOPLEFT")
------------------------------------------------------------------------
-- Add a button for Explosive Trap:
local Freezing = CreateTrapButton(13813)
Freezing:SetPoint("BOTTOMLEFT")
------------------------------------------------------------------------
-- Add buttons for other traps (or even other spells) as desired.
Error for the code directly above: 320x EZTrap\EZTrap-5.2-lua:39: attempt to index field "cooldown" (a nil value)
EZTrap\EZTrap-5.2.lua:39: in function <EZTrap\EZTrap.lua33
The following code generates the error which follows it:
Code:
-- Disable the addon if the player is not a hunter:
if select(2, UnitClass("player")) ~= "HUNTER" then
return DisableAddOn("EZTrap")
end
------------------------------------------------------------------------
-- Create the base frame:
local EZTrap = CreateFrame("Frame", "EZTrap", UIParent)
EZTrap:SetPoint("CENTER", -1, -144)
EZTrap:SetSize(85, 85)
-- Make it draggable:
EZTrap:EnableMouse(true)
EZTrap:SetMovable(true)
EZTrap:RegisterForDrag("RightButton")
EZTrap:SetScript("OnDragStart", EZTrap.StartMoving)
EZTrap:SetScript("OnDragStop", EZTrap.StopMovingOrSizing)
EZTrap:SetScript("OnHide", EZTrap.StopMovingOrSizing)
-- Add the background:
EZTrap:SetBackdrop({
bgFile = [[Interface\Icons\ability_ensnare]], tile = false, tileSize = 0,
edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]], edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 }
})
------------------------------------------------------------------------
-- Set up a button factory:
local CreateTrapButton
do
-- Share the same event handler function between buttons
-- instead of creating duplicate functions:
local function TrapButton_OnEvent(self, event, ...)
local start, duration = GetSpellCooldown(self.spellID)
if duration > 0 then
print(self:GetAttribute("spell"), "is on cooldown for", duration, "seconds.")
self.cooldown:Show()
self.cooldown:SetCooldown(start, duration)
else
print(self:GetAttribute("spell"), "is not on cooldown.")
self.cooldown:Hide()
end
end
function CreateTrapButton(spellID)
-- Get the name and icon for the specificed spell:
local spellName, _, spellIcon = GetSpellInfo(spellID)
if not spellName then
-- That's not a valid spell ID!
return
end
-- Create the button:
local button = CreateFrame("Button", "$parent"..gsub(spellName, "[^%a]", ""), EZTrap, "SecureActionButtonTemplate")
button:SetSize(30, 30)
-- Set the correct trap spell properties:
button:SetAttribute("type", "spell")
button:SetAttribute("spell", spellName)
button:SetNormalTexture(spellIcon)
button.spellID = spellID
-- Add a cooldown to the button:
local cd = CreateFrame("Cooldown", "$parentCooldown", button, "CooldownFrameTemplate")
cd:SetAllPoints(true)
cd:Hide()
-- Update the cooldown when needed:
button:RegisterEvent("SPELL_UPDATE_COOLDOWN")
button:SetScript("OnEvent", TrapButton_OnEvent)
-- Hand the button back to the calling code:
return button
end
end
------------------------------------------------------------------------
-- Add a button for Freezing Trap:
local Freezing = CreateTrapButton(1499)
Freezing:SetPoint("BOTTOMLEFT")
------------------------------------------------------------------------
-- Add a button for Explosive Trap:
local Freezing = CreateTrapButton(13813)
Freezing:SetPoint("TOPLEFT")
------------------------------------------------------------------------
-- Add a button for Ice Trap:
local Freezing = CreateTrapButton(13809)
Freezing:SetPoint("BOTTOMRIGHT")
------------------------------------------------------------------------
-- Add a button for Trap Launcher:
local Freezing = CreateTrapButton(77769)
Freezing:SetPoint("CENTER")
------------------------------------------------------------------------
-- Add a button for Snake Trap:
local Freezing = CreateTrapButton(34600)
Freezing:SetPoint("TOPRIGHT")
-- Add buttons for other traps (or even other spells) as desired.
Error generated for the code direcly above :
32x EZTrap\EZTrap-5.2-lua:41: attempt to index field "cooldown" (a nil value)
<in C code>
<string>: "CAMERORSELECTORMOVE":4 in function
<string>: "CAMERORSELECTORMOVE":1
Locals
("temporary")=nil
("temporary")="SPELL_UPDATE_COOLDOWN"
("temporary")="SPELL_UPDATE_COOLDOWN"
("temporary")= <func>= |c|: -1
-Chat messages correctly indicate when traps are on and off 30 sec cooldown as well as GCD.