SERVICE_DELAY = 600; TREE_NAME = "Ginko tree"; WOOD_NAME = "Ginko wood"; WOOD_LIMIT = 30; STATE_SEARCH = 0; STATE_ATTACK = 1; STATE_TURN = 2; deposit_script = { -- This would be a script that deposits one wood load and returns to the grove } -- Add some stuff to the end of the depoosit script... table.insert(deposit_script, { cmd = auto.WAIT, value = 1000 } ); -- Wait for a little bit table.insert(deposit_script, { cmd = auto.RUN_FUNC, value = (function() state = { kind = STATE_SEARCH }; service(); -- And restart the service end) } ); running = false; DIR_OFS = go.DIR_OFS; OFS_MAP = { }; OFS_MAP[-1] = { }; OFS_MAP[-1][0] = 3; -- Left OFS_MAP[1] = { }; OFS_MAP[1][0] = 1; -- Right OFS_MAP[0] = { }; OFS_MAP[0][-1] = 0; -- Up OFS_MAP[0][1] = 2; -- Down function _G.beginTreeBot() state = { kind = STATE_SEARCH }; target = nil; service(); running = true; print("Tree bot has begun!"); end function _G.endTreeBot() auto.stop(); state = nil; running = false; print("Tree bot has ended!"); end function eventPacket(packet) if(packet.class == GENTEXT_PACKET and packet.text == "Your Axe broke!") then invo.use("axe"); elseif(packet.class == UPDATEINVO_PACKET) then if(packet.singlename == WOOD_ITEM and packet.quantity >= WOOD_LIMIT) then state = nil; auto.run(deposit_script); print("Depositing one wood load!"); end end end function service() if(state == nil) then return; end if(state.kind == STATE_SEARCH) then -- Look for a tree and then move towards it local nearest = { }; -- This table will hold information about the nearest tree so far -- Iterate through the game object registry, looking for trees for k, v in pairs(go.registry) do if(v.name == TREE_NAME) then local distance = math.abs(v.x - player.x) + math.abs(v.y - player.y); if(nearest.distance == nil or nearest.distance > distance) then nearest.uid = v.uid; nearest.distance = distance; end end end if(nearest.uid ~= nil) then target = nearest.uid; local x = go.registry[target].x; local y = go.registry[target].y; if((go.registry[target].x - player.x) < 0) then x = x - 1; else x = x + 1; end move_script = { hostility = auto.NOTHING_HOSTILE, { cmd = auto.HORIZ_MOVE, kind = auto.ABSOLUTE, value = x }, { cmd = auto.VERT_MOVE, kind = auto.ABSOLUTE, value = y }, { cmd = auto.RUN_FUNC, value = service } }; state = { kind = STATE_TURN }; auto.run(move_script); else -- Perhaps I should add something that will make the dude walk around a bit? print("Oops, there are no trees around here!"); end elseif(state.kind == STATE_TURN) then -- Turn to face the target sendPacket( { class = PLAYERDIR_PACKET, direction = OFS_MAP [go.registry[target].x - player.x] [go.registry[target].y - player.y] } ); -- Transition into the attack state state = { kind = STATE_ATTACK }; createTimer(SERVICE_DELAY, service); elseif(state.kind == STATE_ATTACK) then -- Check to see if the target is dead if(go.registry[target] ~= nil) then -- If it isn't dead, then attack the target sendPacket( { class = PLAYERATTACK_PACKET } ); else -- Otherwise, transition into the search state state = { kind = STATE_SEARCH }; end createTimer(SERVICE_DELAY, service); end end