Download
(26Kb)
Download
Updated: 05-10-23 10:28 PM
Pictures
File Info
Compatibility:
Embers of Neltharion (10.1.0)
Updated:05-10-23 10:28 PM
Created:06-01-15 11:23 AM
Downloads:3,266
Favorites:4
MD5:

gmLoot

Version: 1010-2023051101
by: gmarco, Wexen

gmLoot

A small LDB plugin to change the current loot specifications (AUTOLOOT yes/no) and to autoloot coins and currencies and/or quest items only. It manages also AutoDeposit reags at bank.

It shows in a broker display compatible the actual loot settings.

The original looting idea is from "Semi-Auto Looter" by SmileySL.

Requires a data broker display like chocolate bar, bazooka, ninjapanel, stat block, titan panel, docking station, buttonbin and more.

The scale of tooltip can be changed (and saved) by clicking on databroker display:

Lua Code:
  1. SHIFT+LEFT Click decrease scale till <= 0.8
  2. SHIFT+RIGHT Click increase scale till >= 2.0
  3. SHIFT+MIDDLE Click reset scale to 1

1010-2023051101
- bump toc
- added in .toc the IconTexture key

1000-2022110601
- added X-WoWI-ID and X-Curse-Project-ID keywords to let WowUp manage it
- bump toc

915-2021110401
- Used the latest LibQTip alfa version.
- dump toc

915-2021110301
- Hotfix a libqtip error. (taken from xodiv inputs in curseforge pages).
- dump toc

900-2020111001
- fix the loot coins only

900-2020101801
- update libqtip to the latest 442326b-alpha

900-2020101401
- bump toc
- first fixes to work with 9.0.x
- update libqtip to the latest

830-2020040501
- rewrite using libqtip
- added size control for the tooltip and save as variable:
SHIFT+LEFT Click decrease size till <= 0.8
SHIFT+RIGHT Click increase size till >= 2.0
SHIFT+MIDDLE Click reset size to 1

830-2020031501
- bump toc

820-2019062801
- bump toc

815-2019032601
- changed SetCVar to:
SetCVar( "autoLootDefault", "1")
SetCVar( "autoLootDefault", "0")


810-2018122201
- bump toc

801-2018081101
- bump toc

720-2017032801
- bump toc

v715-2017030501
- Added Autodeposit ON/OFF of reags at the bank

v1.0-2016121601
- changed LDB icons

v1.0-2016102601
- bump toc

v1.0-2016090201
- autoloots now currencies as well with coins

v1.0-2016072301
- bump toc for vers.7

v1.0-2015100301
- tons of best practice code rewriting.
thanks to Phanx, you can check all of them here:
http://www.wowinterface.com/downloads/fileinfo.php?id=23599#comments

"Release codename: Chambersburg"

v1.0-2015062401
- bump toc for 6.2

v1.0-2015060101
- first release.

"This release is dedicated to a person that I do not read for a long time.
I hope she'll come back soon, because we miss her so much."
Optional Files (0)


Archived Files (3)
File Name
Version
Size
Author
Date
1000-2022110601
25kB
gmarco
11-06-22 03:10 AM
915-2021110401
25kB
gmarco
11-03-21 11:23 PM
915-2021110301
24kB
gmarco
11-03-21 01:29 PM


Post A Reply Comment Options
Unread 10-03-15, 10:44 AM  
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view AddOns

Forum posts: 362
File comments: 334
Uploads: 46
... and now it's time to fix all others addons of mine with the same best practices
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
Report comment to moderator  
Reply With Quote
Unread 10-03-15, 10:29 AM  
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view AddOns

Forum posts: 362
File comments: 334
Uploads: 46
Much better :-)


