comparison Degaine.lua @ 24:3b1123f50be4 v1.0beta3

Adding support for dismount
author contrebasse
date Fri, 10 Dec 2010 21:06:46 +0100
parents 44e8394d6982
children dd1ef3996d7f
comparison
equal deleted inserted replaced
23:44e8394d6982 24:3b1123f50be4
29 -- Wow functions 29 -- Wow functions
30 local GetTime = GetTime 30 local GetTime = GetTime
31 local InCombatLockdown = InCombatLockdown 31 local InCombatLockdown = InCombatLockdown
32 local ToggleSheath = ToggleSheath 32 local ToggleSheath = ToggleSheath
33 local UnitName = UnitName 33 local UnitName = UnitName
34 local IsMounted = IsMounted
34 35
35 36
36 --------------------------------------------------------------- 37 ---------------------------------------------------------------
37 -- Local vars 38 -- Local vars
38 --------------------------------------------------------------- 39 ---------------------------------------------------------------
39 -- const 40 -- const
40 local DegaineFrame = CreateFrame("Frame") 41 local DegaineFrame = CreateFrame("Frame")
41 local playername = UnitName("player") 42 local playername = UnitName("player")
43 local delay = 2 -- seconds
42 44
43 -- vars 45 -- vars
44 local t_left = -1 46 local t_left = -1
45 local delay = 2 -- seconds
46 local isGossipClosed = true 47 local isGossipClosed = true
47 local wasGossipOpened = false 48 local wasGossipOpened = false
48 local t_lastGossipClosed = 0 49 local t_lastGossipClosed = 0
50 local wasMounted = IsMounted() -- handle mounts with UNIT_AURA
49 51
50 52
51 --------------------------------------------------------------- 53 ---------------------------------------------------------------
52 -- Some stuff... 54 -- Some stuff...
53 --------------------------------------------------------------- 55 ---------------------------------------------------------------
90 } 92 }
91 local events1player = { -- the first arg is "player" 93 local events1player = { -- the first arg is "player"
92 UNIT_SPELLCAST_FAILED = true, 94 UNIT_SPELLCAST_FAILED = true,
93 UNIT_SPELLCAST_INTERRUPTED = true, 95 UNIT_SPELLCAST_INTERRUPTED = true,
94 UNIT_SPELLCAST_SUCCEEDED = true, 96 UNIT_SPELLCAST_SUCCEEDED = true,
97 UNIT_AURA = function()
98 if IsMounted() then
99 wasMounted = true
100 else
101 if wasMounted then
102 start()
103 wasMounted = false
104 end
105 end
106 end
95 } 107 }
96 local SpellBlackList = { -- spells that don't stealth weapons (works with events1player) 108 local SpellBlackList = { -- spells that don't stealth weapons (works with events1player)
97 [1784] = true, -- Stealth (Rogue) 109 [1784] = true, -- Stealth (Rogue)
98 [58984] = true, -- Shadowmeld (Nightelf stealth) 110 [58984] = true, -- Shadowmeld (Nightelf stealth)
99 111
118 CHAT_MSG_TEXT_EMOTE = true, 130 CHAT_MSG_TEXT_EMOTE = true,
119 } 131 }
120 132
121 133
122 --------------------------------------------------------------- 134 ---------------------------------------------------------------
135 -- Handle mounts with OnUpdate
136 ---------------------------------------------------------------
137 -- works with GupPet but not with the default interface...
138 -- I guess that's because a specific /cancelaura or alike is done
139 -- hooksecurefunc("Dismount",start);
140
141 --[[ With OnUpdate
142 local handleMountsFrame = CreateFrame("frame")
143 local handleMountsOnUpdate
144 do
145 local IsMounted = IsMounted
146 local wasMounted = IsMounted()
147 function handleMountsOnUpdate(self,t_elapsed)
148 if IsMounted() then
149 wasMounted = true
150 else
151 if wasMounted then
152 start()
153 wasMounted = false
154 end
155 end
156 end
157 end
158 --]]
159
160
161 ---------------------------------------------------------------
123 -- Launch drawing weapons 162 -- Launch drawing weapons
124 --------------------------------------------------------------- 163 ---------------------------------------------------------------
125 -- Wait a few seconds before drawing, to be able to see the curren animation (and avoid bugs) 164 -- Wait a few seconds before drawing, to be able to see the curren animation (and avoid bugs)
126 local Degaine_OnUpdate = function(self,t_elapsed) 165 local Degaine_OnUpdate = function(self,t_elapsed)
127 t_left = t_left - t_elapsed; 166 t_left = t_left - t_elapsed;
154 for k,_ in pairs(events1player) do DegaineFrame:RegisterEvent(k) end 193 for k,_ in pairs(events1player) do DegaineFrame:RegisterEvent(k) end
155 for k,_ in pairs(events2playername) do DegaineFrame:RegisterEvent(k) end 194 for k,_ in pairs(events2playername) do DegaineFrame:RegisterEvent(k) end
156 --@end-debug@ 195 --@end-debug@
157 end 196 end
158 --@end-debug@ 197 --@end-debug@
198 handleMountsFrame:SetScript("OnUpdate",handleMountsOnUpdate)
159 end 199 end
160 local desactivate = function() 200 local desactivate = function()
201 DegaineFrame:SetScript("OnUpdate", nil)
202 handleMountsFrame:SetScript("OnUpdate",nil)
203 t_left = -1
161 for k,_ in pairs(events) do DegaineFrame:UnregisterEvent(k) end 204 for k,_ in pairs(events) do DegaineFrame:UnregisterEvent(k) end
162 for k,_ in pairs(events1player) do DegaineFrame:UnregisterEvent(k) end 205 for k,_ in pairs(events1player) do DegaineFrame:UnregisterEvent(k) end
163 for k,_ in pairs(events2playername) do DegaineFrame:UnregisterEvent(k) end 206 for k,_ in pairs(events2playername) do DegaineFrame:UnregisterEvent(k) end
164 DegaineFrame:SetScript("OnUpdate", nil)
165 end 207 end
166 Degaine_ToggleAuto = function() 208 Degaine_ToggleAuto = function()
167 if Degaine_isAuto then 209 if Degaine_isAuto then
168 Degaine_isAuto = false 210 Degaine_isAuto = false
169 desactivate() 211 desactivate()
173 end 215 end
174 printState() 216 printState()
175 end 217 end
176 218
177 219
220
178 --------------------------------------------------------------- 221 ---------------------------------------------------------------
179 -- Event/hooks functions 222 -- Event/hooks functions
180 --------------------------------------------------------------- 223 ---------------------------------------------------------------
181 local Degaine_OnEvent = function(self,event, arg1, arg2, _, _, arg5, ...) 224 local Degaine_OnEvent = function(self,event, arg1, arg2, _, _, arg5, ...)
182 --@debug@ 225 --@debug@
191 if type(events[event])~="function" or events[event]() then 234 if type(events[event])~="function" or events[event]() then
192 start() 235 start()
193 end 236 end
194 elseif events1player[event] then 237 elseif events1player[event] then
195 if arg1=="player" then 238 if arg1=="player" then
196 if not SpellBlackList[arg5] then -- arg5 is SpellID 239 if arg5==nil or not SpellBlackList[arg5] then -- arg5 is SpellID
197 start() 240 start()
198 end 241 end
199 end 242 end
200 elseif events2playername[event] then 243 elseif events2playername[event] then
201 if arg2==playername then 244 if arg2==playername then
205 wasGossipOpened = not isGossipClosed 248 wasGossipOpened = not isGossipClosed
206 isGossipClosed = true 249 isGossipClosed = true
207 t_lastGossipClosed = GetTime() 250 t_lastGossipClosed = GetTime()
208 251
209 elseif event == "PLAYER_REGEN_ENABLED" then 252 elseif event == "PLAYER_REGEN_ENABLED" then
210 --for k,_ in pairs(events1player) do DegaineFrame:UnregisterEvent(k) end
211 desactivate() 253 desactivate()
212 elseif event == "PLAYER_REGEN_DISABLED" then 254 elseif event == "PLAYER_REGEN_DISABLED" then
213 --for k,_ in pairs(events1player) do DegaineFrame:RegisterEvent(k) end
214 activate() 255 activate()
215 256
216 elseif event == "ADDON_LOADED" and arg1==AddonName then 257 elseif event == "ADDON_LOADED" and arg1==AddonName then
217 if Degaine_isAuto==nil then 258 if Degaine_isAuto==nil then
218 Degaine_isAuto = true 259 Degaine_isAuto = true
225 end 266 end
226 end 267 end
227 -- Hook when standing up 268 -- Hook when standing up
228 -- (Didn't work, see http://forums.wowace.com/showthread.php?p=310547#post310547) 269 -- (Didn't work, see http://forums.wowace.com/showthread.php?p=310547#post310547)
229 hooksecurefunc("SitStandOrDescendStart",start); 270 hooksecurefunc("SitStandOrDescendStart",start);
230 hooksecurefunc("Dismount",start); -- works with GupPet but not with the default interface...
231 271
232 272
233 --------------------------------------------------------------- 273 ---------------------------------------------------------------
234 -- Commands 274 -- Commands
235 --------------------------------------------------------------- 275 ---------------------------------------------------------------