local params = {
delay = 0,
}
local world = {
size_x = 100,
size_y = 60,
name = ""
}
function pkt_punch(x, y, id)
local lp = GetLocal()
local packet = {
type = 3,
int_data = id,
pos_x = lp.pos_x,
pos_y = lp.pos_y,
int_x = x,
int_y = y,
}
SendPacketRaw(packet)
end
function inv_count(id)
local count = 0
for _, inv in pairs(GetInventory()) do
if inv.id == id then
count = count + inv.count
end
end
return count
end
--#region harvest
local harvest = {
enabled = false,
}
function do_harvest()
world.name = GetLocal().world
log("Starting Harvest!")
for _, tile in pairs(GetTiles()) do
if not harvest.enabled then
return
end
if world.name ~= GetLocal().world then
log("Stopped Harvesting: exit world: " .. GetLocal().world .. ", " ..
world.name)
return
end
if tile.ready and GetIteminfo(tile.fg).name:find("Seed") then
FindPath(tile.pos_x, tile.pos_y)
Sleep(params.delay + 60)
pkt_punch(tile.pos_x, tile.pos_y, 18)
Sleep(params.delay + 130)
end
end
log("Finished Harvesting: successfull.")
end
--#endregion
--#region plant
local plant = {
enabled = false,
plant_id = 0,
mag = {
x = 0, y = 0
}
}
function check_remote()
if inv_count(5640) < 1 then
FindPath(plant.mag.x, plant.mag.y - 1)
pkt_punch(plant.mag.x, plant.mag.y, 32)
SendPacket(2, "action|dialog_return\ndialog_name|magplant_edit\nx|"..
plant.mag.x .."|\ny|" .. plant.mag.y .. "|\nbuttonClicked|getRemote")
end
log(inv_count(5640))
return inv_count(5640) >= 1
end
function do_plant()
world.name = GetLocal().world
if plant.mag.x == 0 and plant.mag.y == 0 or check_remote() then
log("Wrench Magplant and Get Remote.")
return
end
log("Starting Planting!")
for _, tile in pairs(GetTiles()) do
if not plant.enabled then
return
end
if world.name ~= GetLocal().world then
log("Stopped Planting: exit world: " .. GetLocal().world .. ", " ..
world.name)
return
end
if tile.fg == 0 then
FindPath(tile.pos_x, tile.pos_y)
Sleep(params.delay + 60)
pkt_punch(tile.pos_x, tile.pos_y, 5640)
Sleep(params.delay + 130)
end
end
log("Finished Planting: successfull.")
end
--#endregion
--#region place plats
local place_plats = {
enabled = false,
}
function do_place_plats()
world.name = GetLocal().world
if plant.mag.x == 0 and plant.mag.y == 0 or check_remote() then
log("Wrench Magplant and Get Remote.")
return
end
log("Starting Placing Plats!")
for _, tile in pairs(GetTiles()) do
if not place_plats.enabled then
return
end
if world.name ~= GetLocal().world then
log("Stopped Placing Plats: exit world: " .. GetLocal().world .. ",
" .. world.name)
return
end
if tile.pos_y % 2 == 0 then
log(tile.pos_y)
goto continue
end
if tile.fg == 0 then
FindPath(tile.pos_x, tile.pos_y - 1)
Sleep(params.delay + 60)
pkt_punch(tile.pos_x, tile.pos_y, 5640)
Sleep(params.delay + 130)
end
::continue::
end
log("Finished Placing Plats: successfull.")
end
--#endregion
--#region callbacks
local handle_callbacks = {}
-- {str name, str callback, void* func}
handle_callbacks.callbacks = {
{"hook_packet", "OnPacket", hook_packet},
--{"hook_varlist", "OnVarlist", hook_varlist}
}
handle_callbacks.remove_callbacks = function()
for i = 1, #handle_callbacks.callbacks do
RemoveCallback(handle_callbacks.callbacks[i][1])
end
end
handle_callbacks.add_callbacks = function()
for i = 1, #handle_callbacks.callbacks do
AddCallback(table.unpack(handle_callbacks.callbacks[i]))
end
end
function hook_packet(type, packet)
if packet:find("action|input\n|text|/farm quit") then
log("Quitting.")
handle_callbacks.remove_callbacks()
harvest.enabled = false
plant.enabled = false
place_plats.enabled = false
end
if packet:find("action|input\n|text|/farm harvest") then
world.name = GetLocal().world
harvest.enabled = not harvest.enabled
end
if packet:find("action|input\n|text|/farm plant") then
world.name = GetLocal().world
plant.enabled = not plant.enabled
end
if packet:find("action|input\n|text|/farm place_plats") then
world.name = GetLocal().world
place_plats.enabled = not place_plats.enabled
end
if packet:find("buttonClicked|getRemote") and packet:find("dialog_name|
magplant_edit") then
plant.mag.x = packet:match('x|(%d+)')
plant.mag.y = packet:match('y|(%d+)')
end
end
function hook_varlist(varlist, packet)
end
handle_callbacks.add_callbacks()
--#endregion
while true do
Sleep(1000)
if harvest.enabled then
harvest.enabled = false
do_harvest()
end
if plant.enabled then
plant.enabled = false
do_plant()
end
if place_plats.enabled then
place_plats.enabled = false
do_place_plats()
end
end