· 9 years ago · Dec 06, 2016, 02:06 AM
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE muclient>
3
4<muclient>
5<plugin
6 name="Hadar_potion_Tracker"
7 author="Hadar"
8 id="8b614de57c14606ab6f4d4f6"
9 language="Lua"
10 purpose="Track potions display to window, with autoquaffing"
11 date_written="2016-11-30"
12 requires="4.98"
13 version="1.0"
14 save_state="y"
15 >
16<description trim="y">
17<![CDATA[
18
19I liked abelinc/lunks version so i kept the qff alias - rest of code is mine
20
21Install this plugin to automatically quaff a potion when your health falls
22below a preset limit.
23
24aqff ---> Displays the current values of variables
25
26aqff bag * ---> Sets the container to get potions from to *
27
28aqff hp pot * ---> Sets hp potion to *
29
30aqff mn pot * ---> Sets mn potion to *
31
32aqff mv pot * ---> Sets mv potion to *
33
34aqff hp per * ---> Sets the HP percent you must fall below to quaff to *
35
36aqff mn per * ---> Sets the MN percent you must fall below to quaff to *
37
38aqff mv per * ---> Sets what MV percent you must fall below to quaff to *
39
40aqff on/off ---> Turns the actions of the plugin on or off
41
42aqff add hp pot ---> Add a heal pot to the database
43
44aqff add mn pot ---> Add a mana pot to the database
45
46aqff add mv pot ---> Add a move pot to the database
47
48]]>
49</description>
50
51</plugin>
52
53<include name="constants.lua"/>
54
55<triggers>
56 <trigger
57 enabled="y"
58 match="^Auction: (.*) is auctioning (.*) \(Level .*, Num .*\)\. Current bid is .*\.$"
59 regexp="y"
60 send_to="12"
61 script="addpot"
62 sequence="100"
63 >
64 </trigger>
65 <trigger
66 enabled="y"
67 match="^Auction: (.*) SOLD to (.*) for .* gold\.$"
68 regexp="y"
69 send_to="12"
70 script="potionaddsingle"
71 sequence="100"
72 >
73 </trigger>
74 <trigger
75 enabled="y"
76 match="^You buy (\d+) \* (.*) from .* for ([+-]?[0-9,]+) gold\.$"
77 regexp="y"
78 send_to="12"
79 script="potionaddmultiple"
80 sequence="99"
81 >
82 </trigger>
83 <trigger
84 enabled="y"
85 match="^You buy (.*) from .* for ([+-]?[0-9,]+) gold\."
86 regexp="y"
87 send_to="12"
88 script="potionaddsingle"
89 sequence="100"
90 >
91 </trigger>
92 <trigger
93 enabled="y"
94 match="^You drop (\d+) \* (.*)\.$"
95 regexp="y"
96 send_to="12"
97 script="losepotionmultiple"
98 sequence="99"
99 >
100 </trigger>
101 <trigger
102 enabled="y"
103 match="^You drop (.*)\.$"
104 regexp="y"
105 send_to="12"
106 script="losepotionsingle"
107 sequence="100"
108 >
109 </trigger>
110 <trigger
111 enabled="y"
112 match="^You eat (.*)\.$"
113 regexp="y"
114 send_to="12"
115 script="potionQuaff"
116 sequence="100"
117 >
118 </trigger>
119 <trigger
120 enabled="y"
121 match="^You get (\d+) \* (.*)\.$"
122 regexp="y"
123 send_to="12"
124 script="potionaddmultiple"
125 sequence="99"
126 >
127 </trigger>
128 <trigger
129 enabled="y"
130 match="^You get (.*)\.$"
131 regexp="y"
132 send_to="12"
133 script="potionaddsingle"
134 sequence="100"
135 >
136 </trigger>
137 <trigger
138 enabled="y"
139 match="^You give (\d+) \* (.*) to .*\.$"
140 regexp="y"
141 send_to="12"
142 script="losepotionmultiple"
143 sequence="99"
144 >
145 </trigger>
146 <trigger
147 enabled="y"
148 match="^You give (.*) to .*\.$"
149 regexp="y"
150 send_to="12"
151 script="losepotionsingle"
152 sequence="100"
153 >
154 </trigger>
155 <trigger
156 enabled="y"
157 match="^You quaff (.*)\.$"
158 regexp="y"
159 send_to="12"
160 script="potionQuaff"
161 sequence="100"
162 >
163 </trigger>
164 <trigger
165 enabled="y"
166 match="^You receive (\d+) \* (.*) from .*\.$"
167 regexp="y"
168 send_to="12"
169 script="potionaddmultiple"
170 sequence="99"
171 >
172 </trigger>
173 <trigger
174 enabled="y"
175 match="^You receive (.*) from .*\.$"
176 regexp="y"
177 send_to="12"
178 script="potionaddsingle"
179 sequence="100"
180 >
181 </trigger>
182 <trigger
183 enabled="y"
184 match="^You recite (.*)\.$"
185 regexp="y"
186 send_to="12"
187 script="potionQuaff"
188 sequence="100"
189 >
190 </trigger>
191 <trigger
192 enabled="y"
193 match="^You sell (\d+) \* (.*) to .* for .* gold\.$"
194 regexp="y"
195 send_to="12"
196 script="losepotionmultiple"
197 sequence="99"
198 >
199 </trigger>
200 <trigger
201 enabled="y"
202 match="^You sell (.*) to .* for .* gold\.$"
203 regexp="y"
204 send_to="12"
205 script="losepotionsingle"
206 sequence="100"
207 >
208 </trigger>
209 <trigger
210 enabled="y"
211 match="^\((?: )?(\d+)\) (?:\(M\))(?:\(G\))?(?:\(H\))? (.*) \(\d+\)$"
212 regexp="y"
213 send_to="12"
214 script="addpot"
215 sequence="100"
216 >
217 </trigger>
218</triggers>
219
220<aliases>
221
222 <alias
223 name="autoquaff"
224 script="qff_settings"
225 match="^aqff ?(hp per|mn per|mv per|hp pot|mn pot|mv pot|bag|on|off|help|debug|add mv pot|add hp pot|add mn pot)?( [a-z0-9]+)?"
226 enabled="y"
227 regexp="y"
228 ignore_case="y"
229 sequence="100"
230 >
231 </alias>
232
233 <alias
234 match="^MajorHadarTest$"
235 regexp="y"
236 enabled="y"
237 echo_alias="n"
238 send_to="12"
239 sequence="95">
240 <send>
241 print(countDatabase())
242 show_potwin()
243 </send>
244 </alias>
245
246</aliases>
247
248<script>
249<![CDATA[
250dofile (GetPluginInfo (GetPluginID (), 20) .. "luapath.lua")
251
252require "checkplugin"
253require "serialize"
254require "gmcphelper"
255require "HadarLuaCommon"
256
257databasename = GetPluginInfo(GetPluginID (), 20) .. "HadarPotions.db"
258db = "Potions"
259
260
261--[[ +-------------------------------------------------------+
262 | Initilization stuff |
263 +-------------------------------------------------------+ ]]
264
265function OnPluginInstall ()
266 phelper:OnPluginInstall()
267 if GetVariable ("enabled") == "false" then
268 ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
269 check (EnablePlugin(GetPluginID (), false))
270 return
271 end -- they didn't enable us last time
272
273 prepareDatabase()
274 OnPluginEnable ()
275 show_potwin()
276end -- endinstall
277
278function OnPluginEnable ()
279 phelper:OnPluginEnable()
280end -- endenable
281
282function OnPluginSaveState ()
283 phelper:OnPluginSaveState()
284--nothing to save
285end --end save state
286
287
288
289--[[ +-------------------------------------------------------+
290 | MMMM MiniWindow Stuff |
291 +-------------------------------------------------------+ ]]
292require 'miniwin'
293require 'pluginhelper'
294potwin = Miniwin:new{name="HP"}
295potwin:set_default('windowpos', 1) -- if it breaks this used to be 7
296potwin:add_setting("purpleIThink", {help="the colour for the time", type="colour", default=verify_colour(0xD670DA), sortlev=1})
297potwin:add_setting("darkGreen", {help="the colour for when a mob is not in kill table db", type="colour", default=verify_colour("green"), sortlev=1})
298showpotwin = false
299function set_show()
300 showpotwin = true
301end
302
303function show_potwin ()
304
305 local texttable = {}
306 local header = {}
307 local style = {}
308
309 style = {}
310 style.text = "Potions: "
311 table.insert (header, {style})
312 words = {}
313 for word in countDatabase():gmatch("%S+") do table.insert(words, word) end
314 for i, v in pairs (words) do
315 print(v)
316 style = {}
317
318 style.text = v
319
320 style.textcolour = "darkGreen"
321 -- if v[2] == "???" then
322 -- style.textcolour = "mobdead_colour"
323 -- end
324 table.insert (texttable, {style})
325
326 end -- for
327
328
329
330 potwin:enable()
331 potwin:addtab('default', texttable, header, true)
332
333 potwin:show(true)
334
335
336 potwin:changetotab('default')
337
338 style = {}
339 style.text = " Pots: "
340 potwin:tabbroadcast(true, {style})
341
342end
343function OnPluginClose()
344
345 phelper:OnPluginClose()
346end -- OnPluginClose
347
348
349function OnPluginDisable ()
350
351 phelper:OnPluginDisable()
352end -- OnPluginDisable
353
354function OnPluginConnect ()
355
356 phelper:OnPluginConnect()
357end -- OnPluginConnect
358
359function OnPluginDisconnect ()
360
361 phelper:OnPluginDisconnect()
362end -- function OnPluginConnect
363
364phelper:set_default('cmd', 'mcp')
365phelper:set_default('plugin_colour', 'steelblue')
366
367phelper:add_pobject('win', potwin)
368
369phelper:enable()
370
371--[[ +-------------------------------------------------------+
372 | MMMM Actual Potion Stuff |
373 +-------------------------------------------------------+ ]]
374
375local _,pname = CallPlugin("3e7dedbe37e44942dd46d264","gmcpval","char.base.name")
376
377function OnPluginBroadcast(msg, id, name, text)
378 if id == "3e7dedbe37e44942dd46d264" then -- message from the GMCP Handler
379 if (text == "char.vitals") then
380 res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264","gmcpval","char")
381 luastmt = "gmcpdata = " .. gmcparg
382 assert (loadstring (luastmt or "")) ()
383 end --end text viatals
384 end -- end gmcp handler
385end --end pluginbroadcast
386
387function potionaddsingle(name, line, wildcards)
388
389 local item = lookupDatabase(wildcards[1])
390 local ammt = 1
391
392 if item == "heal" or item == "mana" or item == "move" then
393 AddToDatabase(item,ammt)
394 end
395
396end -- end potaddsingle
397
398
399function potionaddmultiple(name, line, wildcards)
400
401 local item = lookupDatabase(wildcards[2])
402 local ammt = wildcards[1]
403
404 if item == "heal" or item == "mana" or item == "move" then
405 AddToDatabase(item,ammt)
406 end
407
408end -- end potaddmultiple
409
410function losepotionsingle(name, line, wildcards)
411
412 local item = lookupDatabase(wildcards[1])
413 local ammt = 1
414
415 if item == "heal" or item == "mana" or item == "move" then
416 RemoveFromDatabase(item,1,"drop")
417 end
418
419end -- end losepotionsingle
420
421function losepotionmultiple(name, line, wildcards)
422
423 local item = lookupDatabase(wildcards[2])
424 local ammt = wildcards[1]
425
426 if item == "heal" or item == "mana" or item == "move" then
427 RemoveFromDatabase(item,ammt,"drop")
428 end
429
430end -- end losepotionmultiple
431
432function potionQuaff(name, line, wildcards)
433 local item = lookupDatabase(wildcards[1])
434 local ammt = 1
435 RemoveFromDatabase(item,1,"quaff")
436end
437
438function addpot()
439end -- addpot
440
441function delpot()
442end -- delpot
443
444function qff_settings (name, line, wildcards)
445 if wildcards [1] == "add mv pot" then
446 movepotion = utils.inputbox ("Copy/Paste name of move potion", "Add Potion", "nil", "Courier", 9)
447 if movepotion ~= nil then
448 putDatabase("move",movepotion)
449 end
450 elseif wildcards [1] == "add hp pot" then
451 healpotion = utils.inputbox ("Copy/Paste name of move potion", "Add Potion", "nil", "Courier", 9)
452 if movepotion ~= nil then
453 putDatabase("heal",healpotion)
454 end
455 elseif wildcards [1] == "add mn pot" then
456 manapotion = utils.inputbox ("Copy/Paste name of move potion", "Add Potion", "nil", "Courier", 9)
457 if manapotion ~= nil then
458 putDatabase("mana",manapotion)
459 end
460 end
461
462 --SaveState()
463end -- autoquaff_settings
464
465--[[ +-------------------------------------------------------+
466 | MMMM Database |
467 +-------------------------------------------------------+ ]]
468
469function lookupDatabase(name)
470 DatabaseOpen(db, databasename, 6)
471
472 local status = DatabasePrepare(db, "SELECT * FROM potions WHERE name='"..name.."'")
473
474 if status == 0 then
475 local cookie = DatabaseStep(db)
476 if cookie == 100 then
477 result = DatabaseColumnValues(db)[2]
478 elseif cookie == 101 then
479 result = false
480 end
481 end
482
483 DatabaseFinalize(db)
484 DatabaseClose(db)
485
486 return result;
487end
488
489function AddToDatabase(type,amt)
490
491 local math1
492
493 DatabaseOpen(db, databasename, 6)
494
495 local status = DatabasePrepare(db, "SELECT * FROM potionstats WHERE type='"..type.."'")
496 if status == 0 then
497 cycle = DatabaseStep(db)
498
499 while cycle == 100 do
500 math1 = DatabaseColumnValues(db)[2]
501 cycle = DatabaseStep(db)
502 end
503 end
504
505 math1=math1+amt
506 DatabaseFinalize(db)
507
508 local update = DatabaseExec(db, "UPDATE potionstats SET ammountLeft='"..math1.."' WHERE type = '"..type.."'")
509 DatabaseFinalize(db)
510 DatabaseClose(db)
511
512 Info (print(countDatabase()))
513end
514
515function RemoveFromDatabase(type,amt,action)
516
517 local math1
518 local math2
519 local math3
520
521 DatabaseOpen(db, databasename, 6)
522
523 local status = DatabasePrepare(db, "SELECT * FROM potionstats WHERE type='"..type.."'")
524 if status == 0 then
525 cycle = DatabaseStep(db)
526
527 while cycle == 100 do
528 math1 = DatabaseColumnValues(db)[2]
529 math2 = DatabaseColumnValues(db)[3]
530 math3 = DatabaseColumnValues(db)[4]
531 cycle = DatabaseStep(db)
532 end
533 end
534
535 math1=math1-amt
536 if action=="quaff" then
537 math2 = math2+1
538 math3 = math3+1
539 end
540 DatabaseFinalize(db)
541
542 local update = DatabaseExec(db, "UPDATE potionstats SET ammountLeft='"..math1.."', quaffed='"..math2.."', quaffedTotal='"..math3.."' WHERE type = '"..type.."'")
543
544 DatabaseFinalize(db)
545 DatabaseClose(db)
546
547 Info (print(countDatabase()))
548end
549
550function putDatabase(type,name)
551 DatabaseOpen(db, databasename, 6)
552 status = DatabaseExec(db, "INSERT INTO potions (type,name) VALUES ( '"..type.."', '"..name.."')")
553 DatabaseFinalize(db)
554 DatabaseClose(db)
555 ColourNote("Cyan","","We put ","Red","",name,"Cyan",""," into ","Red","",type)
556end
557
558function countDatabase()
559 DatabaseOpen(db, databasename, 6)
560 local status = DatabasePrepare(db, "SELECT * FROM potionstats")
561 potstats=nil
562
563 if status == 0 then
564 cycle = DatabaseStep(db)
565 while cycle == 100 do
566 if potstats==nil then
567 potstats = DatabaseColumnValues(db)[1]..":"..DatabaseColumnValues(db)[2]
568 else
569 potstats = potstats.." "..DatabaseColumnValues(db)[1]..":"..DatabaseColumnValues(db)[2]
570 end
571 cycle = DatabaseStep(db)
572 end
573 end
574
575 DatabaseFinalize(db)
576 DatabaseClose(db)
577
578 return potstats;
579end
580
581function prepareDatabase()
582 -- Create database if its not already present
583
584 DatabaseOpen(db, databasename, 6)
585
586 status = DatabaseExec(db, [[
587 CREATE TABLE IF NOT EXISTS potions(
588 ID INTEGER PRIMARY KEY AUTOINCREMENT,
589 type TEXT DEFAULT 'empty',
590 name TEXT DEFAULT 'empty',
591
592 unique(ID)
593 );
594
595 CREATE TABLE IF NOT EXISTS potionstats(
596 type TEXT PRIMARY KEY,
597 ammountLeft INTEGER DEFAULT 0,
598 quaffed INTEGER DEFAULT 0,
599 quaffedTotal INTEGER DEFAULT 0,
600
601 unique(type)
602 );
603
604 ]])
605
606
607 if status ~= 0 then
608 ColourNote("white", "red", centerText("Error creating potion database : " .. DatabaseError(db), 60))
609 end
610
611 DatabaseFinalize(db)
612 DatabaseClose(db)
613end
614
615]]>
616</script>
617
618</muclient>