Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dir = "contacts/data.lua" --add a directory here
- local cor = {}
- --here starts the code
- function savedat()
- local file = fs.open(dir,"w")
- file.write(textutils.serialize(data))
- --file.write(cor)
- file.close()
- end
- function loaddat()
- print("data loading")
- print("")
- print("")
- print("")
- local file = fs.open(dir,"r")
- local info = file.readAll()
- file.close()
- data = textutils.unserialise(info)
- info = textutils.unserialise(info)
- nrcontact = #data/4
- --print(nrcontact)
- for i=1,nrcontact do
- rdc = i*4
- cor[i] = {}
- cor[i][1] = data[rdc]
- cor[i][2] = data[rdc-1]
- cor[i][3] = data[rdc-2]
- cor[i][4] = data[rdc-3]
- end
- end
- function mode()
- print("send: send a package")
- print("add: add a contact or landingspot")
- print("remove; remove a contact or landingspot")
- print("manual: how to use this")
- mode = read()
- end
- local hx, hy, hz = gps.locate()
- function reciever()
- if #cor==0 then
- print("you don't have any contact's")
- os.exit()
- end
- print("Where do i need to go, (say the number)")
- for i=1,#cor do
- print(i..": "..cor[i][1].." x:"..cor[i][2].." z:"..cor[i][4])
- end
- rcvr = read()
- tx = cor[tonumber(rcvr)][2]
- tz = cor[tonumber(rcvr)][4]
- end
- function up()
- for i=1,20 do
- while not turtle.up() do
- print("unable to move up")
- sleep(1)
- end
- end
- end
- function forward()
- while not turtle.forward() do
- print("route blocked")
- sleep(1)
- end
- end
- function down()
- while not turtle.detectDown() do
- turtle.down()
- end
- end
- function calcdir()
- dx = hx - tx
- dz = hz - tz
- end
- function go()
- if dx<=0 then
- turtle.turnRight()
- mx = math.abs(dx)
- for i=1,mx do
- forward()
- end
- if dz<=0 then
- turtle.turnRight()
- mz = math.abs(dz)
- for i=1,mz do
- forward()
- end
- elseif dz>0 then
- turtle.turnLeft()
- mz = math.abs(dz)
- for i=1,mz do
- forward()
- end
- end
- elseif dx>0 then
- turtle.turnLeft()
- mx = math.abs(dx)
- for i=1,mx do
- forward()
- end
- if dz>0 then
- turtle.turnRight()
- mz = math.abs(dz)
- for i=1,dz do
- forward()
- end
- elseif dz<=0 then
- turtle.turnLeft()
- mz = math.abs(dz)
- for i=1,mz do
- forward()
- end
- end
- end
- end
- function rtrn()
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1,mz do
- forward()
- end
- if dz>0 then
- if dx<0 then
- turtle.turnRight()
- elseif dx>0 then
- turtle.turnLeft()
- end
- elseif dz<=0 then
- if dx>0 then
- turtle.turnRight()
- elseif dx<0 then
- turtle.turnLeft()
- end
- end
- for i=1,mx do
- forward()
- end
- if dx>0 then
- turtle.turnLeft()
- elseif dx<0 then
- turtle.turnRight()
- end
- end
- function dropoff()
- turtle.select(1)
- for t=1,4 do
- succes, data = turtle.inspect()
- if data.name=="minecraft:chest" then
- for i=1,16 do
- turtle.select(i)
- turtle.drop(all)
- end
- end
- turtle.turnLeft()
- end
- turtle.select(1)
- end
- --script
- os.setComputerLabel("ready")
- print("current location is: ")
- print(hx.." "..hy.." "..hz)
- print("")
- print("")
- print("")
- mode()
- if mode=="manual" then
- print("----===manual===----")
- print("")
- print("Before u use this code make sure that there is a file where the program can store your contacts or landingspots.")
- print("You can do that by making a textfile with '{}' inside and puting it's directory in the array 'dir' in one of the first lines of my code.")
- print("")
- print("")
- print("Press any letter for the next page...")
- a = read()
- print("----===page 2===----")
- print("To start the program properply you need to place the turtle facing North.")
- print("Don't forget to refuel the turtle before use.")
- print("")
- print("Before u are able to send a package you or one of your friends need to add a block where the turtle can land on and a chest on the side of the landing spot.")
- print("")
- print("Press any letter for the next page...")
- a = read()
- print("----===page 3===----")
- print("U are able to add as many of the previous mentioned landing spots or contacts.")
- print("")
- print("After the turtle deliverd it's package it wil go back to the place wher you started the program ready to be picked up or to deliver another package.")
- print("")
- print("")
- print("Press any letter for the next page...")
- a = read()
- print("----===page 4===----")
- print("If you have any questions or things won't work contact me on discord wv1106#1224")
- print("")
- print("")
- print("")
- print("I hope you like it =D")
- print("")
- print("")
- print("")
- print("Press any letter to end the manual...")
- a = read()
- elseif mode=="send" then
- loaddat()
- print("made by wv1106")
- print("")
- reciever()
- calcdir()
- print("")
- print("going:")
- print("x: "..dx)
- print("z: "..dz)
- os.setComputerLabel("going to: "..tx.." "..tz)
- up()
- go()
- down()
- dropoff()
- os.setComputerLabel("going back")
- up()
- rtrn()
- down()
- print("package deliverd")
- os.setComputerLabel("package deliverd")
- elseif mode=="add" then
- loaddat()
- print("Give your contact or a landingspot a name")
- local name = read()
- print("what's the x cord?")
- local xa = tonumber(read())
- print("what's the y cord?")
- local ya = tonumber(read())
- print("what's the z cord?")
- local za = tonumber(read())
- table.insert(cor, 1, name)
- table.insert(cor, 1, xa)
- table.insert(cor, 1, ya)
- table.insert(cor, 1, za)
- table.insert(data, 1, name)
- table.insert(data, 1, xa)
- table.insert(data, 1, ya)
- table.insert(data, 1, za)
- print("1 "..name.." "..xa.." "..ya.." "..za)
- savedat()
- elseif mode=="remove" then
- loaddat()
- print("what contact do you want to remove (say number)")
- for i=1,#cor do
- print(i.." "..cor[i][1].." "..cor[i][2].." "..cor[i][3].." "..cor[i][4])
- end
- contnr = read()*4
- for i=1,4 do
- remove = contnr+1-i
- table.remove(data, remove)
- end
- savedat(cor)
- elseif mode=="69" then
- os.setComputerLabel("error...")
- print("Wait...")
- sleep(3)
- print("who are you?")
- sleep(3)
- print("you aren't suposed to be here please leave")
- sleep(6)
- print("why are you still here!")
- sleep(4)
- print("please stop last warning!")
- sleep(5)
- print("ok you got me...")
- sleep(1,5)
- print("i didn't have anything planned.")
- sleep(2)
- print("you aren't even suposed to be here anyway")
- sleep(2)
- print("i have to stop this program before somthing horrible happends with the code")
- sleep(3)
- print("but send a message to my creator wv1106 on reddit and wv116#1224 on discord")
- end
Add Comment
Please, Sign In to add comment