comparison Degaine.lua @ 14:c627cef1c6d6 v1.0beta2

Lots of hacks for merchants and gossips
author contrebasse
date Fri, 10 Dec 2010 18:22:56 +0100
parents 7b1f3a9cba48
children c83103057b7a
comparison
equal deleted inserted replaced
13:7b1f3a9cba48 14:c627cef1c6d6
7 --------------------------------------------------------------- 7 ---------------------------------------------------------------
8 -- If you stand up by jumping or walking it won't draw your weapon 8 -- If you stand up by jumping or walking it won't draw your weapon
9 -- (it's not possible to know if you were sitting or standing before) 9 -- (it's not possible to know if you were sitting or standing before)
10 10
11 --@debug@ 11 --@debug@
12 local debug = true 12 local debug = false
13 --@end-debug@ 13 --@end-debug@
14 14
15 15
16 --------------------------------------------------------------- 16 ---------------------------------------------------------------
17 -- Globals to local 17 -- Globals to local
18 --------------------------------------------------------------- 18 ---------------------------------------------------------------
19 -- These need to be globals 19 -- These need to be globals
20 -- GLOBALS: Degaine_ToggleAuto, Degaine_isAuto, BINDING_HEADER_DEGAINE 20 -- GLOBALS: Degaine_ToggleAuto, Degaine_isAuto, BINDING_HEADER_DEGAINE
21 21
22 -- It doesn't matter if they are globals 22 -- It doesn't matter if they are globals
23 -- GLOBALS: DEFAULT_CHAT_FRAME, GossipFrame 23 -- GLOBALS: DEFAULT_CHAT_FRAME
24 24
25 -- Lua functions 25 -- Lua functions
26 local pairs = pairs; 26 local pairs = pairs;
27 local type = type; 27 local type = type;
28 28
29 -- Wow functions 29 -- Wow functions
30 local GetTime = GetTime
30 local InCombatLockdown = InCombatLockdown 31 local InCombatLockdown = InCombatLockdown
31 local ToggleSheath = ToggleSheath 32 local ToggleSheath = ToggleSheath
32 33
33 34
34 --------------------------------------------------------------- 35 ---------------------------------------------------------------
39 local playername = UnitName("player") 40 local playername = UnitName("player")
40 41
41 -- vars 42 -- vars
42 local t_left = -1 43 local t_left = -1
43 local delay = 2 -- seconds 44 local delay = 2 -- seconds
45 local isGossipClosed = true
46 local wasGossipOpened = false
47 local t_lastGossipClosed = 0
44 48
45 49
46 --------------------------------------------------------------- 50 ---------------------------------------------------------------
47 -- Some stuff... 51 -- Some stuff...
48 --------------------------------------------------------------- 52 ---------------------------------------------------------------
58 --------------------------------------------------------------- 62 ---------------------------------------------------------------
59 -- Events config 63 -- Events config
60 --------------------------------------------------------------- 64 ---------------------------------------------------------------
61 -- Events to watch 65 -- Events to watch
62 local events = { -- no args to watch 66 local events = { -- no args to watch
63 GOSSIP_SHOW = true, 67 GOSSIP_SHOW = function()
64 MERCHANT_SHOW = function() return GossipFrame:IsShown() end, 68 local returnvalue = isGossipClosed
69 isGossipClosed = false
70 return returnvalue
71 end,
72 MERCHANT_SHOW = function()
73 -- hack for the cases where the merchant's frame is opened from a gossip frame
74 if (GetTime() - t_lastGossipClosed) < 0.5 then
75 return not wasGossipOpened
76 else
77 return isGossipClosed
78 end
79 end,
65 BANKFRAME_OPENED = true, --function() return GossipFrame:IsShown() end, 80 BANKFRAME_OPENED = true, --function() return GossipFrame:IsShown() end,
66 AUCTION_HOUSE_SHOW = true, 81 AUCTION_HOUSE_SHOW = true,
67 } 82 }
68 local events1player = { -- the first arg is "player" 83 local events1player = { -- the first arg is "player"
69 UNIT_SPELLCAST_FAILED = true, 84 UNIT_SPELLCAST_FAILED = true,
155 --------------------------------------------------------------- 170 ---------------------------------------------------------------
156 -- Event/hooks functions 171 -- Event/hooks functions
157 --------------------------------------------------------------- 172 ---------------------------------------------------------------
158 local Degaine_OnEvent = function(self,event, arg1, arg2, _, _, arg5, ...) 173 local Degaine_OnEvent = function(self,event, arg1, arg2, _, _, arg5, ...)
159 --@debug@ 174 --@debug@
160 if debug then 175 --if debug then
161 DEFAULT_CHAT_FRAME:AddMessage(event) 176 DEFAULT_CHAT_FRAME:AddMessage(event)
162 if arg1 then DEFAULT_CHAT_FRAME:AddMessage("arg1 = "..arg1) end 177 --if arg1 then DEFAULT_CHAT_FRAME:AddMessage("arg1 = "..arg1) end
163 if arg2 then DEFAULT_CHAT_FRAME:AddMessage("arg2 = "..arg2) end 178 --if arg2 then DEFAULT_CHAT_FRAME:AddMessage("arg2 = "..arg2) end
164 end 179 --end
165 --@end-debug@ 180 --@end-debug@
166 181
167 if events[event] then 182 if events[event] then
168 if type(events[event])~="function" or events[event]() then 183 if type(events[event])~="function" or events[event]() then
169 start() 184 start()
176 end 191 end
177 elseif events2playername[event] then 192 elseif events2playername[event] then
178 if arg2==playername then 193 if arg2==playername then
179 start() 194 start()
180 end 195 end
196 elseif event == "GOSSIP_CLOSED" then
197 wasGossipOpened = not isGossipClosed
198 isGossipClosed = true
199 t_lastGossipClosed = GetTime()
181 200
182 elseif event == "PLAYER_REGEN_ENABLED" then 201 elseif event == "PLAYER_REGEN_ENABLED" then
183 desactivate() 202 desactivate()
184 elseif event == "PLAYER_REGEN_DISABLED" then 203 elseif event == "PLAYER_REGEN_DISABLED" then
185 activate() 204 activate()
216 -- Initialization 235 -- Initialization
217 --------------------------------------------------------------- 236 ---------------------------------------------------------------
218 DegaineFrame:SetScript("OnEvent",Degaine_OnEvent) 237 DegaineFrame:SetScript("OnEvent",Degaine_OnEvent)
219 238
220 -- Global events 239 -- Global events
240 DegaineFrame:RegisterEvent("GOSSIP_CLOSED")
221 DegaineFrame:RegisterEvent("PLAYER_REGEN_ENABLED") 241 DegaineFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
222 DegaineFrame:RegisterEvent("PLAYER_REGEN_DISABLED") 242 DegaineFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
223 DegaineFrame:RegisterEvent("ADDON_LOADED") 243 DegaineFrame:RegisterEvent("ADDON_LOADED")
224 activate() 244 activate()
225 245