ravneravn

fusionCasher3

May 2nd, 2013
52
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.  
  40. function getPrize()
  41. open.rednet(mSide)
  42. prize = tonumber(tableAmount[betNum])
  43. prize = prize + prize
  44. rednet.send(sorter, prize)
  45. end
  46.  
  47. function result() -- viser resultatet
  48. if win == 1 then
  49. print("Congratulations, your player won!")
  50. print("If you check the chest you will find your prize in a moment")
  51. getPrize()
  52. print("Thank you for using the FusionCasher")
  53. elseif win == 0 then
  54. print("I'm sorry, your player did not win the race, better luck next time")
  55. print("Thank you for using the FusionCasher")
  56. end
  57. end
  58.  
  59. function checkName()
  60. for i = 1, #tableName do
  61. betNum = i
  62. if tableName[betNum] == logName then
  63. knownName = 1
  64. end
  65. end
  66. end
  67.  
  68. function checkWin() -- tjekker om man har vundet
  69. for i = 1, #tableBetName do
  70. betNum = i
  71. if tableBetName[betNum] == winner then
  72. win = 1
  73. end
  74. end
  75. end
  76.  
  77. function logIn() -- logger in
  78. event, logName = os.pullEvent()
  79. checkName()
  80. if event == "player" and knownName == 1 then
  81. print("Hello "..logName.." welcome to FusionCasher.")
  82. print("Please wait, while I process your bet")
  83. checkWin()
  84. result()
  85. elseif event == "player" and logName ~= knownName then
  86. print("You have not placed a bet yet. To do that please use the FusionBetter.")
  87. print("Thank you for using the FusionCasher")
  88. end
  89. end
  90.  
  91.  
  92.  
  93.  
  94.  
  95. while true do
  96. waitBet()
  97. waitRank()
  98. extractTable()
  99.  
  100. while true do
  101. logIn()
  102.  
  103. if rs.getInput(rsSide) then
  104. break
  105. end
  106. end
  107. end
RAW Paste Data