I think its working for the most of it. feedback is welcome
set razor not to filter repeated messages and change the container variable to your own value.
You may tweak some wait commands to improve efficiency just be careful with your latency
Code:
-- Change this to the ID of container in your bank where you would like
-- your ingots to be placed.
ingotContainer=1082676472
ingotType=7151
toolTypes=3718
status="idle"
bankType=1074118237
idle="idle"
print("Starting OzMining 1.0 moded by Morwen")
status ="idle"
os=""
ref=0
function MineThisSpot(status)
if ( status ~= "idle" ) then
return status
end
local cnt=0
for i=1,UO.ScanItems(true) do
nID,type= UO.GetItem(i)
if type==3718 then
cnt=cnt+1
break
end
end
if cnt > 0 then
UO.LObjectID=nID
UO.Macro(17,0)
local oldX=UO.CharPosX
local oldY=UO.CharPosY
local oldZ=UO.CharPosZ
UO.TileInit (true)
local nType,nZ,sName,nFlags=UO.TileGet(oldX,oldY,2)
UO.LTargetTile=nType
UO.LTargetX=oldX
UO.LTargetY=oldY
UO.LTargetZ=oldZ
UO.LTargetKind=3
--target 10s
wait(200)
UO.Macro(22,0)
wait(400)
UO.Macro(22,0)
wait(800)
UO.Macro(22,0)
status="mining"
end
return status
end
function scanJournalFor(refArg,str)
nRef, nCnt = UO.ScanJournal(refArg)
for ji=nCnt-1,0,-1 do
text,colour=UO.GetJournal(ji)
if string.find(text,str) then
print(ji)
ref=nRef
return true
end
end
return false
end
function ProcessResults(status,jrnl)
while status == "mining" do
if scanJournalFor(ref,"dig some") then
print("You dug something")
status="idle"
end
if scanJournalFor(ref,"loosen some rocks") then
print("FAIL LOL")
status="idle"
end
if scanJournalFor(ref,"too far") then
print("Stupid biatx")
status="idle"
end
if scanJournalFor(ref,"Someone has gotten") then
print("huh?")
status="idle"
end
if scanJournalFor(ref,"target cannot be seen") then
print("stupid blind ****er")
status="no_more_ore"
--MoveToNextSpot()
end
if scanJournalFor(ref,"is no metal here to mine") then
print("Resource depleeted")
status="no_more_ore"
end
if scanJournalFor(ref,"can't mine that") then
print("You can only mine rocks... you know like... rocks")
status="no_more_ore"
--MoveToNextSpot()
end
if scanJournalFor(ref,"save complete.") then
print("God save us from Eru")
status="no_more_ore"
end
if scanJournalFor(ref,"that is too far away") then
print("You are not so big now!")
status="no_more_ore"
end
if scanJournalFor(ref,"for validating your presence") then
UO.Msg("Dont forget to VOTE\n")
status="no_more_ore"
end
if scanJournalFor(ref,"stand closer") then
print("Its ingot melting time!!!")
status="idle"
GoSmelt()
end
if status~=os then
os=status
print("new status "..status)
end
end
return status
end
function MoveToNextSpot()
print("Finding next mining spot\n")
--FindNextSpot:
local oldX=UO.CharPosX
local oldY=UO.CharPosY
local randomInc=math.random(-5,5)
local newX=oldX + randomInc
randomInc = math.random(-5,5)
local newY=oldY + randomInc
print("Checking tile data")
UO.TileInit (true)
nType,nZ,sName,nFlags=UO.TileGet(newX,newY,2)
while sName~="cave floor" do
print("tile wasn't in a cave.")
print("Checking another tile to go.")
math.random()
randomInc = math.random(-5,5)
newX=oldX + randomInc
randomInc = math.random(-5,5)
newY=oldY + randomInc
print("X:"..newX.." Y:"..newY)
nType,nZ,sName,nFlags=UO.TileGet(newX,newY,2)
end
print("Going to "..newX.."-"..newY)
UO.Pathfind(newX,newY)
local countTry=0
while UO.CharPosX~=newX and UO.CharPosY~=newY do
wait(2000)
UO.Pathfind(newX,newY)
if countTry==15 then
break
else
countTry=countTry+1
end
end
status="idle"
end
function GoToForge()
local x=UO.CharPosX
local y=UO.CharPosY
local CountOres=0
for i=1,UO.ScanItems(true) do
local id,type = UO.GetItem(i)
if type==6585 then
CountOres=CountOres+1
end
end
if(CountOres>0) then
local minD=99999999
local currD=-1
local idx=-1
local forgeXs={2568,2569,2575,2576,2568,2569,2570,2571,2572,2573,
2574,2575,2576,2577,2568,2569,2570,2571,2572,2573,
2574,2575,2576,2577,2568,2569,2570,2571,2572,2573,
2574,2575,2576,2577,2572,2573,2574,2575,2576,2577,
2578,2572,2573,2577,2578,2572,2573,2578,2572,2573,
2577,2578,2572,2573,2574,2575,2576,2577,2578,2572,
2573,2574,2575,2576,2577,2578,2572,2573,2574,2575,
2576,2577,2578,2581,2581,2581,2581,2581,2581,2581,
2582,2582,2582,2582,2582,2582,2582,2582,2583,2583,
2583,2583,2583,2583,2583}
local forgeYs={474,474,474,474,475,475,475,475,475,475,475,475,475,
475,476,476,476,476,476,476,476,476,476,476,477,
477,477,477,477,477,477,477,477,477,486,486,486,
486,486,486,486,487,487,487,487,488,488,488,489,
489,489,489,490,490,490,490,490,490,490,491,491,
491,491,491,491,491,492,492,492,492,492,492,492,
490,491,492,493,494,496,497,490,491,492,493,494,
495,496,497,490,491,492,493,494,495,496}
for i=1,95 do
--calc min distance
currD=math.sqrt(math.pow(x-forgeXs[i],2)+math.pow(y-forgeYs[i],2))
if(currD<minD) then
minD=currD
idx=i
end
end
UO.Pathfind(forgeXs[idx],forgeYs[idx])
local newX=forgeXs[idx]
local newY=forgeYs[idx]
while UO.CharPosX~=newX and UO.CharPosY~=newY do
wait(5000)
UO.Pathfind(newX,newY)
end
while UO.CharPosX ~= newX and UO.CharPosY ~= newY do
wait(1000)
end
print("Reached forge")
wait(1000)
--Melt ores
for i=1,UO.ScanItems(true) do
local id,type = UO.GetItem(i)
if type==6585 then
UO.LObjectID=id
UO.Macro(17,0)
print("Smelts ore")
wait(200)
end
end
else
print("No Ores to Smelt")
end
end
function GoSmelt()
--TODO Find nearest forge from a list of forges
-- saves current position and go to forge
-- Once there smelt all the ores and
-- go back
local oldX=UO.CharPosX
local oldY=UO.CharPosY
--SmeltOre:
-- set %oldX #charposX
-- set %oldY #charposY
GoToForge()
if UO.Weight > UO.MaxWeight-10 then
bankOre()
end
UO.Pathfind(oldX,oldY);
while UO.CharPosX~=oldX and UO.CharPosY~=oldY do
wait(2000)
UO.Pathfind(oldX,oldY)
end
while UO.CharPosX ~= oldX and UO.CharPosY ~= oldY do
wait(1000)
end
end
function bankOre()
local oldX=UO.CharPosX
local oldY=UO.CharPosY
local countIng =0
for i=1,UO.ScanItems(true) do
local nID,nType,nKind, nContID, nX, nY, nZ, nStack, nRep, nCol = UO.GetItem(i)
if nType==7151 then--ingotType then
countIng=countIng+1
end
end
if(countIng>0) then
print("Going to bank ingots...")
UO.Pathfind(2569,488);
while UO.CharPosX~=2569 and UO.CharPosY~=488 do
wait(4000)
UO.Pathfind(2569,488);
end
UO.Pathfind(2563,503);
while UO.CharPosX~=2563 and UO.CharPosY~=503 do
wait(4000)
UO.Pathfind(2563,503);
end
UO.Pathfind(2561,510);
while UO.CharPosX~=2561 and UO.CharPosY~=510 do
wait(4000)
UO.Pathfind(2561,510);
end
print("Reached banking spot")
wait(500)
UO.LObjectID=bankType
UO.Macro(17,0)
wait(2000)
print("Opened bankbox")
for i=1,UO.ScanItems(true) do
local nID,nType,nKind, nContID, nX, nY, nZ, nStack, nRep, nCol = UO.GetItem(i)
if nType==ingotType then
wait(200)
UO.Drag(nID,nStack)
wait(400)
UO.DropC(ingotContainer)
wait(800)
end
end
print("Going back...")
UO.Pathfind(2569,488);
while UO.CharPosX~=2569 and UO.CharPosY~=489 do
wait(5000)
UO.Pathfind(2569,488);
end
while UO.CharPosX~=2569 and UO.CharPosY~=489 do
wait(1000)
end
UO.Pathfind(oldX,oldY);
while UO.CharPosX~=oldX and UO.CharPosY~=oldY do
wait(5000)
UO.Pathfind(oldX,oldY)
end
while UO.CharPosX ~= oldX and UO.CharPosY ~= oldY do
wait(1000)
end
end
end
function Main()
local status="idle"
while UO.Hits > 0 do
if ( UO.Weight > UO.MaxWeight ) then
print("gosmelt")
GoSmelt()
end
if status == "no_more_ore" then
print("move next")
status= "idle"
MoveToNextSpot()
end
if ( UO.Weight > UO.MaxWeight ) then
print("gosmelt")
GoSmelt()
end
local nNewRef = UO.ScanJournal(0)
status=MineThisSpot(status)
status=ProcessResults(status,nNewRef)
end
end
Main() --Run biatx