Lua Code:
  1. local ADDON = ...
  2.  
  3. local prgname = "|cffffd200gmLoot|r"
  4. local string_format = string.format
  5. local tooltip
  6.  
  7. GMLOOT = {
  8.      COINS = true,
  9.      QUEST = true,
  10. }
  11.  
  12.  
  13. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  14. local dataobj = ldb:NewDataObject("gmLoot", {
  15.     type = "data source",
  16.     icon = "Interface\\Icons\\INV_Misc_QuestionMark.blp",
  17.     text = "None"
  18. })
  19.  
  20.  
  21. local function UpdateLDB()
  22.  
  23.         local autoloot = GetCVar("autoLootDefault")
  24.  
  25.         dataobj.icon = "Interface\\Icons\\INV_Misc_Gear_08.blp"
  26.  
  27.         if autoloot ==  "1"     then
  28.             dataobj.text = "auto"
  29.         else
  30.             dataobj.text = "man"
  31.         end
  32.        
  33. end
  34.  
  35. local frame = CreateFrame("Frame")
  36. frame:RegisterEvent('CVAR_UPDATE')
  37. frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  38. frame:RegisterEvent('LOOT_OPENED')
  39. frame:SetScript("OnEvent", function(self, event, ...)
  40.  
  41.     if event == "CVAR_UPDATE" or event == "PLAYER_ENTERING_WORLD"then
  42.          
  43.             UpdateLDB()
  44.          
  45.     elseif event == "LOOT_OPENED" then
  46.          
  47.             if  GetCVarBool("autoLootDefault") then return end 
  48.                
  49.                 -- code adapted and simplified by semiautolooter --
  50.                 local loot_count = GetNumLootItems()
  51.                 for slot = 1, loot_count do
  52.                     local _,_,_,_,locked,isQuestItem = GetLootSlotInfo(slot)
  53.                     if isQuestItem == true and not locked and GMLOOT["QUEST"] == true then
  54.                         LootSlot(slot);
  55.                     elseif GetLootSlotType(slot) == LOOT_SLOT_MONEY and not locked and GMLOOT["COINS"] == true then
  56.                         LootSlot(slot);
  57.                     end
  58.             end          
  59.     end
  60. end)   
  61.  
  62.  
  63. dataobj.OnClick = function(self, button)  
  64.  
  65.  
  66.     if      button == "RightButton" then  GMLOOT["QUEST"] = not GMLOOT["QUEST"]
  67.    
  68.     elseif  button == "MiddleButton" then GMLOOT["COINS"] = not GMLOOT["COINS"]
  69.    
  70.     elseif  button == "LeftButton" then
  71.    
  72.         if GetCVarBool("autoLootDefault") then
  73.             SetCVar( "autoLootDefault", "0", true )
  74.         else
  75.             SetCVar( "autoLootDefault", "1", true )
  76.         end
  77.        
  78.         UpdateLDB()
  79.        
  80.      end
  81.  
  82. end
  83.  
  84. function dataobj.OnTooltipShow(tooltip)
  85.  
  86.     tooltip:AddLine(ADDON)
  87.     tooltip:AddLine(" ")
  88.    
  89.     if GetCVarBool("autoLootDefault") then
  90.         tooltip:AddDoubleLine("Loot mode", "auto", 1,1,1,0,1,0)
  91.     else
  92.         tooltip:AddDoubleLine("Loot mode", "manual", 1,1,1,1,0,0)
  93.     end
  94.  
  95.     if GMLOOT["COINS"] == true then
  96.         tooltip:AddDoubleLine("AutoLoot coins", "YES", 1,1,1,0,1,0)
  97.     else
  98.         tooltip:AddDoubleLine("AutoLoot coins", "NO", 1,1,1,1,0,0)
  99.     end
  100.    
  101.     if GMLOOT["QUEST"] == true then
  102.         tooltip:AddDoubleLine("AutoLoot quest items", "YES", 1,1,1,0,1,0)
  103.     else
  104.         tooltip:AddDoubleLine("AutoLoot quest items", "NO", 1,1,1,1,0,0)
  105.     end
  106.    
  107.     tooltip:AddLine(" ")
  108.     tooltip:AddDoubleLine("Left Click", "Toggle Loot Mode")
  109.     tooltip:AddDoubleLine("Middle Click", "Toggle AutoLoot coins")
  110.     tooltip:AddDoubleLine("Right Click", "Toggle AutoLoot quest items")
  111.  
  112. end
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
Report comment to moderator  
Reply With Quote
Unread 10-03-15, 08:16 AM  
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view AddOns

Forum posts: 362
File comments: 334
Uploads: 46
Phanx,

thanks you so much for you debugging.

It is really really a wonderful lesson of LUA coding style. Really appreciated.

I really have learnt more from your comments and inputs (and of others forum users as well than spending hours reading books and googling here and there.

Now I'll try to implement all your suggestions and inputs asap. Let's see what I am able to do :-))

Thanks again Phanx.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
Report comment to moderator  
Reply With Quote
Unread 10-02-15, 05:20 AM  
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view AddOns

Forum posts: 5617
File comments: 2321
Uploads: 54
Originally Posted by gmarco
Ehm ... I hope mine, gmloot, (which is heavily derived from it) is better if you have checked it :-)
At a glance, I don't see any global leakage, so that's good. The only issues I see are minor, and fixing them would mainly be educational.

--------------------------------

You should never specify both OnTooltipShow and OnEnter/OnLeave. When possible, just use OnTooltipShow, and let the display handle showing, positioning, and hiding the tooltip. The only reason to use OnEnter/OnLeave is if you're using a custom tooltip object (like LibQTip) or want to do something other than show a tooltip when the user mouses over your plugin. In your case, just use OnTooltipShow.

