Quantcast
Download
(10 Kb)
Download
Updated: 03-28-17 03:27 PM
Pictures
File Info
Compatibility:
Tomb of Sargeras (7.2.0)
Updated:03-28-17 03:27 PM
Created:06-01-15 11:23 AM
Downloads:712
Favorites:2
MD5:
7.2.0

gmLoot

Version: 720-2017032801
by: gmarco [More]

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.

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 (8)
File Name
Version
Size
Author
Date
715-2017030501
10kB
gmarco
03-06-17 12:29 AM
1.0-2016121601
10kB
gmarco
12-16-16 02:00 AM
1.0-2016102601
7kB
gmarco
10-26-16 10:01 AM
1.0-2016090201
7kB
gmarco
09-02-16 01:32 AM
1.0-2016072301
7kB
gmarco
07-24-16 02:51 AM
1.0-2015100301
7kB
gmarco
10-03-15 11:11 AM
1.0-2015062401
7kB
gmarco
06-24-15 12:09 AM
1.0-2015060101
7kB
gmarco
06-01-15 11:23 AM


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

Forum posts: 218
File comments: 126
Uploads: 36
... 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
A Cobalt Mageweaver
 
gmarco's Avatar
AddOn Author - Click to view AddOns

Forum posts: 218
File comments: 126
Uploads: 36
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
A Cobalt Mageweaver
 
gmarco's Avatar
AddOn Author - Click to view AddOns

Forum posts: 218
File comments: 126
Uploads: 36
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: 5567
File comments: 2288
Uploads: 46
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.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Report comment to moderator  
Reply With Quote
Unread 06-01-15, 11:24 AM  
gmarco
A Cobalt Mageweaver
 
gmarco's Avatar
AddOn Author - Click to view AddOns

Forum posts: 218
File comments: 126
Uploads: 36
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: