Bonus Points
The script is done. But we made some nice functions in this project that i think i will use over and over. And as such i dont want to include them in my script and clutter it up. So im going to cut out the functions into my first main sub library that i can call from every script i write.
So imgoing to create 2 files
MyLibrary.lua and ItemMover.lua
In ItemMover.lua im going to reference mylibrary.lua like so
dofile('MyLibrary.lua')
Contents of MyLibrary.lua
-------------------------------------------------------
-- Functions (subs) - Ive ripped from others per credits
-------------------------------------------------------
function msgbox(default, prompt, title, button, icon)
-- Function By Traegon's, Link: http://www.easyuo.com/forum/viewtopic.php?p=376784#376784
if icon == nil then icon = 2 end
if default == true then default = 1 else default = 0 end
ConfirmDialog = Obj.Create("TMessageBox")
ConfirmDialog.Title = title
ConfirmDialog.Button = button
ConfirmDialog.Icon = icon
ConfirmDialog.Default = default
return ConfirmDialog.Show(prompt)
end
function ENs_GetItemTypeFromItemID(nItemID)
local nThisType = nil
local nCnt = UO.ScanItems(true) -- visible only
local nIndex = 0
while nIndex < nCnt and nThisType == nil do
local nID,nType,nKind,nContID,nX,nY,nZ,nStack,nRep,nCol = UO.GetItem(nIndex)
if nID == nItemID then nThisType = nType end
nIndex = nIndex + 1
end
return nThisType
end
function ENs_MoveItemsFromTo(nFromBag, nToBag, nItemType) -- pass nitemtype -1 if not by type
local nMoved = 0
for nIndex = 0 , UO.ScanItems(true)-1 do
local nID,nType,nKind,nContID,nX,nY,nZ,nStack,nRep,nCol = UO.GetItem(nIndex)
if nContID == nFromBag then
if ( nItemType ~= -1 and nType == nItemType ) or nItemType == -1 then
nMoved = nMoved + ENs_MoveItemToContainor(nID , nToBag ) end
end
end
return nMoved
end
function ENs_MoveItemToContainor(nID , nContID)
UO.Drag(nID)
wait(600)
UO.DropC(nContID)
wait(600)
return 1
end
-----------------------------
-- My Defined Functions (subs)
-----------------------------
function MessageBox(sPrompt, sTitle, sType)
if sType == 'OK' then return msgbox(true, sPrompt, sTitle, 0,4) end
if sType == 'YESNO' then return msgbox(true, sPrompt, sTitle, 4,3) end
end
function TargetOpenBag(sMessage)
UO.LTargetKind = 1 -- object
MessageBox(sMessage, 'Bag Selection:', 'OK' )
UO.TargCurs = true -- make a target cursor
while UO.TargCurs == true do wait(10) end -- wait until something is clicked (ie notarget cursor)
UO.LObjectID = UO.LTargetID -- set last object to the object clicked
UO.Macro(17,0) -- openbag ( invoke macro use last object which hopefully is a bag inwhich case opens bag )
return UO.LTargetID -- set the return value .. the bagid clicked
end
Contents of ItemMover.lua
-----------------------------
--Load Code Librarys
-----------------------------
dofile('MyLibrary.lua')
-----------------------------
-- Script Starts Below
-----------------------------
repeat
local nSourceBag = TargetOpenBag('Please Target The Source Bag:') -- step 1
local nDestinationBag = TargetOpenBag('Please Target The Destination Bag:') -- step 2
local nResult = MessageBox('Move Items By ItemType ?','Item Type', 'YESNO')
local nItemTypeToMove = -1 -- not by type
if nResult == 6 then
MessageBox('Select Item Type','Item Type', 'OK')
UO.TargCurs = true
while UO.TargCurs == true do wait(10) end
nItemTypeToMove = ENs_GetItemTypeFromItemID(UO.LTargetID)
end
local nItemsMoved = ENs_MoveItemsFromTo(nSourceBag, nDestinationBag, nItemTypeToMove) -- if nItemTypeToMove = -1 it moves all items in souce bag
local nResult = MessageBox('Moved '..nItemsMoved..' items. Move more Items ?','Move Item', 'YESNO')
until nResult == 7 -- no
EDITED: To fix 2 capitilation typos