guamie

anothertestforargs

May 26th, 2020
1,486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.99 KB | None | 0 0
  1. --Room rewrite
  2. --Is interactive, run with just 'room' for prompts.
  3. --Rednet Logging
  4. --Digs 3 rows at a time, wherever possible.
  5. --Dumps to return-chest OR EnderChest.
  6. --Places slabs if set on bottom AND/OR top
  7. --Can Run from Left or Right Corner
  8. --Can Run from Middle (left or right of even)
  9. --Can Run Inverted (Down)
  10. --Can return a one-line command
  11.  
  12. --eventhorizoncomputer?other bad coputersscifi
  13.  
  14. --  Rednet Channels:
  15.   --  9997  -   All Action Logging
  16.   --  8089  -   Master Action Logging
  17.   --  666   -   Master Command Channel
  18.   --  69    -   Turtle-Interlink Channel
  19.   --  420   -   Farm Broadcasts
  20.   --  17    -   Quote of the Day
  21.   --  43    -   WhoIs
  22.   --        -   FuelLevel
  23.   --        -   Inventory Count, Type, table?
  24. --  Rednet Variables
  25.   --  host  -   systemname
  26.   --  loc  -   GPS location
  27.   --  Mod   -   hasmodem t/f
  28.  
  29.  
  30. --Arguments for location and etc.
  31.   --  x     -   Direction directly away
  32.   --  y     -   Direction Left/Right
  33.   --  z     -   Direction Up/Down
  34.   --  -     -   Starting Corner (Just L/R to start; middle squares in v.9000)
  35.   --  -     -   FloorBottom Slab
  36.   --  -     -   FloorTop Slab
  37.   --  -     -   Direction (inversion?)
  38.   --  -     -   Chest (reg,ender,none)
  39.  
  40. --  Start modem & announce self on network.
  41. --  Check GPS Location
  42. --  No GPS == set local location
  43.  
  44. --Move the turtle forward, make sure the turtle actually moves into a free space before moving, attempt to pick up things if attack triggered.
  45. --Rednet(9997)
  46.  
  47. function moveForward()
  48.     if not turtle.forward() then
  49.                 if turtle.detect() then
  50.                         if not turtle.dig() then
  51.                                 print("dig returning false after detect")
  52.                                 return false
  53.                         else
  54.                                 if turtle.forward() == true then
  55.                                         return true
  56.                                 else
  57.                                         return moveForward()
  58.                                 end
  59.                         end
  60.                 else
  61.                         while turtle.attack() do
  62.                                 turtle.suck()
  63.                                 print("Turtle is attacking")
  64.                         end
  65.                         if turtle.forward() == true then
  66.                                 return true
  67.                         else
  68.                                 return moveForward()
  69.                         end
  70.                 end
  71.         else
  72.                 return true
  73.     end
  74. end
  75.  
  76. --Move the turtle down, make sure the turtle actually moves into a free space before moving, attempt to pick up things if attack triggered.
  77. --Rednet(9997)
  78.  
  79. function moveDown()
  80.     if not turtle.down() then
  81.         if turtle.detectDown() then
  82.             if not turtle.digDown() then
  83.                 print("dig down returning false after detect")
  84.                 return false
  85.                         else
  86.                                 turtle.down()
  87.                                 return true
  88.                         end
  89.                 else
  90.                         attack = True
  91.                         while turtle.attackDown() do
  92.                                 turtle.suckDown()
  93.                                 turtle.attackDown()
  94.                                 turtle.suckDown()
  95.                         end
  96.                         turtle.down()
  97.             return true
  98.         end
  99.     else
  100.                 return true
  101.         end
  102. end
  103.  
  104. --Move the turtle up, make sure the turtle actually moves into a free space before moving, attempt to pick up things if attack triggered.
  105. --Rednet(9997)
  106.  
  107. function moveUp()
  108.         if not turtle.up() then
  109.                 if turtle.detectUp() then
  110.                         if not turtle.digUp() then
  111.                                 print("dig up returning false after detect")
  112.                                 return false
  113.                         else
  114.                                 turtle.up()
  115.                                 return true
  116.                         end
  117.         else
  118.             attack = True                  
  119.                         while turtle.attackUp() do
  120.                                 turtle.suckUp()
  121.                                 turtle.attackUp()
  122.                                 turtle.suckUp()
  123.             end
  124.             turtle.up()
  125.             return true
  126.         end
  127.     else
  128.         return true
  129.     end
  130. end
  131.  
  132.  
  133. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  134. --------Time to merge floor and room logic for NEWROOMDIG----------------------------------------------------------------------------------------------------------------------
  135. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  136. --Arguments for location and etc.
  137.   --  Mx     -   Direction directly away
  138.   --  My     -   Direction Left/Right
  139.   --  Mz     -   Direction Up/Down
  140.   --  Ms     -   Starting Corner (Just L/R to start; middle squares in v.9000)
  141.   --  Sb     -   FloorBottom Slab
  142.   --  St     -   FloorTop Slab
  143.   --  Mq     -   Direction (inversion?)
  144.   --  Mc     -   Chest (reg,ender,none)
  145.  
  146.  
  147. MYx=0
  148. MYy=0
  149. MYz=0
  150. MYs = null
  151. Sb=0
  152. St=0
  153. Mq = null
  154. Mc = null
  155. direction = true
  156. interactive = "blarg"
  157.  
  158. local tArgs = {...}
  159.  
  160. --Interactive mode if the flags aren't what is expected.  
  161. --Task:Optional Parameters? Presets? Logic to set (if only x, y = x, z= x, etc)
  162.  
  163. if #tArgs ~= 8 then
  164.     print("\n   Arguments are invalid.\n\n     Starting in your face interface.")
  165.  
  166. --Set Myx
  167.  
  168. while MYx==0 do
  169.   print("Input X, directly away.")
  170.   n = tonumber(read())
  171.   MYx = n
  172.   if type(n) == "number" then
  173.     print("X has been set to"..MYx)
  174.   end
  175. end
  176.  
  177. --Set MYy
  178. while MYy==0 do
  179.   print("Input Y, direction left/right.")
  180.   n = tonumber(read())
  181.   MYy = n
  182.   if type(n) == "number" then
  183.     print("Y has been set to"..MYy)
  184.   end
  185. end
  186.  
  187. --Set MYz
  188. while MYz==0 do
  189.   print("Input Z, direction up/down/")
  190.   n = tonumber(read())
  191.   MYz = n
  192.   if type(n) == "number" then
  193.     print("Z has been set to"..MYz)
  194.   end
  195. end
  196.  
  197. --Set MYs
  198. while MYs==null do
  199.   print("Build Left or Right?")
  200.   n = tonumber(read())
  201.   MYs = n
  202.   if type(n) == "number" then
  203.     print("Starting corner has been set to"..MYs)
  204.   end
  205. end
  206.  
  207. --Set Sb
  208. while Sb==0 do
  209.   print("Build slab floor?")
  210.   n = tonumber(read())
  211.   Sb = n
  212.   if type(n) == "number" then
  213.     print("Slab floor has been set to"..Sb)
  214.   end
  215. end
  216.  
  217. --Set St
  218. while St==0 do
  219.   print("Build slab roof?")
  220.   n = tonumber(read())
  221.   St = n
  222.   if type(n) == "number" then
  223.     print("Slab floor has been set to"..St)
  224.   end
  225. end
  226.  
  227. --Set Mq
  228. while Mq==null do
  229.   print("Room (up) or Excavate (down)?")
  230.   n = tonumber(read())
  231.   Mq = n
  232.   if type(n) == "number" then
  233.     print("Room/Excavate has been set to"..Mq)
  234.   end
  235. end
  236.  
  237. --Set Mc
  238. while Mc==null do
  239.   print("Am I using a chest?")
  240.   n = tonumber(read())
  241.   Mc = n
  242.   if type(n) == "number" then
  243.     print("Chest value has been set to"..Mc)
  244.   end
  245. end
  246.  
  247. print("Your combination should be:")
  248. print("room "..MYx.." "..MYy.." "..MYz.." "..MYs.." "..Sb.." "..St.." "..Mq.." "..Mc)
  249.  
  250. --Check fuel before continueing
  251.  
  252. local fuel = turtle.getFuelLevel()
  253. local roomSize = MYx * MYy * MYz
  254. print(roomSize)
  255. while fuel < roomSize do
  256. if not turtle.refuel(1) then
  257. print("Not enough fuel")
  258. return
  259. end
  260. end
  261.  
  262. --shell.run(thestring)
  263. print("Would you like to run now?")
  264.  
  265. repeat
  266. event , param1 = os.pullEvent("char")
  267. if param1 == "y" then
  268. --RUNIT
  269. print("Running room program!")
  270. return
  271. elseif param1 == "n" then
  272. print("Ending.")
  273. return
  274. elseif  param1  ~= ("y"or"a")   then
  275. print ("wrong key")
  276. end
  277. until interactive ~= "blarg"
  278. end
  279.  
  280. local MYx   = tonumber(tArgs[1]) - 1
  281. local MYy   = tonumber(tArgs[2])
  282. local MYz   = tonumber(tArgs[3])
  283. local MYs   = tonumber(tArgs[4])
  284. local Sb    = tonumber(tArgs[5])
  285. local St    = tonumber(tArgs[6])
  286. local Mq    = tonumber(tArgs[7])
  287. local Mc    = tonumber(tArgs[8])
  288. local direction = true
  289.  
  290. for i=1, #tArgs do
  291. print(tArgs[i])
  292. end
  293.      
  294.  
  295.  
  296. --originalroomdig
  297. --local tArgs = {...}
  298. --    if #tArgs ~= 3 then
  299. --      print("Requires length, width, height")
  300. --      return
  301. --    end
  302. --    
  303. --    local x = tonumber(tArgs[1]) - 1
  304. --    local y = tonumber(tArgs[2])
  305. --    local z = tonumber(tArgs[3])
  306. --    
  307. --    if x == nil or y == nil or z == nil then
  308. --      print("Invalid dimensions")
  309. --      return
  310. --    end
  311. --    
  312. --    if x < 0 or y < 0 or z < 0 then
  313. --      print("Invalid (negative) dimensions")
  314. --      return
  315. --    end
  316. --
  317. --
  318. --    
  319. --    local fuel = turtle.getFuelLevel()
  320. --    local roomSize = x * y * z
  321. --    while fuel < roomSize do
  322. --      if not turtle.refuel(1) then
  323. --        print("Not enough fuel")
  324. --        return
  325. --      end
  326. --    end
  327. --
  328. --
  329. --    
  330. --    local direction = true
  331. --    for i = 1, z do
  332. --      for j = 1, y do
  333. --        for k = 1, x do
  334. --      moveForward()
  335. --        end
  336. --        if j < y then
  337. --          if direction then
  338. --            turtle.turnRight()
  339. --          moveForward()
  340. --            turtle.turnRight()
  341. --            direction = false
  342. --          else
  343. --            turtle.turnLeft()
  344. --          moveForward()
  345. --            turtle.turnLeft()
  346. --            direction = true
  347. --          end
  348. --        end
  349. --      end
  350. --      if i < z then
  351. --      moveUp()
  352. --        turtle.turnRight()
  353. --        turtle.turnRight()
  354. --      end
  355. --    end
  356. --    
  357. --    if y % 2 == 0 then
  358. --      turtle.turnRight()
  359. --      for i = 1, y do
  360. --        turtle.forward()
  361. --      end
  362. --      turtle.turnRight()
  363. --    else
  364. --      turtle.turnLeft()
  365. --      for i = 1, y do
  366. --        turtle.forward()
  367. --      end
  368. --      turtle.turnLeft()
  369. --      for i = 1, x do
  370. --        turtle.forward()
  371. --      end
  372. --      turtle.turnRight()
  373. --      turtle.turnRight()
  374. --    end
  375. --    for i = 1, z do
  376. --      turtle.down()
  377. --    end
Add Comment
Please, Sign In to add comment