0% found this document useful (0 votes)
59 views4 pages

AutoSplice Lua

The document contains an Lua script that automates farming in a game by having an AI player plant seeds, gather seeds from the environment, and pathfind to collect seeds when the inventory is empty. It checks that the player count is below a threshold and only plants seeds when there is space available and sufficient seeds in inventory. The script loops this process until the conditions are no longer met or more than the allowed players are in the game.

Uploaded by

baljasart
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views4 pages

AutoSplice Lua

The document contains an Lua script that automates farming in a game by having an AI player plant seeds, gather seeds from the environment, and pathfind to collect seeds when the inventory is empty. It checks that the player count is below a threshold and only plants seeds when there is space available and sufficient seeds in inventory. The script loops this process until the conditions are no longer met or more than the allowed players are in the game.

Uploaded by

baljasart
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

--Made by Finndramere

--SpliceMachine

LogToConsole("Started")

maxPlayerCount = 1 -- if u set this to 1 this script will not run for 10 seconds if
theres more than 1 person in the world. it will continue if conditions are met.

seedID1 = FindItemID("Dirt Seed")


seedID2 = FindItemID("Cave Background Seed")
placeDelay = 110

function place(x, y, itemID)


pkt = {}
pkt.px = x;
pkt.py = y;
pkt.type = 3;
pkt.value = itemID;
pkt.x = GetLocal().posX;
pkt.y = GetLocal().posY;
SendPacketRaw(false, pkt);
Sleep(placeDelay)
end

function getPlayerCount()
count = 0
for _, player in pairs(GetPlayerList()) do
count = count+1
end
return count
end

function getItemAmount(itemid)
for _, item in pairs(GetInventory()) do
if item.id == itemid then
return item.amount
end
end
return 0
end

function PathFindToObj(objID ,targetAmount)


for _, obj in pairs(GetObjectList()) do
if obj.itemid == objID and obj.amount >= targetAmount then
if GetTiles(math.floor((obj.posX+10)/32),
math.floor((obj.posY+10)/32)).flag == 0 or GetTiles(math.floor((obj.posX+10)/32),
math.floor((obj.posY+10)/32)).flag == 2 then
FindPath(math.floor((obj.posX+10)/32),
math.floor((obj.posY+10)/32))
--LogToConsole("Finding Path to
"..math.floor(obj.posX/32).." and "..math.floor(obj.posY/32).." id "..obj.itemid.."
amount "..obj.amount)
return true
end
end
end
return false
end
function getFloatingItemAmount(objID)
count = 0
for _, obj in pairs(GetObjectList()) do
if GetTiles(math.floor((obj.posX+10)/32),
math.floor((obj.posY+10)/32)).flag == 0 or GetTiles(math.floor((obj.posX+10)/32),
math.floor((obj.posY+10)/32)).flag == 2 then
if obj.itemid == objID then -- and
GetTiles(math.floor(obj.posX/32), math.floor(obj.posY/32)).flag == 0
count = count + obj.amount
end
end
end
return count
end

function getPlacedAmount(id)
count = 0
for _, tile in pairs(GetTiles()) do
if tile.fg == id then -- and GetTiles(math.floor(obj.posX/32),
math.floor(obj.posY/32)).flag == 0
count = count + 1
end
end
return count
end

function plant(seed1, seed2)


for _, tile in pairs(GetTiles()) do
if tile.fg == 0 and GetTiles(tile.x, tile.y+1).flag == 1 or tile.fg ==
0 and GetTiles(tile.x, tile.y+1).flag == 2 then
if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y then
place(tile.x, tile.y, seed1)
place(tile.x, tile.y, seed2)
else
if(math.floor(GetLocal().posX/32) == tile.x-1 and
math.floor(GetLocal().posY/32) == tile.y) then
FindPath(tile.x, tile.y)
Sleep(50)
else
FindPath(tile.x, tile.y)
Sleep(100)
end
end
return true

elseif tile.fg == seed1 and GetTiles(tile.x, tile.y+1).flag == 1 or


tile.fg == seed1 and GetTiles(tile.x, tile.y+1).flag == 2 then
if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y then
place(tile.x, tile.y, seed2)
else
if(math.floor(GetLocal().posX/32) == tile.x-1 and
math.floor(GetLocal().posY/32) == tile.y) then
FindPath(tile.x, tile.y)
Sleep(50)
else
FindPath(tile.x, tile.y)
Sleep(100)
end
end
return true

elseif tile.fg == seed2 and GetTiles(tile.x, tile.y+1).flag == 1 or


tile.fg == seed2 and GetTiles(tile.x, tile.y+1).flag == 2 then
if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y then
place(tile.x, tile.y, seed1)
else
if(math.floor(GetLocal().posX/32) == tile.x-1 and
math.floor(GetLocal().posY/32) == tile.y) then
FindPath(tile.x, tile.y)
Sleep(50)
else
FindPath(tile.x, tile.y)
Sleep(100)
end
end
return true
end

end
return false
end

function hasPlantableSpot()
for _, tile in pairs(GetTiles()) do
if (tile.fg == 0 and GetTiles(tile.x, tile.y+1).flag == 1 or tile.fg ==
0 and GetTiles(tile.x, tile.y+1).flag == 2) then
return true
elseif tile.fg == seed1 and GetTiles(tile.x, tile.y+1).flag == 1 or
tile.fg == seed1 and GetTiles(tile.x, tile.y+1).flag == 2 then
return true
elseif tile.fg == seed2 and GetTiles(tile.x, tile.y+1).flag == 1 or
tile.fg == seed2 and GetTiles(tile.x, tile.y+1).flag == 2 then
return true
end
end
return false
end

-------------------------------------
splicemode = true

while splicemode == true do


if getPlayerCount() <= maxPlayerCount then

if (getFloatingItemAmount(seedID1) + getItemAmount(seedID1) > 0 or


getFloatingItemAmount(seedID2) + getItemAmount(seedID2) > 0) and hasPlantableSpot()
== true then

--gather seed1
if getItemAmount(seedID1) == 0 and getFloatingItemAmount(seedID1)
> 0 then
LogToConsole("PathFinding to Seed1")
while (getItemAmount(seedID1) < 200 and
getFloatingItemAmount(seedID1) > 0 ) and getPlayerCount() <= maxPlayerCount do
PathFindToObj(seedID1, 1)
Sleep(1000)
end
end

--gather seed2
if getItemAmount(seedID2) == 0 and getFloatingItemAmount(seedID2)
> 0 then
LogToConsole("PathFinding to Seed2")
while (getItemAmount(seedID2) < 200 and
getFloatingItemAmount(seedID2) > 0 ) and getPlayerCount() <= maxPlayerCount do
PathFindToObj(seedID2, 1)
Sleep(1000)
end
end

if (getItemAmount(seedID1) > 0 and getItemAmount(seedID2) > 0)


and hasPlantableSpot() == true then
LogToConsole("Planting")
while getItemAmount(seedID1) > 0 and hasPlantableSpot() ==
true and getPlayerCount() <= maxPlayerCount do
plant(seedID1, seedID2)
end
end

else
splicemode = false
end

else
SendPacket(2, "action|respawn")
Sleep(5000)
while getPlayerCount() > maxPlayerCount do
Sleep(10000)
end
end
end

Sleep(2000)
LogToConsole("Script Ended")

You might also like