ravneravn

fusionCasher2

May 2nd, 2013
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. knownName = 0
  2. mSide = "left"
  3. sorter = 86
  4. display = 0
  5. better = 84
  6. win = 0
  7. rsSide = "back"
  8.  
  9. function waitBet() -- venter p?? at better sender sin data
  10. rednet.open(mSide)
  11. event, sid, tableName, dis = os.pullEvent("rednet_message")
  12. print("names received")
  13. event, sid, tableAmount, dis = os.pullEvent("rednet_message")
  14. print("amount received")
  15. event, sid, tableBetName, dis = os.pullEvent("rednet_message")
  16. print("betNames received")
  17. end
  18.  
  19. function waitRank() -- venter p?? at ranker sender sine data
  20. rednet.open(mSide)
  21. event, sid, winner, dis = os.pullEvent("rednet_message")
  22. print("winner received")
  23. end
  24.  
  25. function extractTable() -- udpakker de tables som better har sendt
  26. knownNameTable = textutils.unserialize(tableName)
  27. betAmountTable = textutils.unserialize(tableAmount)
  28. betNameTable = textutils.unserialize(tableBetName)
  29. end
  30.  
  31. function count()
  32. tableLength = 0
  33. for i in pairs(tableName) do
  34. tableLength = tableLength+1
  35. return tableLength
  36. end
  37. end
  38.  
  39. function checkWin() -- tjekker om man har vundet
  40. for i = 1, tableLength do
  41. betNum = i
  42. if tableBetName[betNum] == winner then
  43. win = 1
  44. end
  45. end
  46. end
  47.  
  48. function getPrize()
  49. open.rednet(mSide)
  50. prize = tonumber(tableAmount[betNum])
  51. prize = prize + prize
  52. rednet.send(sorter, prize)
  53. end
  54.  
  55. function result() -- viser resultatet
  56. if win == 1 then
  57. print("Congratulations, your player won!")
  58. print("If you check the chest you will find your prize in a moment")
  59. getPrize()
  60. print("Thank you for using the FusionCasher")
  61. elseif win == 0 then
  62. print("I'm sorry, your player did not win the race, better luck next time")
  63. print("Thank you for using the FusionCasher")
  64. end
  65. end
  66.  
  67. function checkName()
  68. count()
  69. for i = 1, tableLength do
  70. betNum = i
  71. if tableName[betNum] == logName then
  72. knownName = 1
  73.  
  74. function logIn() -- logger in
  75. event, logName = os.pullEvent()
  76. checkName()
  77. if event == "player" and knownName == 1 then
  78. print("Hello "..logName.." welcome to FusionCasher.")
  79. print("Please wait, while I process your bet")
  80. checkWin()
  81. result()
  82. elseif event == "player" and logName ~= knownName then
  83. print("You have not placed a bet yet. To do that please use the FusionBetter.")
  84. print("Thank you for using the FusionCasher")
  85. end
  86. end
  87.  
  88.  
  89.  
  90.  
  91.  
  92. while true do
  93. waitBet()
  94. waitRank()
  95. extractTable()
  96.  
  97. while true do
  98. logIn()
  99.  
  100. if rs.getInput(rsSide) then
  101. break
  102. end
  103. end
  104. end
RAW Paste Data