|
10-30-16, 12:55 PM | #1 |
auto SetLootMethod
i'm trying make a addon for my guild because they almost always forget to change loot method in raid.
Code:
local frame = CreateFrame("Frame") frame:RegisterEvent("GROUP_ROSTER_UPDATE") local function eventHandler(self, event, ...) if IsInRaid() and UnitInRaid("player") and UnitIsGroupLeader("player") then if event == "GROUP_ROSTER_UPDATE" then if InGuildParty() then SetLootMethod("master", UnitName("player")) print("master") else SetLootMethod("freeforall") print("free") end end end end frame:SetScript("OnEvent", eventHandler) i think something wrong in code but dont know how to fix it, wrong event? which should i use? |
|
10-30-16, 01:05 PM | #2 |
You need to check for GetLootMethod before SetLootMethod.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. |
|
10-30-16, 08:48 PM | #3 |
thanks, it works now:
Code:
local frame = CreateFrame("Frame") frame:RegisterEvent("PARTY_LOOT_METHOD_CHANGED") local function eventHandler(self, event, ...) local method, _, _ = GetLootMethod() if event == "PARTY_LOOT_METHOD_CHANGED" then if method ~= master or freeforall then if IsInRaid() and UnitInRaid("player") and UnitIsGroupLeader("player") then if InGuildParty() then SetLootMethod("master", UnitName("player")) else SetLootMethod("freeforall") end end end end end frame:SetScript("OnEvent", eventHandler) i have no idea to do that. maybe slash command to enable/disable is better way? |
|
10-31-16, 04:03 AM | #4 |
You can check for normal vs instance (premade) group by passing a specifier to IsInRaid:
http://wow.gamepedia.com/API_IsInRaid However, your code will currently not work, for several reasons. Most importantly: Code:
if method ~= master or freeforall then Code:
if method ~= "master" or method ~= "freeforall" then Apart from that, some other issues / suggestions / hints:
Here's an updated version: Code:
local player = UnitName("player") local frame = CreateFrame("Frame") frame:RegisterEvent("GROUP_ROSTER_UPDATED") frame:SetScript("OnEvent", function() if IsInRaid(LE_INSTANCE_TYPE_HOME) and UnitIsGroupLeader("player") then local wanted = InGuildParty() and "master" or "freeforall" if GetLootMethod() ~= wanted then SetLootMethod(wanted, player) end end end)
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
11-01-16, 05:13 AM | #5 | ||
for my bad lua knowledge i usually forget correct logic lol so that code magically worked as a wrong way.....
Indentation was lost when i copy to thread (i delete some note when copy it). what thay need -- sloved: 1.auto select master loot in guild team. 2.auto select freeforall if not in a guild team. they are release now. ------ what thay need -- now doing: 3.need keep personal loot when sometimes make a premade group, so need a function to disable it. >do not auto select, creat a frame show option just like "wanna change loot method? [presonal] [master] [freeforall]" when leader make a group or get into a instance. >a slash cmd to enable/disable addon. form this, in fact i think they just need a Popup frame to "remind them change loot method if need". so i try another thing: make a frame to remind ppl when they get into raid. is this way correct? Code:
local f = CreateFrame("Frame") f:SetPoint("CENTER", UIParent, "CENTER", 0, 120) f:SetSize(150, 70) f:Hide() f.Text = f:CreateFontString(nil, "OVERLAY") f.Text:SetFont(STANDARD_TEXT_FONT, 16, OUTLINE) f.Text:SetPoint("CENTER", f) f:RegisterEvent("ZONE_CHANGED_NEW_AREA") f:RegisterEvent("PLAYER_ENTERING_WORLD") f:SetScript("OnEvent", function() if IsInRaid() and UnitIsGroupLeader("player") then f:Show() f.Text:SetText("check loot method!") else f:Hide() end end) f:SetScript("OnMouseUp", function() f:Hide() end) Last edited by EKE : 11-01-16 at 05:57 AM. |
|||
11-02-16, 12:30 AM | #6 |
That will work... but it will only trigger when you either (a) move from one zone map to another or (b) enter or leave an instance. To make it trigger only when you change from "leader of a raid" to "not leader of a raid" you'd need to (a) listen for a different event and (b) keep track of which state you were in (to avoid triggering it repeatedly if the state wasn't changing). Example:
Code:
f:RegisterEvent("GROUP_ROSTER_UPDATE") local isLeader = false f:SetScript("OnEvent", function() local isLeaderNow = IsInRaid() and UnitIsGroupLeader("player") if IsLeaderNow == isLeader then return end isLeader = isLeaderNow if isLeaderNow then f:Show() f.Text:SetText("check loot method!") else f:Hide() end end) ✦ When you create a frame that's visible on screen, it must be parented to the UIParent, or to something else whose parentage traces back to the UIParent. Otherwise, it will (a) not be hidden with Alt-Z and (b) won't respect the user's UI scale setting. Code:
local f = CreateFrame("Frame", nil, UIParent) ✦ If you want to be able to click on the frame, you need to turn on mouse interactivity: Code:
f:EnableMouse(true) Code:
f:SetWidth(f.Text:GetStringWidth()) f:SetHeight(f.Text:GetStringHeight()) Code:
f:Show() C_Timer.After(10, function() f:Hide() end) Code:
local f = CreateFrame("Frame", "LeaderLootReminder", UIParent) f:SetToplevel(true) f:EnableKeyboard(true) f:EnableMouse(true) f:SetFrameStrata("DIALOG") f:Hide() f:SetSize(320, 72) f:SetBackdrop({ bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]], tile = "true", insets = { left="11", right="12", top="12", bottom="11" }, tileSize = 32, edgeSize = 32 }) f.text = f:CreateFontString("$parentText", "ARTWORK", "GameFontHighlight") f.text:SetWidth(290) f.text:SetPoint("TOP", 0, -16) f.text:SetText("You are now a raid leader!\nPick your loot method:") f.close = CreateFrame("Button", "$parentCloseButton", f, "UIPanelCloseButton") f.close:SetPoint("TOPRIGHT", -3, -3) local function Button_OnClick(self) local me = UnitName("player") SetLootMethod(self.lootType, me) end f.button1 = CreateFrame("Button", "$parentButton1", f, "StaticPopupButtonTemplate") f.button1:SetPoint("BOTTOMRIGHT", f, "BOTTOM", -72, 16) f.button1:SetText("Group Loot") f.button1.lootType = "group" f.button2 = CreateFrame("Button", "$parentButton2", f, "StaticPopupButtonTemplate") f.button2:SetPoint("LEFT", f.button1, "RIGHT", 13, 0) -- (source) f.button2:SetText("Free For All") f.button2.lootType = "freeforall" f.button3 = CreateFrame("Button", "$parentButton3", f, "StaticPopupButtonTemplate") f.button3:SetPoint("LEFT", f.button2, "RIGHT", 13, 0) f.button3:SetText("Master Looter") f.button3.lootType = "master" f:SetScript("OnEscapePressed", function(self) self:Hide() end) function f:SetAnchor(self) for i = 1, STATICPOPUP_NUMDIALOGS do local popup = _G["StaticPopup"..i] if popup:IsShown() then return self:SetPoint("TOP", popup, "BOTTOM") end end self:SetPoint("TOP", UIParent, 0, -135) end f:SetScript("OnShow", f.SetAnchor) hooksecurefunc("StaticPopup_Show", f.SetAnchor) -- Handle events here
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. Last edited by Phanx : 11-02-16 at 12:41 AM. |
|
11-06-16, 11:05 PM | #7 |
WoWInterface » Developer Discussions » Lua/XML Help » auto SetLootMethod |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Hybrid Mode |
Switch to Threaded Mode |
|
|