comparison Degaine.lua @ 28:a91e7552c682 v1.0beta5

Use a whitelis instead of a blacklist. Used OnUpdate for mounts, didn't work well with UNIT_AURA
author contrebasse
date Fri, 10 Dec 2010 22:40:32 +0100
parents dd1ef3996d7f
children d66bb6a8d8bb
comparison
equal deleted inserted replaced
27:239bedf57140 28:a91e7552c682
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
57 BINDING_HEADER_DEGAINE = "Dégainer automatiquement" 57 BINDING_HEADER_DEGAINE = "Dégainer automatiquement"
58 58
59 -- Print status 59 -- Print status
60 local printState = function() 60 local printState = function()
61 DEFAULT_CHAT_FRAME:AddMessage(Degaine_isAuto and "Dégainage automatique |cFF00FF00activé|r" or "Dégainage automatique |cFFFF0000désactivé|r") 61 DEFAULT_CHAT_FRAME:AddMessage(Degaine_isAuto and "Dégainage automatique |cFF00FF00activé|r" or "Dégainage automatique |cFFFF0000désactivé|r")
62 end
63
64
65 ---------------------------------------------------------------
66 -- Launch drawing weapons
67 ---------------------------------------------------------------
68 -- Wait a few seconds before drawing, to be able to see the curren animation (and avoid bugs)
69 local Degaine_OnUpdate = function(self,t_elapsed)
70 t_left = t_left - t_elapsed;
71 if t_left<=0 then
72 ToggleSheath()
73 DegaineFrame:SetScript("OnUpdate", nil)
74 end
75 end
76 local start = function()
77 if Degaine_isAuto and not InCombatLockdown() then
78 t_left = delay
79 DegaineFrame:SetScript("OnUpdate", Degaine_OnUpdate)
80 end
62 end 81 end
63 82
64 83
65 --------------------------------------------------------------- 84 ---------------------------------------------------------------
66 -- Events config 85 -- Events config
92 } 111 }
93 local events1player = { -- the first arg is "player" 112 local events1player = { -- the first arg is "player"
94 UNIT_SPELLCAST_FAILED = true, 113 UNIT_SPELLCAST_FAILED = true,
95 UNIT_SPELLCAST_INTERRUPTED = true, 114 UNIT_SPELLCAST_INTERRUPTED = true,
96 UNIT_SPELLCAST_SUCCEEDED = true, 115 UNIT_SPELLCAST_SUCCEEDED = true,
97 UNIT_AURA = function() 116 }
98 if IsMounted() then 117 local SpellWhiteList = {
99 wasMounted = true 118 [8690] = true, -- Heartstone
100 else 119 [818] = true, -- Basic Campfire
101 if wasMounted then 120 }
102 wasMounted = false 121 --[[
103 start()
104 end
105 end
106 end
107 }
108 local SpellBlackList = { -- spells that don't stealth weapons (works with events1player) 122 local SpellBlackList = { -- spells that don't stealth weapons (works with events1player)
109 [1784] = true, -- Stealth (Rogue) 123 [1784] = true, -- Stealth (Rogue)
110 [58984] = true, -- Shadowmeld (Nightelf stealth) 124 [58984] = true, -- Shadowmeld (Nightelf stealth)
111 125
112 -- Tradeskill spells 126 -- Tradeskill spells
122 [2550] = true, -- Cooking 136 [2550] = true, -- Cooking
123 [3273] = true, -- First Aid 137 [3273] = true, -- First Aid
124 [53428] = true -- Runeforge 138 [53428] = true -- Runeforge
125 -- Archaeology ? 139 -- Archaeology ?
126 } 140 }
141 --]]
127 local events2playername = { -- the 2nd arg is playername 142 local events2playername = { -- the 2nd arg is playername
128 CHAT_MSG_SAY = true, 143 CHAT_MSG_SAY = true,
129 CHAT_MSG_YELL = true, 144 CHAT_MSG_YELL = true,
130 CHAT_MSG_TEXT_EMOTE = true, 145 CHAT_MSG_TEXT_EMOTE = true,
131 } 146 }
136 --------------------------------------------------------------- 151 ---------------------------------------------------------------
137 -- works with GupPet but not with the default interface... 152 -- works with GupPet but not with the default interface...
138 -- I guess that's because a specific /cancelaura or alike is done 153 -- I guess that's because a specific /cancelaura or alike is done
139 -- hooksecurefunc("Dismount",start); 154 -- hooksecurefunc("Dismount",start);
140 155
141 --[[ With OnUpdate 156 -- With OnUpdate
142 local handleMountsFrame = CreateFrame("frame") 157 local handleMountsFrame = CreateFrame("frame")
143 local handleMountsOnUpdate 158 local handleMountsOnUpdate
144 do 159 do
145 local IsMounted = IsMounted 160 local IsMounted = IsMounted
146 local wasMounted = IsMounted() 161 local wasMounted = IsMounted()
153 wasMounted = false 168 wasMounted = false
154 end 169 end
155 end 170 end
156 end 171 end
157 end 172 end
158 --]]
159
160
161 ---------------------------------------------------------------
162 -- Launch drawing weapons
163 ---------------------------------------------------------------
164 -- Wait a few seconds before drawing, to be able to see the curren animation (and avoid bugs)
165 local Degaine_OnUpdate = function(self,t_elapsed)
166 t_left = t_left - t_elapsed;
167 if t_left<=0 then
168 ToggleSheath()
169 DegaineFrame:SetScript("OnUpdate", nil)
170 end
171 end
172 local start = function()
173 if Degaine_isAuto and not InCombatLockdown() then
174 t_left = delay
175 DegaineFrame:SetScript("OnUpdate", Degaine_OnUpdate)
176 end
177 end
178 173
179 174
180 --------------------------------------------------------------- 175 ---------------------------------------------------------------
181 -- Activation functions 176 -- Activation functions
182 --------------------------------------------------------------- 177 ---------------------------------------------------------------
190 else 185 else
191 --@end-debug@ 186 --@end-debug@
192 for k,_ in pairs(events) do DegaineFrame:RegisterEvent(k) end 187 for k,_ in pairs(events) do DegaineFrame:RegisterEvent(k) end
193 for k,_ in pairs(events1player) do DegaineFrame:RegisterEvent(k) end 188 for k,_ in pairs(events1player) do DegaineFrame:RegisterEvent(k) end
194 for k,_ in pairs(events2playername) do DegaineFrame:RegisterEvent(k) end 189 for k,_ in pairs(events2playername) do DegaineFrame:RegisterEvent(k) end
190 --DegaineFrame:RegisterEvent("UNIT_AURA")
191 handleMountsFrame:SetScript("OnUpdate",handleMountsOnUpdate)
195 --@end-debug@ 192 --@end-debug@
196 end 193 end
197 --@end-debug@ 194 --@end-debug@
198 handleMountsFrame:SetScript("OnUpdate",handleMountsOnUpdate)
199 end 195 end
200 local desactivate = function() 196 local desactivate = function()
201 DegaineFrame:SetScript("OnUpdate", nil) 197 DegaineFrame:SetScript("OnUpdate", nil)
202 handleMountsFrame:SetScript("OnUpdate",nil)
203 t_left = -1 198 t_left = -1
204 for k,_ in pairs(events) do DegaineFrame:UnregisterEvent(k) end 199 for k,_ in pairs(events) do DegaineFrame:UnregisterEvent(k) end
205 for k,_ in pairs(events1player) do DegaineFrame:UnregisterEvent(k) end 200 for k,_ in pairs(events1player) do DegaineFrame:UnregisterEvent(k) end
206 for k,_ in pairs(events2playername) do DegaineFrame:UnregisterEvent(k) end 201 for k,_ in pairs(events2playername) do DegaineFrame:UnregisterEvent(k) end
202 --DegaineFrame:UnregisterEvent("UNIT_AURA")
203 handleMountsFrame:SetScript("OnUpdate",nil)
207 end 204 end
208 Degaine_ToggleAuto = function() 205 Degaine_ToggleAuto = function()
209 if Degaine_isAuto then 206 if Degaine_isAuto then
210 Degaine_isAuto = false 207 Degaine_isAuto = false
211 desactivate() 208 desactivate()
228 --if arg1 then DEFAULT_CHAT_FRAME:AddMessage("arg1 = "..arg1) end 225 --if arg1 then DEFAULT_CHAT_FRAME:AddMessage("arg1 = "..arg1) end
229 --if arg2 then DEFAULT_CHAT_FRAME:AddMessage("arg2 = "..arg2) end 226 --if arg2 then DEFAULT_CHAT_FRAME:AddMessage("arg2 = "..arg2) end
230 --end 227 --end
231 --@end-debug@ 228 --@end-debug@
232 229
230 --[[ IsMounted() renvoie toujours false ici, on doit passer par OnUpdate
231 if event=="UNIT_AURA" then
232 if arg1=="player" then
233 DEFAULT_CHAT_FRAME:AddMessage("player")
234 if IsMounted() then
235 DEFAULT_CHAT_FRAME:AddMessage("ismounted")
236 wasMounted = true
237 else
238 DEFAULT_CHAT_FRAME:AddMessage("notmounted")
239 if wasMounted then
240 DEFAULT_CHAT_FRAME:AddMessage("wasmounted : start")
241 wasMounted = false
242 start()
243 end
244 end
245 end
246 else
247 --]]
233 if events[event] then 248 if events[event] then
234 if type(events[event])~="function" or events[event]() then 249 if type(events[event])~="function" or events[event]() then
235 start() 250 start()
236 end 251 end
237 elseif events1player[event] then 252 elseif events1player[event] then
238 if arg1=="player" then 253 if arg1=="player" then
239 if arg5==nil or not SpellBlackList[arg5] then -- arg5 is SpellID 254 if arg5==nil or SpellWhiteList[arg5] then -- arg5 is SpellID
240 start() 255 start()
241 end 256 end
242 end 257 end
243 elseif events2playername[event] then 258 elseif events2playername[event] then
244 if arg2==playername then 259 if arg2==playername then