This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Ministringham's profile picture

I need a little help

Started by Ministringham, 23 July 2014 - 12:06 AM
Ministringham #1
Posted 23 July 2014 - 02:06 AM
I am new to computercraft and i am curios if I can use the advanced wireless pocket computer to make it so if I fall below y level 0 teleport me to my spawn if any one could tell me how to do this that would be great, I was thinking it sending off a redstone signal to a command block but I also do not know how to write the code for that and I dont want to cheat in a commandblock but if I really really have to, then I will so please let me have some feedback thanks for reading!
DannySMc #2
Posted 23 July 2014 - 11:30 PM
This is possible indeed! You first need to have a working GPS System:
Okay so here is what the program will need to do:
  1. Pocket computer will constantly obtain your x,y,z location, (every 0.5) seconds,
  2. Then it will need to check whether your Y value is below 0,
  3. If you are below it then it will send a message to a server computer that will be connected to a command block
  4. This will set the command block to teleport you to a safe area,
  5. A safe area will need to be set on the server computer.
How to do this? okay so in total you will need 5 computers and 1 wireless pocket computer.
The pocket computer will be checking your location (x,y,z) using the gps station you will need to set up (Links below).
The server computer will be waiting for requests to teleport them to a safe area.
So make a safe area in your world, get the x,y,z values (F3 will show you them) and write them down somewhere
get the ID's of the pocket pc and the server.

Follow the instructions on this site or watch the youtube video (if not on link, just search gps-deploy)
http://www.computerc...dated-04012014/

Please note to do the following you will need to set your modem distance to 9999999999999999999999999999 and put a world anchor by the gps servers and the safety net server.

I have added a bit of simple code for you:

Main Server (Example ID: 12)

-- Safety Net
-- Created By DannySMc
version = 1
tpCount = 0
commandBlock = "top"
-- Safe Zone
intX = 50
intY = 70
intZ = 50
local function cs(txtColour)
term.clear()
term.setCursorPos(1,1)
if txtColour then
  term.setTextColour(colours[txtColour])
end
end
local function main()
cs("lime")
print("Safety Net Server - Version: "..version)
print(" ")
while true do
  print("> Safety Catch Count: "..tpCount)
  local args = { os.pullEvent() }
  if args[1] == "rednet_message" then
   if args[3] == "catch_me" then
	local nID, sUsername = rednet.receive(2)
	commandBlock.setCommand("/tp "..sUsername.." "..intX.." "..intY.." "..intZ)
	commandBlock.runCommand()
   end
  end
end
end
-- runs the main program
main()

This would run on your safety net server.

Pocket Computer:

-- Safety Net Pocket Computer Program
-- Created By DannySMc
version = 1
sUsername = "Add_Your_Username"
local function cs(txtColour)
term.clear()
term.setCursorPos(1,1)
if txtColour then
  term.setTextColour(colours[txtColour])
end
end
local function main()
print("> Safety Net is running...")
print("> Version: "..version)
while true do
  intX, intY, intZ = gps.locate(1)
  if intY < 0 then
   rednet.send(12, "catch_me")
   rednet.send(12, sUsername)
  end
sleep(0.5)
end
end
main()

There you go :)/> Not tested it, but should work.
Edited on 23 July 2014 - 09:30 PM