ecco7777

lotto

Mar 12th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. p=peripheral.wrap("right")
  2. c=peripheral.wrap("left")
  3. users={}
  4.  
  5. timeHandle=nil
  6. while timeHandle==nil do
  7. timeHandle = http.get("http://www.timeapi.org/utc/in+one+hours")
  8. end
  9. time = timeHandle.readLine()
  10. day=tonumber(time:sub(9, 10))
  11. month=tonumber(time:sub(6, 7))
  12. hour=tonumber(time:sub(12, 13))
  13. minute=tonumber(time:sub(15, 16))
  14. sec=tonumber(time:sub(18, 19))
  15.  
  16. codeChars={"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
  17.  
  18. function saveTab(file,tab)
  19. fp=fs.open(file,"w")
  20. fp.write(textutils.serialize(tab))
  21. fp.close()
  22. end
  23.  
  24. function getTab(file)
  25. fp=fs.open(file,"r")
  26. return textutils.unserialize(fp.readAll())
  27. end
  28.  
  29. if fs.exists(".codes")==false then
  30. codes={}
  31. saveTab(".codes",codes)
  32. end
  33. codes=getTab(".codes")
  34.  
  35. if fs.exists(".account")==false then
  36. account={}
  37. account["No User"]=0
  38. saveTab(".account",account)
  39. end
  40. account=getTab(".account")
  41.  
  42. if fs.exists(".users")==false then
  43. users={}
  44. saveTab(".users",users)
  45. end
  46. users=getTab(".users")
  47.  
  48. function generateCode()
  49. code=codeChars[math.random(1,#codeChars)]
  50. for i=1,3 do
  51. code=code..codeChars[math.random(1,#codeChars)]
  52. end
  53. codes=getTab(".codes")
  54. codes[code]=250
  55. saveTab(".codes",codes)
  56. p.newPage()
  57. p.write(code)
  58. p.endPage()
  59. end
  60.  
  61. function payin()
  62. if codes[io.read()] then
  63. account[user]=250
  64. users[#users+1]=user
  65. saveTab(".account",account)
  66. end
  67. end
  68.  
  69. while true do
  70. event,arg1,arg2,arg3=os.pullEvent()
  71.  
  72. if event=="player" then
  73. user=arg1
  74. c.say("Hallo "..user)
  75. getTab(".account",account)
  76. if account[user]==nil then
  77. c.say("Gebe bitte deinen Code ein um am Lotto teilzunehmen :D")
  78. payin()
  79. else
  80. c.say("Du nimmst breits am Lotto teil")
  81. end
  82. end
  83.  
  84. end
Add Comment
Please, Sign In to add comment