MCFunRide

MC Bank Withdraw

Apr 15th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. --[[
  2. CC-Bank
  3. Copyright Β© 2012 Yingtong Li
  4.  
  5. CC-Bank is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9.  
  10. CC-Bank is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with CC-Bank. If not, see <http://www.gnu.org/licenses/>.
  17. --]]
  18.  
  19. local modemSide = "right"
  20. local clientId = 0
  21. local version = "CC-Bank-0.2.0-Compatible"
  22.  
  23. local function serve()
  24. rednet.open(modemSide)
  25. local senderId, message = rednet.receive()
  26.  
  27. if senderId == clientId then
  28. if string.len(message) >= string.len(version) then
  29. if string.sub(message, 1, string.len(version)) == version then
  30. local bits = textutils.unserialize(string.sub(message, string.len(version) + 1))
  31. local command = bits[1]
  32. local amount = tonumber(bits[2])
  33.  
  34. if command == "WITHDRAW" then
  35. local slot = 1
  36. turtle.select(slot)
  37. for i = 1, amount, 1 do
  38. while turtle.getItemCount(slot) <= 0 do
  39. if slot < 16 then
  40. slot = slot + 1
  41. turtle.select(slot)
  42. else
  43. rednet.send(senderId, "-")
  44. return
  45. end
  46. end
  47.  
  48. turtle.drop(1)
  49. end
  50. rednet.send(senderId, "+")
  51. elseif command == "DEPOSIT" then
  52. -- Depositing cannot be implemented until turtle.suck() takes a number
  53. rednet.send(senderId, "-")
  54. end
  55. end
  56. rednet.send(senderId, "-")
  57. end
  58. end
  59. end
  60.  
  61. while true do
  62. serve()
  63. end
Add Comment
Please, Sign In to add comment