Also, your OnTooltipShow method doesn't get your data object as its first argument, but does get a reference to the tooltip object being used, so this:
Code:
function dataobj:OnTooltipShow()
should be rewritten like this:
Code:
function dataobj.OnTooltipShow(tooltip)
and then inside that function, you should refer to "tooltip" instead of "GameTooltip". In the vast majority of cases, the display addon will just use the GameTooltip, but it doesn't have to, and in cases where it doesn't, your code won't work.

--------------------------------

You're currently doing this in both your OnClick and OnEnter methods:
Code:
	
	if InCombatLockdown() then 
		return 
	end
Don't do this, in either place (though you should be getting rid of OnEnter anyway). You should leave it up to the user's chosen display whether they want to show the tooltip and/or respond to clicks in combat. The only good reason to handle yourself is if your plugin does things that can't be done in combat. Personally, I find it bad enough that my display addon (Bazooka) defaults to "no tooltips in combat" for newly installed plugins, and then I try to mouse over it in combat, and get nothing. If I didn't want to see the tooltip, I wouldn't put my mouse there!

--------------------------------

"elseif" is your friend!
Code:
	if button == "RightButton" then 
		-- stuff
	end

	if button == "MiddleButton" then
		-- stuff
	end

	if button ==  "LeftButton" then
		-- stuff
	end
Change all those "end ... if"s to "elseif"s. Currently you're running all 3 checks, even after you've found the only one that will pass.

--------------------------------

You don't need to (and shouldn't) create 3 separate frames to handle events. One frame can handle multiple events:
Code:
local frame = CreateFrame("Frame")
frame:RegisterEvent("RECEIVED_APPLES")
frame:RegisterEvent("RECEIVED_BANANAS")
frame:RegisterEvent("RECEIVED_COCONUTS")
frame:SetScript("OnEvent", function(self, event, ...)
     if event == "RECEIVED_APPLES" then
          print("It's an apple!")
     elseif event == "RECEIVED_BANANAS" or event == "RECEIVED_COCONUTS" then
          print("It's either a banana or a coconut.")
     end
end)
--------------------------------

When you initialize a saved variable in the main chunk (eg. right away when WoW loads your file, not waiting for any events) it will always be nil so there's no purpose in checking whether it's anything else.
Code:
GMLOOT = GMLOOT or {}
GMLOOT will always be nil here, so it will always get set to {}. Saved variables aren't loaded until ADDON_LOADED fires for your addon, so it's safe to set the initial value in the main chunk with just:
Code:
GMLOOT = {}
The next line has an additional problem:
Code:
GMLOOT["COINS"] = 	GMLOOT["COINS"] 	or true
Not only will GMLOOT["COINS"] always be nil here, but if this line ran after the actual saved variable had been loaded, and the user had turned off coin looting, since that preference would be stored as the boolean false, this line would overwrite their preference with true, turning coin looting back on.

You should replace these three lines with this:
Code:
GMLOOT = {
     COINS = true,
     QUEST = true,
}
This way, GMLOOT is defined as that (default) table when your file is read, then gets overwritten by the real (saved) table just before ADDON_LOADED fires.

--------------------------------

You could use boolean values more effectively. For example, you can simplify things like this:
Code:
			if GMLOOT["QUEST"] == true then
				GMLOOT["QUEST"] = false
			else 
				GMLOOT["QUEST"] = true
			end
to this:
Code:
			GMLOOT["QUEST"] = not GMLOOT["QUEST"]
And instead of this:
Code:
			if GMLOOT["COIN"] == false then
				summary = summary .. "[autoloot money no] "
			else
				summary = summary .. "[autoloot money yes] "
			end
Do this:
Code:
			if GMLOOT["COIN"] then
				summary = summary .. "[autoloot money yes] "
			else
				summary = summary .. "[autoloot money no] "
			end
You can also work with CVars as booleans. Instead of doing things like this:
Code:
if  GetCVar("autoLootDefault") ==  "1" then
you can do this:
Code:
if GetCVarBool("autoLootDefault") then
--------------------------------

Don't print stuff every time the player logs in. Give them credit for being able to remember that they installed your addon and configured it to their liking. When it's just your addon spamming, it's maybe not so bad, but imagine that every addon you use prints even just one line of text when you log in. That's a ton of spam, and not only is annoying, but also ends up hiding things that actually matter, like your guild's message of the day.
__________________
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.
Report comment to moderator  
Reply With Quote
Unread 06-01-15, 11:24 AM  
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view AddOns

Forum posts: 362
File comments: 334
Uploads: 46
v1.0-2015060101
- first release.

"This release is dedicated to a person that I do not read for a long time.
I hope she'll come back soon, because we miss her so much."
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: