ravneravn

casinoSorter

May 20th, 2013
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- 4 = -x
  2. -- 3 = +z
  3.  
  4. disk = peripheral.wrap("left")
  5. sort = peripheral.wrap("bottom")
  6. diamond = 264
  7. gold = 266
  8. nugget = 371
  9. credits = 0
  10. floppy = 4257
  11. id = 18
  12.  
  13.  
  14.  
  15. function sendTurtleBack()
  16. rednet.open("right")
  17. rednet.send(id, "go")
  18. end
  19.  
  20. function readCredits()
  21. file = fs.open("/disk/credits", "r")
  22. cashOutCredits = file.readLine()
  23. file.close()
  24. end
  25.  
  26.  
  27. function writeCredits()
  28. file = fs.open("/disk/credits", "w")
  29. file.write(tostring(credits))
  30. file.close()
  31. credits = 0
  32. end
  33.  
  34. function getDisk()
  35. sort.extract(3, 4257, 5, 1)
  36. sleep(2)
  37. writeCredits()
  38. rednet.send(22, "go")
  39. end
  40.  
  41. function exchange()
  42. numberOfDiamonds = math.floor(cashOutCredits / 50)
  43. sort.extract(3, 264, 2, numberOfDiamonds)
  44.  
  45. cashOutCredits = cashOutCredits - numberOfDiamonds*50
  46. numberOfIngots = math.floor(cashOutCredits / 10)
  47. sort.extract(3, 266, 2, numberOfIngots)
  48.  
  49. cashOutCredits = cashOutCredits - numberOfIngots*10
  50. numberOfNuggets = cashOutCredits
  51. sort.extract(3, 371, 2, numberOfNuggets)
  52. end
  53.  
  54.  
  55.  
  56. function resetVariables()
  57. credits = 0
  58. numberOfDiamonds = 0
  59. numberOfIngots = 0
  60. numberOfNuggets = 0
  61. cashOutCredits = 0
  62. credits = 0
  63. end
  64.  
  65. function wait()
  66. event, item, message = os.pullEvent()
  67. if event == "isort_item" and item == 264 then
  68. credits = credits + 50*message
  69. print("Credits = "..credits)
  70. sort.sort(4, message)
  71. print("diamond")
  72.  
  73. elseif event == "isort_item" and item == 266 then
  74. credits = credits + 10*message
  75. print("Credits = "..credits)
  76. sort.sort(4, message)
  77. print("ingot")
  78.  
  79. elseif event == "isort_item" and item == 371 then
  80. credits = credits + 1*message
  81. print("Credits = "..credits)
  82. sort.sort(4, message)
  83. print("nugget")
  84.  
  85. elseif event == "rednet_message" and message == "go" then -- check in
  86. print("signal received, getting disk")
  87. getDisk()
  88. resetVariables()
  89.  
  90. elseif event == "rednet_message" and message == "cashOut" then -- cash out
  91. print("disk received, cashing out")
  92. sort.sort(5, 1)
  93. sleep(2)
  94. readCredits()
  95. sort.extract(5, 4257, 3, 1)
  96. exchange()
  97. sleep(1)
  98. sendTurtleBack()
  99. resetVariables()
  100. end
  101. end
  102.  
  103.  
  104.  
  105. while true do
  106. rednet.open("right")
  107. wait()
  108. end
RAW Paste Data