Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------------------
- -- Script Name: AutoFish
- -- Author: MadMartyr
- -- Version: 1.7
- -- Client Tested with: 7.0.10.1
- -- Written with OpenEUO
- -- Shard OSI / FS: (OSI)
- -- Last Modified: 11/10/2010
- -- Description: Automatically fishes down the left side of the boat
- -- while monitoring for enemies. If one shows up, it
- -- whips out the bow you select and kills it. Once
- -- the enemy is dead, it will loot various items from
- -- its corpse.
- --------------------------------------------------
- -- Changelog:
- --
- -- 11/10/2010 - v 1.7
- -- 1. Added nil exception handilng to hold value acquisition
- -- 2. Added client selection.
- --
- -- 11/09/2010 - v 1.6
- -- 1. Added differentiation between MiBs and other bottles
- -- 2. Now correctly tosses out non-MiB bottles.
- -- 3. Now stows cut steaks if weight is above 80% while cutting.
- -- 4. Updated boat movement code to stop before changing direction.
- --
- -- 11/08/2010 - v1.5
- -- 1. Added routine to cut up fish
- -- 2. Added hold weight checking routine
- -- 3. Added dagger selection for fish cutting
- -- 4. Added stop if Hold is full, and no dagger selected
- --
- -- 11/04/2010 - v1.4
- -- 1. Added nets to loot and stow
- -- 2. All garbage is now tossed to random tiles
- -- 3. Boat movement on empty tile randomized
- -- 4. Added auto-dismount
- --
- -- 11/03/2010 - v1.3
- -- 1. Fixed trash tossing by increased area
- -- 2. Fixed journal scanning
- -- 3. Changed wording on Hold selection
- -- 4. Gave random start tile for trash tossing
- -- 5. Set trash tossing to skip the tile the character is occupying
- --
- -- 11/02/2010 - v1.2
- -- 1. Fixed Energy Bolt
- -- 2. Added Bandies
- -- 3. Various bug fixes
- -- 4. Heavy commenting
- --
- -- 11/01/2010 - v1.1
- -- 1. Added trash, storage, and item usage.
- -- 2. Combined trash, storage, and item usage.
- --
- function main()
- -- Our main function is where all the magic gets started.
- SelectClient()
- -- Boots
- intTrash = { 5899, 5900, 5901, 5902, 5903, 5904, 5905, 5906 }
- -- Fish types, White Pearls, and Gold to throw in the cargo hold.
- intStore = { 2426, 2427, 2508, 2509, 2510, 2511, 3530, 3821, 5355, 12694, 17154, 17155, 17158, 17159, 17603, 17604, 17605, 17606, 22330 }
- -- Items to use up (Mess of Fish)
- intUse = { 2463, 3542 }
- -- Loot to pull from the corpses of hostiles.
- intLoot = { 2463, 3530, 3821, 3903, 5355 }
- -- Find the fishing pole to use (automatic).
- intPole = FindPole()
- -- Let the user select a bow to use. If none, use Magery.
- intBow = FindBow()
- if intBow == 0 then
- UseMagery = true
- end
- -- Let the user select the Boat's hold.
- intHold = FindHold()
- if intHold == 0 then
- UO.ExMsg( UO.CharID, 3, 50, "Items will remain in pack." )
- end
- -- Let the user select dagger to use for cutting up the
- -- fish in the hold if it gets full.
- intDagger = FindDagger()
- if intDagger == 0 then
- UO.ExMsg( UO.CharID, 3, 50, "Fish will not be cut." )
- end
- -- Start with a clean pack, and no visible corpses.
- CheckWeightAndCut()
- TossStoreAndUse()
- DoLoot()
- -- Make sure we have a fishing pole ID.
- if intPole == 0 then
- UO.ExMsg( UO.CharID, 3, 50, "Fishing Pole Not Found!" )
- return
- end
- -- Kick things off.
- StartFishing()
- end
- function msgbox(default, prompt, title, button, icon)
- 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 showmsg(prompt, title)
- msgbox( true, prompt, title, 0,4)
- end
- function SelectClient()
- result = msgbox( true,"Client logged in as: " .. UO.CharName, "Client Selection", 3 )
- if result == 6 then
- -- Yes.
- return
- elseif result == 7 then
- -- No.
- UO.CliNr=UO.CliNr+1
- SelectClient()
- return
- else
- -- Cancel
- showmsg( "Client selection canceled.", "Script Ended" )
- stop()
- end
- if UO.CliCnt < UO.CliNr then
- showmsg( "No client found.", "Script Ended" )
- stop()
- end
- end
- function FindHold()
- -- Our method to let the user select their boat's hold.
- UO.LTargetID = 0
- UO.ExMsg( UO.CharID, 3, 50, "Select the stowing container (ESC for toon pack)." )
- UO.TargCurs = true
- while( UO.TargCurs == true ) do
- wait( 1 )
- end
- return UO.LTargetID
- end
- function FindBow()
- -- Our method to let the user select the bow they want to use,
- -- if not using magery.
- UO.LTargetID = 0
- UO.ExMsg( UO.CharID, 3, 50, "Select the bow you wish to use (ESC for Magery)." )
- UO.TargCurs = true
- while( UO.TargCurs == true ) do
- wait( 1 )
- end
- return UO.LTargetID
- end
- function FindDagger()
- -- Our method to let the user select the dagger they want to use.
- UO.LTargetID = 0
- UO.ExMsg( UO.CharID, 3, 50, "Select the dagger you wish to use (ESC to quit when full)." )
- UO.TargCurs = true
- while( UO.TargCurs == true ) do
- wait( 1 )
- end
- return UO.LTargetID
- end
- function GetHoldCurrWeight( strIn )
- local itemName, itemContents = UO.Property( intHold )
- local commaStart, commaEnd = string.find( itemContents, ", " )
- if commaStart == nil or commaEnd == nil then return 0 end
- local slashStart, slashEnd = string.find( itemContents, "/", commaEnd )
- if slashStart == nil or slashEnd == nil then return 0 end
- local stonesStart, stonesEnd = string.find( itemContents, " Stones", slashEnd )
- if stonesStart == nil or stonesEnd == nil then return 0 end
- local strRet = string.sub( itemContents, commaEnd + 1, slashStart - 1 )
- return tonumber( strRet )
- end
- function GetHoldMaxWeight( strIn )
- local itemName, itemContents = UO.Property( intHold )
- local commaStart, commaEnd = string.find( itemContents, ", " )
- if commaStart == nil or commaEnd == nil then return 0 end
- local slashStart, slashEnd = string.find( itemContents, "/", commaEnd )
- if slashStart == nil or slashEnd == nil then return 0 end
- local stonesStart, stonesEnd = string.find( itemContents, " Stones", slashEnd )
- if stonesStart == nil or stonesEnd == nil then return 0 end
- local strRet = string.sub( itemContents, slashEnd + 1, stonesStart - 1 )
- return tonumber( strRet )
- end
- function StartFishing()
- -- Setup all of our positioning variables.
- local intX = UO.CharPosX - 3
- local intY = UO.CharPosY + 3
- local intStartX = UO.CharPosX
- local intStartY = UO.CharPosY
- -- Start our main loop
- while true == true do
- -- If the character has moved, reset our positioning variables.
- -- Causes: Spot is fished out, player moved the boat, player
- -- moved the character.
- if UO.CharPosX ~= intStartX or UO.CharPosY ~= intStartY then
- intX = UO.CharPosX - 3
- intY = UO.CharPosY + 3
- intStartX = UO.CharPosX
- intStartY = UO.CharPosY
- end
- -- Use the pole
- UO.LObjectID = intPole
- UO.Macro( 17, 0 )
- wait( 1000 )
- if UO.SysMsg == "You can't fish while riding or flying!" then
- -- Dismount.
- wait( 500 )
- UO.LObjectID = UO.CharID
- UO.Macro( 17, 0 )
- end
- WaitForTargWithTimeout( 500 )
- -- Set our tagetting up to fish the specified coords.
- UO.LTargetKind = 3
- UO.LTargetX = intX
- UO.LTargetY = intY
- UO.LTargetZ = UO.CharPosZ
- -- And do it.
- UO.Macro( 22, 0 )
- wait( 1000 )
- -- Wait for our fishing to be finished. We could have done the next
- -- few steps during this time, but I was seeing some strange
- -- artifacts of the process.
- wait( 9000 )
- -- Move on to the next fishing X coord.
- intX = intX + 1
- -- We only fish 7 spots on the x plain. -3x through +3x
- -- Check to make sure we are within this area.
- if intX > UO.CharPosX + 3 then
- -- Moving on the next Y coord.
- intY = intY + 1
- -- Reset our X coord.
- intX = UO.CharPosX - 3
- -- Put everything away.
- TossStoreAndUse()
- wait( 1000 )
- end
- -- We start at Y+3, and fish through Y+5. That means we
- -- we fish two tiles along the Y plain, 14 tiles total.
- -- Check to make sure we are within this area.
- if intY == UO.CharPosY + 5 then
- -- Getting here means that intX should already be reset, so
- -- we'll reset Y.
- intY = UO.CharPosY + 3
- -- Put everything away.
- CheckWeightAndCut()
- TossStoreAndUse()
- wait( 1000 )
- end
- -- Check our journal to see if the tile is fished out.
- if isFishedOut() == true then
- -- And, apparently, it is. Move a few tiles.
- if math.random( 1, 2 ) == 1 then
- UO.Macro( 1, 0, "left" )
- else
- UO.Macro( 1, 0, "right" )
- end
- wait( 2500 )
- UO.Macro( 1, 0, "stop" )
- wait( 500 )
- if math.random( 1, 2 ) == 1 then
- UO.Macro( 1, 0, "forward" )
- else
- UO.Macro( 1, 0, "reverse" )
- end
- wait( 2500 )
- UO.Macro( 1, 0, "stop" )
- end
- -- We're under attack. Own that bitch up!
- if UO.EnemyID ~= 0 and UO.EnemyHits ~= 0 then
- -- Like I said, asshole...own that bitch up!
- DoBattle()
- end
- end
- end
- function CheckWeightAndCut()
- local intCurrWeight = GetHoldCurrWeight()
- local intMaxWeight = GetHoldMaxWeight()
- if intCurrWeight + UO.Weight >= intMaxWeight then
- if intDagger ~= 0 then
- UO.NextCPosX = 100
- UO.NextCPosY = 100
- UO.LObjectID = intHold
- UO.Macro( 17, 0 )
- wait( 1000 )
- UO.ContTop( intHold )
- local intCycle
- local intMax = UO.ScanItems( false )
- for intCycle = 1,intMax do
- -- Get all of the info about this item that we need.
- local ID,Type,Kind,ContID,X,Y = UO.GetItem( intCycle )
- -- Loop through our keepers array.
- local intCycle2
- local intMax2 = table.getn( intStore )
- for intCycle2 = 1, intMax2 do
- if Type == intStore[intCycle2] and ContID == intHold then
- UO.LObjectID = intDagger
- UO.Macro( 17, 0 )
- WaitForTargWithTimeout( 1000 )
- UO.LTargetID = ID
- UO.Macro( 22, 0 )
- wait( 2000 )
- end
- end
- if UO.Weight > UO.MaxWeight * 0.80 then
- StowSteaks()
- end
- end
- else
- UO.ExMsg( UO.CharID, 3, 50, "Hold full. Script Ended." )
- stop()
- end
- end
- end
- function StowSteaks()
- local intCycle
- local intMax = UO.ScanItems( false )
- for intCycle = 1,intMax do
- -- Get all of the info about this item that we need.
- local ID,Type,Kind,ContID,X,Y,Z,Stack = UO.GetItem( intCycle )
- if ContID == UO.BackpackID and InStr( Name, "Steak" ) == true then
- UO.Drag( ID, Stack )
- wait( 1000 )
- UO.DropC( intHold )
- wait( 1000 )
- end
- end
- stop()
- end
- function InStr( strFindIn, strToFind )
- if strFindIn == nil or strToFind == nil then
- return false
- end
- local strRet = string.match( strFindIn, strToFind )
- if strRet ~= nil then
- return true
- end
- return false
- end
- function WaitForTargWithTimeout(intTimeout)
- while( UO.TargCurs == false ) do
- wait( 1 )
- intTimeout = intTimeout + 1
- if intTimeout >= 500 then
- break
- end
- end
- end
- function isFishedOut()
- -- We're only gonna scan the last five lines so we don't mistakenly return
- -- true.
- local intCycle
- local intMax = UO.ScanJournal(0)
- for intCycle = 0, 5 do
- local strLine = UO.GetJournal( intCycle )
- if strLine == UO.CharName .. ": The fish don't seem to be biting here." then
- -- Tile is empty, move on.
- return true
- end
- end
- return false
- end
- function TossStoreAndUse()
- --Loop through all items found in the backpack.
- local intCycle
- local intMax = UO.ScanItems( false )
- for intCycle = 1,intMax do
- -- Get all of the info about this item that we need.
- local ID,Type,Kind,ContID,X,Y,Z,Stack = UO.GetItem( intCycle )
- -- Toss bottles that aren't MiBs.
- if Type == 2463 and ContID == UO.BackpackID then
- local bottleName, bottleInfo = UO.Property( ID )
- if bottleName ~= "A Message In A Bottle" then
- -- Bitch ain't worth shit. Toss it.
- UO.Drag( ID, Stack )
- wait( 1000 )
- UO.DropG( UO.CharPosX + math.random( -2, 2 ), UO.CharPosY + math.random( -2, 2 ) )
- wait( 1000 )
- end
- end
- -- Loop through our trash array.
- local intCycle2
- local intMax2 = table.getn( intTrash )
- for intCycle2 = 1, intMax2 do
- if Type == intTrash[intCycle2] and ContID == UO.BackpackID then
- -- Bitch ain't worth shit. Toss it.
- UO.Drag( ID, Stack )
- wait( 1000 )
- UO.DropG( UO.CharPosX + math.random( -2, 2 ), UO.CharPosY + math.random( -2, 2 ) )
- wait( 1000 )
- end
- end
- -- Loop through our keepers array.
- if intHold ~= 0 then
- intMax2 = table.getn( intStore )
- for intCycle2 = 1, intMax2 do
- if Type == intStore[intCycle2] and ContID == UO.BackpackID then
- -- Good shit, stow it.
- UO.Drag( ID, Stack )
- wait( 1000 )
- UO.DropC( intHold )
- wait( 1000 )
- end
- end
- end
- -- Loop through our array of stuff to use (MiB, special fish, etc.)
- intMax2 = table.getn( intUse )
- for intCycle2 = 1, intMax2 do
- if Type == intUse[intCycle2] and ContID == UO.BackpackID then
- UO.LObjectID = ID
- UO.Macro( 17, 0 )
- wait( 1000 )
- end
- end
- end
- end
- function DoBattle()
- -- Time to kick some ass.
- if UseMagery == true then
- -- This attempts to ensure that we're not needlessly casting. When it's
- -- dead, stop.
- while UO.EnemyID ~= 0 and UO.EnemyHits ~= 0 do
- -- Cast Energy Bolt
- UO.Macro( 15, 41 )
- wait( 3000 )
- -- Wait for the Target cursor.
- while( UO.TargCurs == false ) do
- wait( 1 )
- end
- -- Target the current enemy. We don't cache this in case you have
- -- multiple enemies around.
- UO.LTargetID = UO.EnemyID
- UO.LTargetKind = 1 -- Thanks for the tip, PetKiller.
- UO.Macro( 22, 0 )
- wait( 2000 )
- -- See if we're in trouble. Could be changed to 1/2 HP, but 3/4 HP
- -- worked best for me.
- if UO.Hits < UO.MaxHits - (UO.MaxHits / 4) then
- -- Cast Greater Heal
- UO.Macro(15, 28)
- wait( 3000 )
- -- Wait for the Target cursor.
- while( UO.TargCurs == false ) do
- wait( 1 )
- end
- -- Target self
- UO.LTargetID = UO.CharID
- UO.Macro( 22, 0 )
- wait( 1000 )
- end
- end
- else
- -- Equip the bow and whip it's candy ass.
- UO.LObjectID = intBow
- UO.Macro( 37, 0 )
- while UO.EnemyID ~= 0 and UO.EnemyHits ~= 0 do
- -- We need to heal. Using bandies.
- if UO.Hits < UO.MaxHits - (UO.MaxHits / 4) then
- UO.LObjectID = FindBandies()
- UO.Macro(37, 0)
- wait( 3000 )
- -- Wait for the Target cursor.
- while( UO.TargCurs == false ) do
- wait( 1 )
- end
- -- Target the character
- UO.LTargetID = UO.CharID
- UO.LTargetKind = 1
- UO.Macro( 22, 0 )
- wait( 3000 )
- -- Re-equip the bow, just in case.
- UO.LObjectID = intBow
- UO.Macro( 37, 0 )
- end
- end
- end
- wait( 1000 )
- -- Bitch is dead. Get your booty.
- DoLoot()
- end
- function DoLoot()
- -- Find the corpse(s)
- local intCycle
- local intMax = UO.ScanItems( false )
- -- Loop through all items
- for intCycle = 1,intMax do
- -- Get all of the info about this item that we need.
- local corpseID,corpseType,corpseKind,corpseContID = UO.GetItem( intCycle )
- -- If it's the corpse.
- if corpseType == 8198 then
- -- I'm pretty sure Type 8198 is just a Sea Serpent corpse, but
- -- we're not really worried about looting Water Elems.
- -- Move the corpse pack gump. Not really needed, but I like it asshole.
- UO.NextCPosX = 100
- UO.NextCPosY = 100
- -- Open the gump.
- UO.LObjectID = corpseID
- UO.Macro( 17, 0, "" )
- wait( 1000 )
- -- Loop through all items to get only what's in the corpse.
- local intCycle2
- local intMax2 = UO.ScanItems( true )
- for intCycle2 = 1, intMax2 do
- local itemID,itemType,itemKind,itemContID = UO.GetItem( intCycle2 )
- -- It's in the corpse.
- if itemContID == UO.ContID then
- -- Loop through and make sure it's the loot we want.
- local intCycle3
- local intMax3 = table.getn( intLoot )
- for intCycle3 = 1, intMax3 do
- if itemType == intLoot[intCycle3] then
- -- Loot match, grab it! Quick!
- UO.Drag( itemID, 999 )
- wait( 1000 )
- UO.DropC( UO.BackpackID )
- wait( 1000 )
- end
- end
- end
- end
- -- Hide the corpse we just raided and move on.
- UO.HideItem( corpseID )
- end
- end
- end
- function FindPole()
- --Loop through all items
- local intCycle
- local intMax = UO.ScanItems( false )
- for intCycle = 1,intMax do
- -- Get all of the info about this item that we need.
- local ID,Type,Kind,ContID,X,Y = UO.GetItem( intCycle )
- -- If it's a pole, use it.
- if Type == 3519 then
- return ID
- end
- end
- end
- function FindBandies()
- --Loop through all items
- local intCycle
- local intMax = UO.ScanItems( false )
- for intCycle = 1,intMax do
- -- Get all of the info about this item that we need.
- local ID,Type,Kind,ContID,X,Y = UO.GetItem( intCycle )
- -- If it's bandies, we're usin' it!
- if Type == 3617 then
- return ID
- end
- end
- end
- -- Without this next line, the script will NOT work.
- -- This line initiates the entire runtime process.
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement