function lisa_cot() --=== version 1.1 ===-- function gotAllKeys() local room = currentRoom() local keys = inventory:itemTotalCount(203027) local keyGoal = (room == 1 and 1) or (room == 2 and 3) or (room == 3 and 6) or (room == 4 and 10) return keys >= keyGoal end function currentRoom() return memoryReadRepeat("int",getProc(), player.Address + 0x1cc) end local function gotogate() if not cottravel({X=4079.2 , Z=3975.5, Y=28.7},true) then -- teleport to key seal avoiding summon print("Can't avoid summoning seal") cottravel({X=4079.2 , Z=3975.5, Y=28.7}) -- can't avoid summoning end player:faceDirection(3.14/2) -- Face forward keyboardPress( settings.hotkeys.MOVE_FORWARD.key ); repeat player:update() dist = distance(player.X, player.Z, 4081, 3335) yrest(700) until 100 > dist yrest(500) player:update() if 18 > player.Y then print("\a") local y = player.Y for i = 1,20 do teleport(nil,nil,y+i) player:turnDirection(1) yrest(50) end keyboardPress( settings.hotkeys.MOVE_FORWARD.key ); yrest(500) player:update() if 18 > player.Y then print("\a\aplayer is stuck") player:sleep() end end printf("Distance checked and continuing.\n") end local function currentRoom() return memoryReadRepeat("int",getProc(), player.Address + 0x1cc) end local function gotAllKeys() local room = currentRoom() local keys = inventory:itemTotalCount(203027) local keyGoal = (room == 1 and 1) or (room == 2 and 3) or (room == 3 and 6) or (room == 4 and 10) return keys >= keyGoal end local function checkaggro() repeat player:update() if player.Battling then local clown = player:findEnemy(true) player.X, player.Z = clown.X, clown.Z -- Temporarily change player coords so we can find nearest seal to mob local seal = player:findNearestNameOrId(102368) player:updateXYZ() player:target(seal) -- kills the summoning portal and not the ghost clown. teleport(seal.X,seal.Z,seal.Y+5,true) player:fight() yrest(2000) -- give a couple of seconds for the clown to disappear. player:update() end until not player.Battling end local function getpoints() return { [1]={ X=4213 , Z=3707, Y=18.7, Links={[1]={Num=7},[2]={Num=8},[3]={Num=33},}}, [2]={ X=3947 , Z=3707, Y=18.7, Links={[1]={Num=3},[2]={Num=28},[3]={Num=6},}}, [3]={ X=4013.5 , Z=3707, Y=18.7, Links={[1]={Num=23},[2]={Num=2},[3]={Num=10},[4]={Num=36},}}, [4]={ X=4079.2 , Z=3975.5, Y=18.7, Links={[1]={Num=25},}}, [5]={ X=4146.5 , Z=3672.5, Y=18.7, Links={[1]={Num=9},[2]={Num=7},[3]={Num=8},}}, [6]={ X=3947 , Z=3672.5, Y=18.7, Links={[1]={Num=10},[2]={Num=2},}}, [7]={ X=4213 , Z=3672.5, Y=18.7, Links={[1]={Num=5},[2]={Num=1},}}, [8]={ X=4146.5 , Z=3707, Y=18.7, Links={[1]={Num=1},[2]={Num=23},[3]={Num=5},[4]={Num=30},}}, [9]={ X=4080 , Z=3672.5, Y=18.7, Links={[1]={Num=10},[2]={Num=5},[3]={Num=23},}}, [10]={ X=4013.5 , Z=3672.5, Y=18.7, Links={[1]={Num=6},[2]={Num=9},[3]={Num=3},}}, [11]={ X=4213 , Z=3914, Y=18.7, Links={[1]={Num=17},[2]={Num=26},[3]={Num=19},}}, [12]={ X=4080 , Z=3845, Y=18.7, Links={[1]={Num=20},[2]={Num=13},[3]={Num=14},[4]={Num=39},}}, [13]={ X=4013.5 , Z=3845, Y=18.7, Links={[1]={Num=12},[2]={Num=44},[3]={Num=45},[4]={Num=22},}}, [14]={ X=4080 , Z=3879.5, Y=18.7, Links={[1]={Num=22},[2]={Num=12},[4]={Num=18},}}, [15]={ X=4013.5 , Z=3914, Y=18.7, Links={[1]={Num=18},[2]={Num=31},[3]={Num=22},[4]={Num=27},}}, [16]={ X=4146.5 , Z=3948.5, Y=18.7, Links={[1]={Num=25},[2]={Num=19},[3]={Num=26},}}, [17]={ X=4213 , Z=3879.5, Y=18.7, Links={[1]={Num=21},[2]={Num=11},[3]={Num=24},}}, [18]={ X=4080 , Z=3914, Y=18.7, Links={[1]={Num=26},[2]={Num=15},[3]={Num=25},[4]={Num=14},}}, [19]={ X=4213 , Z=3948.5, Y=18.7, Links={[1]={Num=16},[2]={Num=11},}}, [20]={ X=4146.5 , Z=3845, Y=18.7, Links={[1]={Num=24},[2]={Num=12},[3]={Num=40},[4]={Num=21},}}, [21]={ X=4146.5 , Z=3879.5, Y=18.7, Links={[1]={Num=14},[2]={Num=17},[3]={Num=20},[4]={Num=26},}}, [22]={ X=4013.5 , Z=3879.5, Y=18.7, Links={[1]={Num=43},[2]={Num=14},[3]={Num=13},[4]={Num=15},}}, [23]={ X=4080 , Z=3707, Y=18.7, Links={[1]={Num=8},[2]={Num=3},[3]={Num=46},[4]={Num=9},}}, [24]={ X=4213 , Z=3845, Y=18.7, Links={[1]={Num=37},[2]={Num=20},[3]={Num=17},}}, [25]={ X=4080 , Z=3948.5, Y=18.7, Links={[1]={Num=27},[2]={Num=16},[3]={Num=4},[4]={Num=18},}}, [26]={ X=4146.5 , Z=3914, Y=18.7, Links={[1]={Num=11},[2]={Num=18},[3]={Num=21},[4]={Num=16},}}, [27]={ X=4013.5 , Z=3948.5, Y=18.7, Links={[1]={Num=35},[2]={Num=25},[3]={Num=15},}}, [28]={ X=3947 , Z=3741.5, Y=18.7, Links={[1]={Num=2},[2]={Num=36},[3]={Num=38},}}, [29]={ X=4146.5 , Z=3776, Y=18.7, Links={[1]={Num=41},[2]={Num=32},[3]={Num=30},[4]={Num=40},}}, [30]={ X=4146.5 , Z=3741.5, Y=18.7, Links={[1]={Num=46},[2]={Num=33},[3]={Num=8},[4]={Num=29},}}, [31]={ X=3947 , Z=3914, Y=18.7, Links={[1]={Num=15},[2]={Num=35},[3]={Num=43},}}, [32]={ X=4080 , Z=3776, Y=18.7, Links={[1]={Num=29},[2]={Num=42},[3]={Num=39},[4]={Num=46},}}, [33]={ X=4213 , Z=3741.5, Y=18.7, Links={[1]={Num=30},[2]={Num=41},[3]={Num=1},}}, [34]={ X=3947 , Z=3810.5, Y=18.7, Links={[1]={Num=38},[2]={Num=45},[3]={Num=44},}}, [35]={ X=3947 , Z=3948.5, Y=18.7, Links={[1]={Num=31},[2]={Num=27},}}, [36]={ X=4013.5 , Z=3741.5, Y=18.7, Links={[1]={Num=28},[2]={Num=46},[3]={Num=3},[4]={Num=42},}}, [37]={ X=4213 , Z=3810.5, Y=18.7, Links={[1]={Num=40},[2]={Num=24},[3]={Num=41},}}, [38]={ X=3947 , Z=3776, Y=18.7, Links={[1]={Num=42},[2]={Num=34},[3]={Num=28},}}, [39]={ X=4080 , Z=3810.5, Y=18.7, Links={[1]={Num=45},[2]={Num=40},[3]={Num=12},[4]={Num=32},}}, [40]={ X=4146.5 , Z=3810.5, Y=18.7, Links={[1]={Num=39},[2]={Num=37},[3]={Num=29},[4]={Num=20},}}, [41]={ X=4213 , Z=3776, Y=18.7, Links={[1]={Num=33},[2]={Num=29},[3]={Num=37},}}, [42]={ X=4013.5 , Z=3776, Y=18.7, Links={[1]={Num=32},[2]={Num=38},[3]={Num=36},[4]={Num=45},}}, [43]={ X=3947 , Z=3879.5, Y=18.7, Links={[1]={Num=44},[2]={Num=22},[3]={Num=31},}}, [44]={ X=3947 , Z=3845, Y=18.7, Links={[1]={Num=13},[2]={Num=43},[3]={Num=34},}}, [45]={ X=4013.5 , Z=3810.5, Y=18.7, Links={[1]={Num=34},[2]={Num=39},[3]={Num=42},[4]={Num=13},}}, [46]={ X=4080 , Z=3741.5, Y=18.7, Links={[1]={Num=36},[2]={Num=30},[3]={Num=32},[4]={Num=23},}}, } end function cottravel(dest,_avoid) player:update() local path = {} local points = getpoints() -- so we can edit table without affecting original if _avoid then -- try to avoid summoning seals local objectList = CObjectList(); objectList:update(); local objSize = objectList:size() local number = 0 for i = 0,objSize do obj = objectList:getObject(i); if obj.Id == 113111 then -- sealed summon for k,v in pairs(points) do if 5 >= distance(v.X,v.Z,obj.X,obj.Z) then -- this is the point where the summon seal is. points[k] = { X=0 , Z=0, Y=0, Links={}} end end end end end --=== determine location ===-- local closest = 1; for i,v in pairs(points) do local oldClosestWp = points[closest]; if( distance(player.X, player.Z, oldClosestWp.X, oldClosestWp.Z) > distance(player.X, player.Z, v.X, v.Z) ) then closest = i; end travellocation = closest end --=== determine destination ===-- local closest = 1; for i,v in pairs(points) do local oldClosestWp = points[closest]; if( distance(dest.X, dest.Z, oldClosestWp.X, oldClosestWp.Z) > distance(dest.X, dest.Z, v.X, v.Z) ) then closest = i; end traveldestination = closest end for pointnum,point in pairs(points) do for Num,link in pairs(point.Links) do if points[pointnum].Links[Num].dist == nil then points[pointnum].Links[Num].dist = distance(point.X, point.Z, points[Num].X, points[Num].Z) end end end local function findPath(_from, _val) -- initialize local dist = {} -- Current total distances to each point local previous = {} -- Current previous points that yield the shortest distance to those points local completed = {} -- points already checked and finished with local Q = {}-- queue of current points being worked on. Only the index numbers dist[_from] = 0 Q[_from] = true local function getSmallestDist(_Q) -- Look for shortest path in Q local shortestdist = math.huge -- So we don't have to check for nil all the time local shortest for k,__ in pairs(_Q) do if shortestdist > dist[k] then shortestdist = dist[k] shortest = k end end return shortest end local destination_found = false while next(Q) ~= nil do -- not empty -- find point with shortest dist local currNum = getSmallestDist(Q) if currNum == nil then error("I think it finished without finding a path to the destination.") end if points[currNum]~= nil then -- This line is not needed. Added because of faulty database currPoint = table.copy(points[currNum]) -- see if it's the destination if currNum == _val then destination_found = currNum end if destination_found then -- destination reached print("Destination found") break end -- bring in connected Links that aren't already completed for k,v in pairs(currPoint.Links) do if Q[v.Num] then -- Already in the Q. Update dist. local tmp = dist[currNum] + v.dist if dist[v.Num] > tmp then dist[v.Num] = tmp previous[v.Num] = currNum end elseif not completed[v.Num] then -- add new point Q[v.Num] = true dist[v.Num] = dist[currNum] + v.dist previous[v.Num] = currNum end end end -- pop from the Q. completed[currNum] = true Q[currNum] = nil end if next(Q) == nil then print("Didn't find path to destination.") return false end if destination_found then -- return path -- 'currNum' is the destination table.insert(path,{X=points[destination_found].X,Z=points[destination_found].Z,Y=points[destination_found].Y}) while previous[destination_found] do destination_found = previous[destination_found] --table.insert(path,destination_found) table.insert(path,{X=points[destination_found].X,Z=points[destination_found].Z,Y=points[destination_found].Y}) end end end findPath(traveldestination,travellocation) local count = #path for k,v in pairs(path) do --player:moveTo(CWaypoint(v.X,v.Z,v.Y),true,false,30) teleport(v.X,v.Z,v.Y + 10,true) checkaggro() -- check for mobs, I guess. print(count..": points left to go before destination.") count = (count - 1) end print("Arrived at destination.") return true end --=== changing teleport settings teleport_SetStepSize(50) teleport_SetStepPause(500) local lastSealAddress = 0 repeat player:update() local seal = player:findNearestNameOrId(113112, lastSealAddress) if seal then if not cottravel(seal,true) then -- teleport to key seal avoiding summon print("Can't avoid summoning seal") cottravel(seal) -- can't avoid summoning end -- click seal repeat checkaggro() player:target(seal) yrest(100) Attack() yrest(1500) player:update() until player:findNearestNameOrId(113106) -- until a key appears -- Remember last seal lastSealAddress = seal.Address local keys = inventory:itemTotalCount(203027) repeat checkaggro() player:target_Object(113106,nil,nil,true) -- harvests key until inventory:itemTotalCount(203027) == keys + 1 end gotogate() until gotAllKeys() end