Advertisement
Muhi98

STS

Apr 3rd, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. --STS
  2.  
  3. --load wireless modem
  4. function loadWireless()
  5.     modem = peripheral.wrap("left")
  6.     wirelessMode = true
  7.    
  8.     if( modem == nil) then
  9.         wirelessMode = false
  10.         return false
  11.     else
  12.         return true
  13.     end
  14. end
  15.  
  16.  
  17. local currentX, currentY, currentZ = 0
  18. local currentFace, startingFace = 0
  19. pcId = 0
  20. --face: 0 South; 1 East; 2 North; 3 West
  21.  
  22. function sendMsg(msg, channel)
  23.     if not wirelessMode then
  24.         print("Not wireless")
  25.     end
  26.    
  27.    
  28.     modem.transmit(channel, pcId, msg)
  29.  
  30. end
  31.  
  32. function getStartingFace()
  33.     return startingFace
  34. end
  35.  
  36. function initLocation(x, y, z, face, pc)
  37.     currentX = x
  38.     currentY = y
  39.     currentZ = z
  40.     currentFace = face
  41.     pcId = tonumber(pc)
  42. end
  43.  
  44. function getX()
  45.     return currentX
  46. end
  47.  
  48. function getY()
  49.     return currentY
  50. end
  51.  
  52. function getZ()
  53.     return currentZ
  54. end
  55.  
  56. function getFace()
  57.     return currentFace
  58. end
  59.  
  60. function down()
  61.     if turtle.down() then
  62.         currentY = currentY - 1
  63.         return true
  64.     else
  65.         return false
  66.     end
  67. end
  68.  
  69. function up()
  70.     turtle.up()
  71.     currentY = currentY + 1
  72. end
  73.  
  74.  
  75. function forward()
  76.     while not turtle.forward() do
  77.         turtle.dig()
  78.     end
  79.     --face: 0 South; 1 East; 2 North; 3 West
  80.     if (currentFace == 0) then
  81.         currentZ = currentZ + 1
  82.     elseif currentFace == 1 then
  83.         currentX = currentX + 1
  84.     elseif currentFace == 2 then
  85.         currentZ = currentZ - 1
  86.     else
  87.         currentX = currentX - 1
  88.     end
  89.    
  90. end
  91.  
  92. function turnLeft()
  93.     turtle.turnLeft()
  94.     if(currentFace == 3) then
  95.         currentFace = 0
  96.     else
  97.         currentFace = currentFace + 1
  98.     end
  99. end
  100.  
  101. function turnRight()
  102.     turtle.turnRight()
  103.     if(currentFace == 0) then
  104.         currentFace = 3
  105.     else
  106.         currentFace = currentFace - 1
  107.     end
  108.  
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement