Mercurial > wow > degaine
comparison Degaine.lua @ 8:47f9e596ef5a
Use a specific function for drawing
| author | contrebasse |
|---|---|
| date | Fri, 10 Dec 2010 16:37:00 +0100 |
| parents | f8198806d261 |
| children | 571dcc76d801 |
comparison
equal
deleted
inserted
replaced
| 7:f8198806d261 | 8:47f9e596ef5a |
|---|---|
| 25 local InCombatLockdown = InCombatLockdown | 25 local InCombatLockdown = InCombatLockdown |
| 26 local ToggleSheath = ToggleSheath | 26 local ToggleSheath = ToggleSheath |
| 27 | 27 |
| 28 | 28 |
| 29 --------------------------------------------------------------- | 29 --------------------------------------------------------------- |
| 30 -- Local vars | |
| 31 --------------------------------------------------------------- | |
| 32 -- const | |
| 33 local DegaineFrame = CreateFrame("Frame") | |
| 34 local playername = UnitName("player") | |
| 35 | |
| 36 -- vars | |
| 37 local done = true | |
| 38 local t_left = -1 | |
| 39 local delay = 2 -- seconds | |
| 40 | |
| 41 --------------------------------------------------------------- | |
| 30 -- Some stuff... | 42 -- Some stuff... |
| 31 --------------------------------------------------------------- | 43 --------------------------------------------------------------- |
| 32 -- Bindings | 44 -- Bindings |
| 33 BINDING_HEADER_DEGAINE = "Dégainer automatiquement" | 45 BINDING_HEADER_DEGAINE = "Dégainer automatiquement" |
| 34 | 46 |
| 35 -- Print status | 47 -- Print status |
| 36 local printState = function() | 48 local printState = function() |
| 37 DEFAULT_CHAT_FRAME:AddMessage(Degaine_isAuto and "Dégainage automatique |cFF00FF00activé|r" or "Dégainage automatique |cFFFF0000désactivé|r"); | 49 DEFAULT_CHAT_FRAME:AddMessage(Degaine_isAuto and "Dégainage automatique |cFF00FF00activé|r" or "Dégainage automatique |cFFFF0000désactivé|r"); |
| 38 end | 50 end |
| 39 | 51 |
| 40 | |
| 41 --------------------------------------------------------------- | |
| 42 -- Local vars | |
| 43 --------------------------------------------------------------- | |
| 44 -- const | |
| 45 local DegaineFrame = CreateFrame("Frame") | |
| 46 local playername = UnitName("player") | |
| 47 | |
| 48 -- vars | |
| 49 local done = true | |
| 50 local t_left = -1 | |
| 51 | 52 |
| 52 --------------------------------------------------------------- | 53 --------------------------------------------------------------- |
| 53 -- Events config | 54 -- Events config |
| 54 --------------------------------------------------------------- | 55 --------------------------------------------------------------- |
| 55 -- Events to watch | 56 -- Events to watch |
| 74 CHAT_MSG_TEXT_EMOTE = true, | 75 CHAT_MSG_TEXT_EMOTE = true, |
| 75 } | 76 } |
| 76 | 77 |
| 77 | 78 |
| 78 --------------------------------------------------------------- | 79 --------------------------------------------------------------- |
| 79 -- Timer | 80 -- Launch drawing weapons |
| 80 --------------------------------------------------------------- | 81 --------------------------------------------------------------- |
| 81 -- Wait a few seconds before drawing, to be able to see the curren animation (and avoid bugs) | 82 -- Wait a few seconds before drawing, to be able to see the curren animation (and avoid bugs) |
| 82 local Degaine_OnUpdate = function(self,t_elapsed) | 83 local Degaine_OnUpdate = function(self,t_elapsed) |
| 83 if not done then | 84 if not done then |
| 84 t_left = t_left - t_elapsed; | 85 t_left = t_left - t_elapsed; |
| 85 if t_left<=0 then | 86 if t_left<=0 then |
| 86 done = true; | 87 done = true; |
| 87 ToggleSheath(); | 88 ToggleSheath(); |
| 89 DegaineFrame:SetScript("OnUpdate", nil); | |
| 88 end | 90 end |
| 89 end | 91 end |
| 90 end | 92 end |
| 91 | 93 local start = function() |
| 94 if Degaine_isAuto and not InCombatLockdown() then | |
| 95 t_left = delay | |
| 96 done = false | |
| 97 DegaineFrame:SetScript("OnUpdate", Degaine_OnUpdate); | |
| 98 end | |
| 99 end | |
| 92 | 100 |
| 93 --------------------------------------------------------------- | 101 --------------------------------------------------------------- |
| 94 -- Activation functions | 102 -- Activation functions |
| 95 --------------------------------------------------------------- | 103 --------------------------------------------------------------- |
| 96 local activate = function() | 104 local activate = function() |
| 141 --@end-debug@ | 149 --@end-debug@ |
| 142 | 150 |
| 143 if ((events[event] and (type(events[event])~="function" or events[event]())) | 151 if ((events[event] and (type(events[event])~="function" or events[event]())) |
| 144 or (events1player[event] and arg1=="player") | 152 or (events1player[event] and arg1=="player") |
| 145 or (events2playername[event] and arg2==playername)) then | 153 or (events2playername[event] and arg2==playername)) then |
| 146 t_left = 2 | 154 start() |
| 147 done = false | |
| 148 | 155 |
| 149 elseif event == "PLAYER_REGEN_ENABLED" then | 156 elseif event == "PLAYER_REGEN_ENABLED" then |
| 150 desactivate() | 157 desactivate() |
| 151 elseif event == "PLAYER_REGEN_DISABLED" then | 158 elseif event == "PLAYER_REGEN_DISABLED" then |
| 152 activate() | 159 activate() |
| 153 | 160 |
| 154 elseif event == "ADDON_LOADED" and arg1==AddonName then | 161 elseif event == "ADDON_LOADED" and arg1==AddonName then |
| 155 if Degaine_isAuto==nil then | 162 if Degaine_isAuto==nil then |
| 156 Degaine_isAuto = true | 163 Degaine_isAuto = true |
| 157 end | 164 end |
| 158 if Degaine_isAuto then | 165 if Degaine_isAuto then activate(); else desactivate(); end |
| 159 activate() | |
| 160 else | |
| 161 desactivate() | |
| 162 end | |
| 163 printState() | 166 printState() |
| 164 | 167 |
| 165 -- Not needed anymore | 168 -- Not needed anymore |
| 166 DegaineFrame:UnregisterEvent("ADDON_LOADED") | 169 DegaineFrame:UnregisterEvent("ADDON_LOADED") |
| 167 end | 170 end |
| 168 end | 171 end |
| 169 -- Hook when standing up | 172 -- Hook when standing up |
| 170 -- (Didn't work, see http://forums.wowace.com/showthread.php?p=310547#post310547) | 173 -- (Didn't work, see http://forums.wowace.com/showthread.php?p=310547#post310547) |
| 171 hooksecurefunc("SitStandOrDescendStart",function() | 174 hooksecurefunc("SitStandOrDescendStart",start); |
| 172 if Degaine_isAuto and not InCombatLockdown() then | |
| 173 t_left = 2 | |
| 174 done = false | |
| 175 end | |
| 176 end) | |
| 177 | 175 |
| 178 | 176 |
| 179 --------------------------------------------------------------- | 177 --------------------------------------------------------------- |
| 180 -- Commands | 178 -- Commands |
| 181 --------------------------------------------------------------- | 179 --------------------------------------------------------------- |
