-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities-0.1.3.lua
204 lines (185 loc) · 4.67 KB
/
utilities-0.1.3.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
--------------------------------------------------------------------------------
-- Utilities Libraries
--
-- Changelog:
-- 03/01/2012 Added FluentUO, and findBodBookWithName,
-- findTailorBods, findSmithBods, moveBodToBook
-- 03/04/2012 Changed the restartClient wait time from 10s to 20s
-- 0.1.1
-- 03/06/2012 Added getTargetItem
-- 0.1.2
-- 03/06/2012 Added dropBodFromBook, findBods, doubleClickObject
-- 0.1.3
--------------------------------------------------------------------------------
dofile("FluentUO.lua")
dofile("journal.lua")
-- Wait for particular gump for some time
function gumpAppeared(gumpName, delay)
if delay == nil then
delay = 30000
end
local timeout = getticks() + delay
repeat
if getticks() < timeout then
wait(50)
else
return false
end
until UO.ContName == gumpName
return true
end
-- Wait for particular gump for some time
function gumpAppearedWithId(gumpId, delay)
if delay == nil then
delay = 30000
end
local timeout = getticks() + delay
repeat
if getticks() < timeout then
wait(50)
else
return false
end
until UO.ContID == gumpId
return true
end
function currentTime()
local nHour, nMinute, nSecond = gettime()
local hh, mm, ss
if nHour < 10 then
hh = "0"..nHour
else
hh = nHour
end
if nMinute < 10 then
mm = "0"..nMinute
else
mm = nMinute
end
if nSecond < 10 then
ss = "0"..nSecond
else
ss = nSecond
end
return hh..":"..mm..":"..ss
end
function log(value)
if value == nil then
print(currentTime()..": nil")
else
print(currentTime()..": "..value)
end
end
function restartClient(msg)
if msg ~= nil then
log(msg)
end
local f = openfile("kill_them_all.txt", "w")
f:flush()
f:close()
wait(20000)
UO.CliNr=1
end
-- Find Bulk Order Book named with "name".
-- return item table from FluentUO lib.
function findBodBookWithName(name)
return Backpack().WithType(8793).WithProperty("Book Name").EqualTo(name).Items[1]
end
function findTailorBods()
return Backpack().WithType(8792).WithCol(1155).Items
end
function findSmithBods()
return Backpack().WithType(8792).WithCol(1102).Items
end
function findBods()
return Backpack().WithType(8792).Items
end
function moveBodToBook(bods, book)
if bods == nil or book == nil or #bods == 0 then
return
end
local bodtype
if bods[1].Col == 1155 then
bodtype = "tailor"
elseif bods[1].Col == 1102 then
bodtype = "smith"
end
log("Moving "..#bods.." "..bodtype.." bods to "..book.Property["Book Name"])
for i = 1, #bods do
UO.Drag(bods[i].ID)
wait(100)
UO.DropC(book.ID)
wait(1000)
gumpAppeared("generic gump")
end
end
function getTargetItem(delay)
UO.TargCurs = true
if delay == nil or delay == 0 then
delay = 30000
end
local timeout = getticks() + delay
repeat
if getticks() < timeout then
wait(50)
else
return nil
end
until UO.TargCurs == false
local item = World().WithID(UO.LTargetID).Items[1]
return item
end
function doubleClickObject(objectId)
local tmpId = UO.LObjectID
if objectId ~= nil then
UO.LObjectID = objectId
UO.Macro(17, 0)
end
UO.LObjectID = tmpId
end
-- Wait for the bod book open. Returns true if book is open, or false if the book
-- can not be open
function waitForBodBook(delay)
if delay == nil then
delay = 30000
end
local myJournal = journal.new()
local timeout = getticks() + delay
repeat
-- First, check jounal for empty book
local text = myJournal:next()
if text ~= nil and (text:match("The book is empty") ~= nil) then
-- the book is empty
return false
end
if getticks() < timeout then
wait(50)
else
return false
end
until UO.ContName == "generic gump"
return true
end
-- Open specified bod book until it is open or it is an empty book.
-- If it is an empty book, this will return false, otherwise true
function openBodBook(book)
-- First, open that backpack
UO.Macro(8, 7)
if gumpAppearedWithId(1086632648) then
-- Then, try openning the book
doubleClickObject(book.ID)
return waitForBodBook()
else
return false
end
end
-- Drop the first bod from the given bod book. Returns nil if book is empty
function dropBodFromBook(book)
if book == nil then
return nil
end
-- First, double click the book
doubleClickObject(book.ID)
if not gumpAppeared("generic gump", 15) then
end
end