· 8 years ago · Mar 08, 2018, 10:38 PM
1
2<?xml version="1.0" encoding="iso-8859-1"?>
3<!DOCTYPE muclient>
4<!-- Saved on dimanche, mars 04, 2018, 10:01 -->
5<!-- MuClient version 5.06-pre -->
6
7<!-- Plugin "Testit" generated by Plugin Wizard -->
8
9<muclient>
10<plugin
11 name="Testit"
12 id="acb4277943a45b208163d8f5"
13 language="Lua"
14 date_written="2018-03-04 21:59:53"
15 requires="5.06"
16 version="1.0"
17 >
18
19</plugin>
20
21
22<!-- Get our standard constants -->
23
24<include name="constants.lua"/>
25
26<!-- Script -->
27
28
29<script>
30<![CDATA[
31require "tprint"
32require "gmcphelper" -- adds the gmcp() function for simplifying data access
33require "wait" -- for waiting for inventory lines
34
35DatabaseOpen ("db", GetInfo (66) .. "RoomsMobsDB.sqlite", 6)
36
37rc = DatabaseExec ("db", [[
38-- DROP TABLE IF EXISTS RoomsMobs;
39 CREATE TABLE IF NOT EXISTS RoomsMobs (
40 RoomsMobs_id INTEGER NOT NULL PRIMARY KEY autoincrement NOT NULL,
41 Room_uid TEXT NOT NULL,
42 Mob_desc TEXT NOT NULL,
43 Mob_con TEXT NOT NULL,
44 RM_DateTime DATETIME NOT NULL DEFAULT (DATETIME ('now', 'localtime'))
45 );
46]])
47
48DatabaseExec ("db",
49[[
50 INSERT INTO RoomsMobs ( Room_uid, Mob_desc, Mob_con ) VALUES (000,'zero', 'grosminet');
51]])
52
53
54-- prepare a query
55DatabasePrepare ("db", "SELECT * from RoomsMobs ORDER BY Mob_desc")
56
57-- find the column names
58names = DatabaseColumnNames ("db")
59tprint (names)
60
61-- execute to get the first row
62rc = DatabaseStep ("db") -- read first row
63
64-- now loop, displaying each row, and getting the next one
65
66print ("")
67values = DatabaseColumnValues ("db")
68tprint (values)
69-- finished with the statement
70DatabaseFinalize ("db")
71
72DatabaseClose ("db") -- close it
73
74incr=0
75
76
77
78function fixsql (s)
79
80 if s then
81 return "'" .. (string.gsub (s, "'", "''")) .. "'" -- replace single quotes with two lots of single quotes
82 else
83 return "NULL"
84 end -- if
85end -- fixsql
86
87function fixbool (b)
88 if b then
89 return 1
90 else
91 return 0
92 end -- if
93end -- fixbool
94
95
96
97
98
99local MUSHclient_Database_Errors = {
100 [-1] = "Database id not found",
101 [-2] = "Database not open",
102 [-3] = "Already have prepared statement",
103 [-4] = "Do not have prepared statement",
104 [-5] = "Do not have a valid row",
105 [-6] = "Database already exists under a different disk name",
106 [-7] = "Column number out of range",
107 } -- end of MUSHclient_Database_Errors
108
109-- check for errors on a DatabaseXXXXX call
110function dbcheck (code)
111 if code == sqlite3.OK or -- no error
112 code == sqlite3.ROW or -- completed OK with another row of data
113 code == sqlite3.DONE then -- completed OK, no more rows
114 return code
115 end -- if code OK
116
117 -- DatabaseError won't return the negative errors
118 local err = MUSHclient_Database_Errors [code] or DatabaseError("db")
119 DatabaseExec ("db", "ROLLBACK") -- rollback any transaction to unlock the database
120 error (err, 2) -- show error in caller's context
121end -- dbcheck
122
123function OnPluginBroadcast(msg, id, name, text)
124 if id == "3e7dedbe37e44942dd46d264" then -- message from the GMCP Handler
125 if (text == "room.info") then -- the GMCP Handler plugin says "I got a new room.info!"
126 print("id v 0.12")
127 print(id)
128 print("text")
129 print(text)
130 roominfo = gmcp("room.info")
131 roomnum= roominfo.num
132 print(roomnum)
133
134 wait.make (function () -- coroutine starts here
135
136-- request scan
137
138Send "scan"
139
140-- wait for scan to start
141
142local x = wait.match ("Right here you see:", 10)
143
144if not x then
145 ColourNote ("white", "blue", "No scan received within 10 seconds")
146 return
147end -- if
148
149-- loop until end of inventory
150
151while true do
152 local line, wildcards, styles = wait.match ("*")
153
154 print("line")
155 print(line)
156 print("wildcards")
157 print(wildcards)
158 print("styles")
159 print(styles)
160 -- see if end of scan
161
162 if not string.match (line, " - ") then
163 break
164 end -- if
165
166 -- save scan line
167 table.insert (scant, styles)
168
169end -- while loop
170end) -- end of coroutine
171
172
173
174
175
176
177
178 -- put some data into the database
179 DatabaseOpen ("db", GetInfo (66) .. "RoomsMobsDB.sqlite", 6)
180 dbcheck( DatabaseExec ("db",
181 [[INSERT INTO RoomsMobs ( Room_uid, Mob_desc, Mob_con ) VALUES (]] .. roomnum .. [[,'Tech tip', 'U mob');]])
182 )
183 DatabaseFinalize ("db")
184 DatabaseClose ("db")
185 end
186 end
187end
188
189
190
191function OnPluginInstall()
192 print("You've installed the Room Mob plugin.")
193end
194
195
196
197
198]]>
199</script>
200
201
202</muclient>