Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local title = select(2, GetAddOnInfo((...)));
- local active, lasthp, guid = true, 1, nil;
- local backdrop = {
- -- path to the background texture
- bgFile = "Interface\DialogFrame\UI-DialogBox-Background",
- -- path to the border texture
- edgeFile = "Interface\DialogFrame\UI-DialogBox-Border",
- -- true to repeat the background texture to fill the frame, false to scale it
- tile = true,
- -- size (width or height) of the square repeating background tiles (in pixels)
- tileSize = 32,
- -- thickness of edge segments and square size of edge corners (in pixels)
- edgeSize = 32,
- -- distance from the edges of the frame to those of the background texture (in pixels)
- insets = {
- left = 11,
- right = 12,
- top = 12,
- bottom = 11,
- },
- };
- -- Localization
- local enabled, options, editBoxDescription;
- if (GetLocale()=="deDE") then
- enabled = {[true] = "aktiviert", [false] = "deaktiviert",
- ["alreadyActive"] = "ist bereits aktiviert", ["alreadyDeactive"] = "ist bereits deaktiviert"};
- options = {["enable"] = "Aktiviert das Abspielen der Sounds", ["disable"] = "Deaktiviert das Abspielen der Sounds",
- ["toggle"] = "Öffnet das Fenster für die Platzierung der eigenen Musik"};
- editBoxDescription = {["executeTime"] = "spielt, wenn Target unter 20%", ["unitDied"] = "spielt, wenn Target stirbt",
- ["playerDied"] = "spielt, wenn man selbst stirbt", ["havePost"] = "spielt, wenn man Post erhält"};
- else
- enabled = {[true] = "enabled", [false] = "disabled",
- ["alreadyActive"] = "it's already activated", ["alreadyDeactive"] = "it's already deactivated"}; -- Default
- options = {["enable"] = "activate the playing of sounds", ["disable"] = "deactivate the playing of sounds",
- ["toggle"] = "Open the window to place your own music in it"};
- editBoxDescription = {["executeTime"] = "plays, if target below 20%", ["unitDied"] = "plays, if target die",
- ["playerDied"] = "plays, if yourself die", ["havePost"] = "plays, if you get mail"};
- end
- ExecuteSoundTable = {
- ["playerDied"] = "laugh",
- ["unitDied"] = "fatality",
- ["executeTime"] = "finish him",
- ["havePost"] = "hallo post",
- }
- local ExecuteSoundsFrame = CreateFrame("Frame", "ExecuteSoundsFrame", UIParent, "BasicFrameTemplate");
- local ExecuteSoundsRegion = ExecuteSoundsFrame:CreateTitleRegion();
- local ExecuteSoundsFontString = ExecuteSoundsFrame:CreateFontString("ExecutesoundsFontString", "OVERLAY", "GameFontNormal");
- local ExecuteSoundsFontString1 = ExecuteSoundsFrame:CreateFontString("ExecutesoundsFontString1", "OVERLAY", "GameFontNormal");
- local ExecuteSoundsFontString2 = ExecuteSoundsFrame:CreateFontString("ExecutesoundsFontString2", "OVERLAY", "GameFontNormal");
- local ExecuteSoundsFontString3 = ExecuteSoundsFrame:CreateFontString("ExecutesoundsFontString3", "OVERLAY", "GameFontNormal");
- local ExecuteSoundsFontString4 = ExecuteSoundsFrame:CreateFontString("ExecutesoundsFontString4", "OVERLAY", "GameFontNormal");
- local ExecuteSoundsEditBox1 = CreateFrame("EditBox", "ExecuteSoundsEditBox1", nil, "InputBoxTemplate");
- local ExecuteSoundsEditBox2 = CreateFrame("EditBox", "ExecuteSoundsEditBox2", nil, "InputBoxTemplate");
- local ExecuteSoundsEditBox3 = CreateFrame("EditBox", "ExecuteSoundsEditBox3", nil, "InputBoxTemplate");
- local ExecuteSoundsEditBox4 = CreateFrame("EditBox", "ExecuteSoundsEditBox4", nil, "InputBoxTemplate");
- ExecuteSoundsFrame:RegisterEvent("ADDON_LOADED");
- ExecuteSoundsFrame:RegisterEvent("PLAYER_TARGET_CHANGED");
- ExecuteSoundsFrame:RegisterEvent("UNIT_HEALTH");
- ExecuteSoundsFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
- ExecuteSoundsFrame:RegisterEvent("PLAYER_DEAD");
- ExecuteSoundsFrame:RegisterEvent("UPDATE_PENDING_MAIL");
- ExecuteSoundsFrame:SetScript("OnEvent", function(self, event, ...)
- if (not active) then return; end
- if (event == "ADDON_LOADED") then
- tinsert(UISpecialFrames, self:GetName());
- if (... == "ExecuteSounds") then
- end
- elseif (event == "PLAYER_TARGET_CHANGED") then
- -- Reset when changing targets
- lasthp = 1;
- if (UnitIsEnemy("target", "player")) then
- guid = UnitGUID("target");
- end
- if (UnitIsEnemy("target", "player")) then
- guid = UnitGUID("target");
- end
- elseif (event == "UNIT_HEALTH" and UnitIsUnit(..., "target")) then
- if UnitCanAttack("player", "target") then
- -- Need to make sure this runs only once when entering the low HP range
- local pcnt = UnitHealth("target")/UnitHealthMax("target");
- if pcnt < 0.2 and lasthp > 0.2 then
- PlaySoundFile("Interface\\AddOns\\ExecuteSounds\\sounds\\"..ExecuteSoundTable["executeTime"]..".mp3");
- end
- lasthp = pcnt;
- end
- elseif (event == "PLAYER_DEAD") then
- PlaySoundFile("Interface\\AddOns\\ExecuteSounds\\sounds\\"..ExecuteSoundTable["playerDied"]..".mp3");
- elseif (event == "COMBAT_LOG_EVENT_UNFILTERED") then
- local _, subevent,_,_,_,_,_, destguid = ...;
- if (subevent == "UNIT_DIED" and destguid == guid) then
- PlaySoundFile("Interface\\AddOns\\ExecuteSounds\\sounds\\"..ExecuteSoundTable["unitDied"]..".mp3");
- end
- elseif (event == "UPDATE_PENDING_MAIL" and HasNewMail() ~= nil) then
- PlaySoundFile("Interface\\AddOns\\ExecuteSounds\\sounds\\"..ExecuteSoundTable["havePost"]..".mp3");
- end
- end);
- ExecuteSoundsFrame:SetScript("OnLoad", ExecuteSoundsFrame_Hide);
- ExecuteSoundsFrame:SetPoint("CENTER");
- ExecuteSoundsFrame:SetSize(205, 230);
- ExecuteSoundsFrame:SetBackdrop(backdrop);
- ExecuteSoundsFrame:EnableMouse(true);
- ExecuteSoundsRegion:SetPoint("TOP");
- ExecuteSoundsRegion:SetSize(100, 10);
- ExecuteSoundsFontString:SetText("ExecuteSounds");
- ExecuteSoundsFontString:SetPoint("TOP", ExecuteSoundsRegion, nil, 0, -2);
- ExecuteSoundsFontString:SetSize(100, 20);
- ExecuteSoundsEditBox1:SetParent(ExecuteSoundsFrame);
- ExecuteSoundsEditBox1:RegisterEvent("OnEnterPressed");
- ExecuteSoundsEditBox1:SetSize(150, 20);
- ExecuteSoundsEditBox1:SetPoint("TOP", ExecuteSoundsFrame, "TOP", 0, -50);
- ExecuteSoundsEditBox1:SetText(ExecuteSoundTable["executeTime"]);
- ExecuteSoundsEditBox1:SetScript("OnEnterPressed", function(self)
- local file = ExecuteSoundsEditBox1:GetText();
- if (file ~= nil) then
- ExecuteSoundTable["executeTime"] = file;
- ExecuteSoundsEditBox1:ClearFocus();
- return ExecuteSoundsEditBox1:SetText(file);
- end
- end);
- ExecuteSoundsEditBox1:SetAutoFocus(false);
- ExecuteSoundsFontString1:SetText(editBoxDescription["executeTime"]);
- ExecuteSoundsFontString1:SetPoint("TOP", ExecuteSoundsEditBox1, "TOP", 0, 20);
- ExecuteSoundsFontString1:SetSize(165, 20);
- ExecuteSoundsEditBox2:SetParent(ExecuteSoundsFrame);
- ExecuteSoundsEditBox2:RegisterEvent("OnEnterPressed");
- ExecuteSoundsEditBox2:SetSize(150, 20);
- ExecuteSoundsEditBox2:SetPoint("CENTER", ExecuteSoundsFrame, "CENTER", 0, 10);
- ExecuteSoundsEditBox2:SetText(ExecuteSoundTable["unitDied"]);
- ExecuteSoundsEditBox2:SetScript("OnEnterPressed", function(self)
- local file = ExecuteSoundsEditBox2:GetText();
- if (file ~= nil) then
- ExecuteSoundTable["unitDied"] = file;
- ExecuteSoundsEditBox2:ClearFocus();
- return ExecuteSoundsEditBox2:SetText(file);
- end
- end);
- ExecuteSoundsEditBox2:SetAutoFocus(false);
- ExecuteSoundsFontString2:SetText(editBoxDescription["unitDied"]);
- ExecuteSoundsFontString2:SetPoint("TOP", ExecuteSoundsEditBox2, "TOP", 0, 20);
- ExecuteSoundsFontString2:SetSize(150, 20);
- ExecuteSoundsEditBox3:SetParent(ExecuteSoundsFrame);
- ExecuteSoundsEditBox3:RegisterEvent("OnEnterPressed");
- ExecuteSoundsEditBox3:SetSize(150, 20);
- ExecuteSoundsEditBox3:SetPoint("CENTER", ExecuteSoundsFrame, "CENTER", 0, -35);
- ExecuteSoundsEditBox3:SetText(ExecuteSoundTable["playerDied"]);
- ExecuteSoundsEditBox3:SetScript("OnEnterPressed", function(self)
- local file = ExecuteSoundsEditBox3:GetText();
- if (file ~= nil) then
- ExecuteSoundTable["playerDied"] = file;
- ExecuteSoundsEditBox3:ClearFocus();
- return ExecuteSoundsEditBox3:SetText(file);
- end
- end);
- ExecuteSoundsEditBox3:SetAutoFocus(false);
- ExecuteSoundsFontString3:SetText(editBoxDescription["playerDied"]);
- ExecuteSoundsFontString3:SetPoint("TOP", ExecuteSoundsEditBox3, "TOP", 0, 20);
- ExecuteSoundsFontString3:SetSize(150, 20);
- ExecuteSoundsEditBox4:SetParent(ExecuteSoundsFrame);
- ExecuteSoundsEditBox4:RegisterEvent("OnEnterPressed");
- ExecuteSoundsEditBox4:SetSize(150, 20);
- ExecuteSoundsEditBox4:SetPoint("BOTTOM", ExecuteSoundsFrame, "BOTTOM", 0, 20);
- ExecuteSoundsEditBox4:SetText(ExecuteSoundTable["havePost"]);
- ExecuteSoundsEditBox4:SetScript("OnEnterPressed", function(self)
- local file = ExecuteSoundsEditBox4:GetText();
- if (file ~= nil) then
- ExecuteSoundTable["havePost"] = file;
- ExecuteSoundsEditBox4:ClearFocus();
- return ExecuteSoundsEditBox4:SetText(file);
- end
- end);
- ExecuteSoundsEditBox4:SetAutoFocus(false);
- ExecuteSoundsFontString4:SetText(editBoxDescription["havePost"]);
- ExecuteSoundsFontString4:SetPoint("TOP", ExecuteSoundsEditBox4, "TOP", 0, 20);
- ExecuteSoundsFontString4:SetSize(150, 20);
- SlashCmdList["EXECUTESOUNDS"] = function(cmd, editbox)
- cmd = string.lower(cmd);
- local command, rest = cmd:match("^(%S*)%s*(.-)$");
- if (command == "enable") then
- if (active) then
- print(title, enabled["alreadyActive"]);
- else
- active = true;
- print(title, enabled[active]);
- end
- elseif (command == "disable") then
- if (not active) then
- print(title, enabled["alreadyDeactive"]);
- else
- active = false;
- print(title, enabled[active]);
- end
- elseif (command == "toggle") then
- ExecuteSoundsFrame_Show();
- else
- print(title..": ", "ENABLE", options["enable"]);
- print(title..": ", "DISABLE", options["disable"]);
- print(title..": ", "TOGGLE", options["toggle"]);
- end
- end
- SLASH_EXECUTESOUNDS1 = "/executesounds";
- SLASH_EXECUTESOUNDS2 = "/exesounds";
- SLASH_EXECUTESOUNDS3 = "/es";
- ExecuteSoundsFrame_Show = function()
- ExecuteSoundsFrame:Show();
- end
- ExecuteSoundsFrame_Hide = function()
- ExecuteSoundsFrame:Hide();
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement