vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2  
3 BCUI Ammo Warning
4 =================
5  
6 Description:
7 ------------
8 Displays warning messages when the ammo type you have equiped in your ammo slot
9 reaches configurable levels. Initial values are set to warn you when your ammo
10 reaches 200, and then every 50 shots after that until your ammo reaches the
11 critical limit. Then, you recieve warnings every shot until you run out of ammo.
12  
13 Credits:
14 --------
15 - Many thanks to CapnBry over at http://capnbry.net/wow/ for the regular expression to
16 parse the item link string in bcAW_GetItemName().
17  
18 Setup:
19 ------
20 Change the BCAW_* variables below to set when the warning messages show. For example,
21 with the default values (BCAW_INITIAL_WARNING_COUNT = 200, BCAW_WARNING_INCREMENT = 50,
22 and BCAW_CRITICAL_WARNING_COUNT = 30), you'll recieve the first warning when you reach
23 an ammo count of 200. The next will be at 150, then 100, then 50. You then start to
24 recieve warnings at every shot once you reach 30 bullets/arrows left.
25  
26 Revision History:
27 -----------------
28 04/05/2005 1.06
29 - New Interface number.
30  
31 02/22/2005 1.05
32 - New Interface number.
33  
34 02/15/2005 1.04
35 - Added version numbers.
36  
37 - New Interface number.
38  
39 01/15/2005 v1.02
40 - Updated to check the ranged slot for thrown weapon count if nothing is found in the
41 ammo slot.
42  
43 - Added more verbose comments throughout the code.
44  
45 12/??/2004 v1.00
46 Initial release.
47  
48 ]]
49  
50 BCAW_INITIAL_WARNING_COUNT = 200;
51 BCAW_WARNING_INCREMENT = 50;
52 BCAW_CRITICAL_WARNING_COUNT = 30;
53  
54 function bcAW_OnLoad()
55 this:RegisterEvent("UNIT_INVENTORY_CHANGED");
56  
57 -- Let the user know the mod loaded.
58 if ( DEFAULT_CHAT_FRAME ) then
59 DEFAULT_CHAT_FRAME:AddMessage("BC Ammo Warning loaded");
60 end
61 end
62  
63 function bcAW_GetItemName(id)
64 local linktext = GetInventoryItemLink("player", id);
65  
66 if (linktext) then
67 local _,_,name = string.find(linktext, "^.*%[(.*)%].*$");
68 return name;
69 end
70 end
71  
72 function bcAW_OnEvent()
73 -- DEFAULT_CHAT_FRAME:AddMessage("bcAW_OnEvent(): called - "..event);
74 if (event == "UNIT_INVENTORY_CHANGED") then
75  
76 -- By default, monitor the ammo slot. But, if there is something in the ranged
77 -- slot with a quantity > 1, assume it's a throwing weapon.
78 this.ammoSlot = CharacterAmmoSlot:GetID();
79 local rangedCount = GetInventoryItemCount("player", CharacterRangedSlot:GetID());
80 if (rangedCount > 1) then
81 this.ammoSlot = CharacterRangedSlot:GetID();
82 end
83  
84 if (this.lastAmmoCount == nil) then
85 this.lastAmmoCount = GetInventoryItemCount("player", this.ammoSlot);
86 end
87  
88 this.currentAmmoCount = GetInventoryItemCount("player", this.ammoSlot);
89  
90 if (this.lastAmmoCount ~= this.currentAmmoCount) then
91 if (this.currentAmmoCount == BCAW_INITIAL_WARNING_COUNT) then
92 UIErrorsFrame:AddMessage("Low Ammo Warning! Shots left = "..this.currentAmmoCount, 1.0, 1.0, 0.0, 1.0, UIERRORS_HOLD_TIME);
93 elseif (math.mod(BCAW_INITIAL_WARNING_COUNT - this.currentAmmoCount, BCAW_WARNING_INCREMENT) == 0 and this.currentAmmoCount < BCAW_INITIAL_WARNING_COUNT) then
94 UIErrorsFrame:AddMessage("Low Ammo Warning! Shots left = "..this.currentAmmoCount, 1.0, 1.0, 0.0, 1.0, UIERRORS_HOLD_TIME);
95 elseif (this.currentAmmoCount > 0 and this.currentAmmoCount < BCAW_CRITICAL_WARNING_COUNT) then
96 UIErrorsFrame:AddMessage("Low Ammo Warning! Shots left = "..this.currentAmmoCount, 1.0, 1.0, 0.0, 1.0, UIERRORS_HOLD_TIME);
97 end
98 this.lastAmmoCount = this.currentAmmoCount;
99 end
100 end
101 end