vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- Addon: !AutoSave (version: 1.12.1) |
2 | -- Autor: Platine (e-mail: platine.wow@gmail.com) |
||
3 | |||
4 | -- Localization |
||
5 | local AS_Messages = { |
||
6 | loaded ="loaded.", -- loaded. |
||
7 | saved ="Saved the form.", -- Character saved. |
||
8 | active ="Enable AutoSave features", -- Enable AutoSave |
||
9 | confirme="View your record", -- Print confirmation |
||
10 | period ="Entry in the interval [sec]", -- Save-interval in [sec] |
||
11 | combat ="Save the output from the fight", -- Run on exit of combat |
||
12 | skill ="Sign in skills after promotion", -- Run on skill-up |
||
13 | quest ="Save this post", -- Run on quest completed |
||
14 | close ="Close", -- Close the window |
||
15 | |||
16 | AFK_on ="You are now AFK: Away from Keyboard", -- System message from event CHAT_MSG_SYSTEM |
||
17 | AFK_off ="You are no longer AFK." }; |
||
18 | |||
19 | -- Global Variables |
||
20 | local AutoSave_LastTime = GetTime(); -- last time made a record |
||
21 | local AutoSave_MinimPeriod = 100; -- protection against excessively high burden on the server |
||
22 | local AutoSave_PutSave = false; |
||
23 | local AutoSave_AFKtime = false; |
||
24 | local AutoSave_InCombat = false; |
||
25 | local AS_OnDebug = false; |
||
26 | |||
27 | |||
28 | function AS_OnLoad() |
||
29 | SLASH_AUTOSAVE1 = "/autosave"; |
||
30 | SLASH_AUTOSAVE2 = "/as"; |
||
31 | SlashCmdList["AUTOSAVE"] = AS_OnShow; |
||
32 | this:RegisterEvent("ADDON_LOADED"); |
||
33 | this:RegisterEvent("PLAYER_REGEN_ENABLED"); |
||
34 | this:RegisterEvent("PLAYER_REGEN_DISABLED"); |
||
35 | this:RegisterEvent("CHAT_MSG_SAY"); |
||
36 | this:RegisterEvent("CHAT_MSG_SKILL"); |
||
37 | this:RegisterEvent("CHAT_MSG_SYSTEM"); |
||
38 | this:RegisterEvent("PLAYER_LEVEL_UP"); |
||
39 | this:RegisterEvent("PLAYER_TARGET_CHANGED"); |
||
40 | this:RegisterEvent("QUEST_COMPLETE"); |
||
41 | this:RegisterEvent("UNIT_AURA"); |
||
42 | end |
||
43 | |||
44 | |||
45 | function AS_OnEvent() |
||
46 | if ((event == "ADDON_LOADED") and (arg1 == "!AutoSave")) then |
||
47 | -- dodatek zaladowano |
||
48 | AS_CheckVars(); |
||
49 | if (DEFAULT_CHAT_FRAME) then |
||
50 | DEFAULT_CHAT_FRAME:AddMessage("|cffffff00!AutoSave ver. 1.12.1 - "..AS_Messages.loaded); |
||
51 | else |
||
52 | UIErrorsFrame:AddMessage("!AutoSave ver. 1.12.1 - "..AS_Messages.loaded, 1.0, 1.0, 1.0, 1.0, UIERRORS_HOLD_TIME); |
||
53 | end |
||
54 | end |
||
55 | if (AutoSave_PC["check1"]=="on") then |
||
56 | -- działanie dodatku jest zezwolone |
||
57 | if (GetTime()<AutoSave_LastTime) then |
||
58 | -- zegar systemowy wyzerował się |
||
59 | if (AS_OnDebug) then |
||
60 | DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Wyzerowany licznik czasu: "..AutoSave_LastTime.." "..GetTime()); |
||
61 | end |
||
62 | AutoSave_LastTime=GetTime(); |
||
63 | end |
||
64 | if (AutoSave_LastTime+AutoSave_PC["okres"]<=GetTime()) then |
||
65 | -- minąl czas - trzeba zapisać postać |
||
66 | AutoSave_PutSave=true; |
||
67 | end |
||
68 | if (event=="PLAYER_REGEN_DISABLED") then |
||
69 | -- poczatek walki, nie zapisuj! |
||
70 | AutoSave_InCombat=true; |
||
71 | if (AS_OnDebug) then |
||
72 | DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Zdarzenie: PLAYER_REGEN_DISABLED."); |
||
73 | end |
||
74 | end |
||
75 | if (event=="PLAYER_REGEN_ENABLED") then |
||
76 | -- walka skonczona |
||
77 | AutoSave_InCombat=false; |
||
78 | if (AS_OnDebug) then |
||
79 | DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Zdarzenie: PLAYER_REGEN_ENABLED."); |
||
80 | end |
||
81 | if (AutoSave_PC["check3"]=="on") then |
||
82 | AutoSave_PutSave=true; |
||
83 | end |
||
84 | end |
||
85 | if (event=="PLAYER_LEVEL_UP") then |
||
86 | -- zmiana levela gracza |
||
87 | if (AS_OnDebug) then |
||
88 | DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Zdarzenie: PLAYER_LEVEL_UP "..arg1.." lvl"); |
||
89 | end |
||
90 | if (AutoSave_PC["check4"]=="on") then |
||
91 | AutoSave_PutSave=true; |
||
92 | end |
||
93 | end |
||
94 | if (event=="CHAT_MSG_SKILL") then |
||
95 | -- zmiana poziomu umiejętnosci |
||
96 | if (AS_OnDebug) then |
||
97 | DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Zdarzenie: CHAT_MSG_SKILL "..arg1.." "..arg2.." "..arg6); |
||
98 | end |
||
99 | if (strsub(arg1,1,10)=="Your skill") then |
||
100 | if (AutoSave_PC["check4"]=="on") then |
||
101 | AutoSave_PutSave=true; |
||
102 | end |
||
103 | end |
||
104 | end |
||
105 | if (event=="QUEST_COMPLETE") then |
||
106 | -- quest skompletowany, zakończony |
||
107 | if (AS_OnDebug) then |
||
108 | DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Zdarzenie: QUEST_COMPLETE"); |
||
109 | end |
||
110 | if (AutoSave_PC["check5"]=="on") then |
||
111 | AutoSave_PutSave=true; |
||
112 | end |
||
113 | end |
||
114 | if (event=="CHAT_MSG_SYSTEM") then |
||
115 | -- zabezpieczenie: podczas AFK - licznik zegara stoi |
||
116 | if (arg1==AS_Messages.AFK_on) then |
||
117 | AutoSave_AFKtime=true; |
||
118 | AutoSave_PutSave=false; |
||
119 | end |
||
120 | if (arg1==AS_Messages.AFK_off) then |
||
121 | AutoSave_AFKtime=false; |
||
122 | AutoSave_PutSave=false; |
||
123 | AutoSave_LastTime=GetTime(); |
||
124 | end |
||
125 | end |
||
126 | end |
||
127 | if ((AutoSave_PutSave) and (not AutoSave_InCombat) and (not AutoSave_AFKtime)) then |
||
128 | -- trzeba zapisać |
||
129 | if (AutoSave_LastTime+AutoSave_MinimPeriod<GetTime()) then |
||
130 | -- zachowany jest bezpieczny okres zapisu |
||
131 | AutoSave_PutSave=false; |
||
132 | SendChatMessage(".save", "SAY", nil); |
||
133 | AutoSave_LastTime=GetTime(); |
||
134 | if (AutoSave_PC["check2"]=="on") then |
||
135 | -- jest pozwolenie na komunikat |
||
136 | if (DEFAULT_CHAT_FRAME) then |
||
137 | DEFAULT_CHAT_FRAME:AddMessage("|cffffff00"..AS_Messages.saved); |
||
138 | else |
||
139 | UIErrorsFrame:AddMessage(AS_Messages.saved, 1.0, 1.0, 1.0, 1.0, UIERRORS_HOLD_TIME); |
||
140 | end |
||
141 | end |
||
142 | end |
||
143 | end |
||
144 | end |
||
145 | |||
146 | |||
147 | function AS_CheckVars() |
||
148 | if (not AutoSave_PC) then |
||
149 | AutoSave_PC = {}; |
||
150 | end |
||
151 | -- zainicjuj przelaczniki |
||
152 | if (not AutoSave_PC["okres"] ) then |
||
153 | AutoSave_PC["okres"] = "400"; |
||
154 | end |
||
155 | if (not AutoSave_PC["check1"] ) then |
||
156 | AutoSave_PC["check1"] = "on"; |
||
157 | end |
||
158 | if (not AutoSave_PC["check2"] ) then |
||
159 | AutoSave_PC["check2"] = "off"; |
||
160 | end |
||
161 | if (not AutoSave_PC["check3"] ) then |
||
162 | AutoSave_PC["check3"] = "off"; |
||
163 | end |
||
164 | if (not AutoSave_PC["check4"] ) then |
||
165 | AutoSave_PC["check4"] = "off"; |
||
166 | end |
||
167 | if (not AutoSave_PC["check5"] ) then |
||
168 | AutoSave_PC["check5"] = "off"; |
||
169 | end |
||
170 | -- Ustaw przelaczniki wg. zapisanych zmiennych |
||
171 | if (AutoSave_PC["check1"] == "on") then |
||
172 | AS_CheckButton1:SetChecked(1); |
||
173 | else |
||
174 | AS_CheckButton1:SetChecked(0); |
||
175 | end |
||
176 | if (AutoSave_PC["check2"] == "on") then |
||
177 | AS_CheckButton2:SetChecked(1); |
||
178 | else |
||
179 | AS_CheckButton2:SetChecked(0); |
||
180 | end |
||
181 | if (AutoSave_PC["check3"] == "on") then |
||
182 | AS_CheckButton3:SetChecked(1); |
||
183 | else |
||
184 | AS_CheckButton3:SetChecked(0); |
||
185 | end |
||
186 | if (AutoSave_PC["check4"] == "on") then |
||
187 | AS_CheckButton4:SetChecked(1); |
||
188 | else |
||
189 | AS_CheckButton4:SetChecked(0); |
||
190 | end |
||
191 | if (AutoSave_PC["check5"] == "on") then |
||
192 | AS_CheckButton5:SetChecked(1); |
||
193 | else |
||
194 | AS_CheckButton5:SetChecked(0); |
||
195 | end |
||
196 | end |
||
197 | |||
198 | |||
199 | function AS_OnShow() |
||
200 | AS_CheckLabel1:SetText(AS_Messages.active); |
||
201 | AS_CheckLabel2:SetText(AS_Messages.confirme); |
||
202 | AS_CheckLabel3:SetText(AS_Messages.combat); |
||
203 | AS_CheckLabel4:SetText(AS_Messages.skill); |
||
204 | AS_CheckLabel5:SetText(AS_Messages.quest); |
||
205 | AS_PeriodLabel:SetText(AS_Messages.period); |
||
206 | AS_Button1:SetText(AS_Messages.close); |
||
207 | AS_EditBox1:SetText(AutoSave_PC["okres"]); |
||
208 | if (AS_OnDebug) then |
||
209 | AS_Button1:SetText(tonumber(GetTime())); |
||
210 | end |
||
211 | AutoSaveForm:Show(); |
||
212 | end |
||
213 | |||
214 | |||
215 | function AS_OnMouseDown() |
||
216 | if (arg1 == "LeftButton") then |
||
217 | this:StartMoving(); |
||
218 | end |
||
219 | end |
||
220 | |||
221 | |||
222 | function AS_OnMouseUp() |
||
223 | if (arg1 == "LeftButton") then |
||
224 | this:StopMovingOrSizing(); |
||
225 | end |
||
226 | end |
||
227 | |||
228 | |||
229 | function AS_CheckButton_OnClick(par1) |
||
230 | if (AutoSave_PC[par1] == "off") then |
||
231 | AutoSave_PC[par1] = "on"; |
||
232 | else |
||
233 | AutoSave_PC[par1] = "off"; |
||
234 | end |
||
235 | end |
||
236 | |||
237 | |||
238 | function AS_EditBox1_OnEnterPressed() |
||
239 | local zm1=AS_EditBox1:GetText(); |
||
240 | if ((zm1==nil) or (zm1=="")) then |
||
241 | zm1="0"; |
||
242 | end |
||
243 | if (tonumber(zm1)<AutoSave_MinimPeriod) then |
||
244 | AS_EditBox1:SetText(tostring(AutoSave_MinimPeriod)); |
||
245 | else |
||
246 | AutoSave_PC["okres"]=zm1; |
||
247 | end |
||
248 | end |
||
249 | |||
250 | |||
251 | function AS_Button1_OnClick() |
||
252 | AS_EditBox1_OnEnterPressed(); |
||
253 | AutoSaveForm:Hide(); |
||
254 | end |