TNT_Nolan

TeamMaker 0.2Beta

Mar 14th, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. --Main Function
  2. function init()
  3. startup()
  4. confirm = "n"
  5. number_of_players = 0
  6. while confirm ~= "y" do
  7. number_of_players = getPlayers()
  8. confirm = confirmPlayers(number_of_players)
  9. end
  10. player_names = getPlayerNames(number_of_players)
  11. people_it = getIt()
  12. vconfirm = checkValue(people_it,number_of_players)
  13. if vconfirm == false then
  14. term.clear()
  15. term.setCursorPos(1,1)
  16. term.setTextColor(colors.red)
  17. term.write("Error, invalid numbers")
  18. sleep(2)
  19. else
  20. people_it = tonumber(people_it)
  21. if people_it ~= 1 then
  22. whosit = spinGroup(people_it)
  23. a = table.getn(whosit)
  24. for i=1,a do
  25. term.write("Player #"..whosit[i].." -> "..player_names[whosit[i]].." is it!")
  26. print()
  27. end
  28. sleep(3)
  29. elseif people_it == 1 then
  30. whosit = spinPlayers(number_of_players,people_it)
  31. term.write("Player #"..whosit.." -> "..player_names[whosit].." is it!")
  32. sleep(3)
  33. elseif people_it == 0 then
  34. term.clear()
  35. term.setCursorPos(1,1)
  36. term.setTextColor(colors.red)
  37. term.write("Invalid Numbers!")
  38. sleep(3)
  39. end
  40. term.clear()
  41. end
  42. end
  43. --Puts the startup screen
  44. function startup()
  45. term.clear()
  46. term.setBackgroundColor(colors.gray)
  47. _bt = paintutils.loadImage(shell.dir() .. "/teammakerpaint")
  48. term.setBackgroundColor(colors.gray)
  49. paintutils.drawImage(_bt,1,1)
  50. term.setCursorPos(15,1)
  51. term.setTextColor(colors.lime)
  52. term.setBackgroundColor(colors.gray)
  53. term.write("WHOSIT, 0.2b by TNT_Nolan")
  54. sleep(2.5)
  55. term.setBackgroundColor(colors.black)
  56. end
  57. --Asks for how many players there will be
  58. function getPlayers()
  59. term.clear()
  60. term.setCursorPos(1,1)
  61. term.setTextColor(colors.green)
  62. term.write("How many players?")
  63. term.setTextColor(colors.lime)
  64. term.setCursorPos(1,2)
  65. local number_of_players = read()
  66. tonumber(number_of_players)
  67. return number_of_players
  68. end
  69. function checkValue(a,b)
  70.  
  71. if a == b then
  72. return false
  73. elseif a == 0 then
  74. return false
  75. elseif a ~= b then
  76. return true
  77. end
  78. end
  79. --Asks how many people will be it
  80. function getIt()
  81. term.clear()
  82. term.setCursorPos(1,1)
  83. term.setTextColor(colors.green)
  84. term.write("How many people will be it?")
  85. term.setTextColor(colors.lime)
  86. term.setCursorPos(1,2)
  87. local people_it = read()
  88. tonumber(people_it)
  89. return people_it
  90. end
  91. --Confirms the amount of players they put
  92. function confirmPlayers(players)
  93. term.clear()
  94. term.setCursorPos(1,1)
  95. term.setTextColor(colors.green)
  96. term.write(number_of_players.." players correct? [y/n]")
  97. term.setCursorPos(1,2)
  98. term.setTextColor(colors.lime)
  99. local confirm = read()
  100. return confirm
  101. end
  102. --Asks for the player's names'
  103. function getPlayerNames(number_of_players)
  104. term.clear()
  105. term.setCursorPos(1,1)
  106. term.setTextColor(colors.green)
  107. a = {}
  108. for i=1,number_of_players do
  109. term.write ("Enter name for Player #"..i..": ")
  110. a[i]= read()
  111. end
  112. return a
  113. end
  114. --If the input is only one player it this function will be called
  115. function spinPlayers(number_of_players)
  116. local whosit = math.random(1,number_of_players)
  117. return whosit
  118. end
  119. --If the input is more than one players it this function will run
  120. function spinGroup(number_of_players)
  121. local peopleit = {}
  122. for i=1,number_of_players do
  123. index = math.random(1,number_of_players)
  124.  
  125. while (has_value(peopleit,index)) do
  126. index = math.random(1,number_of_players)
  127. end
  128. peopleit[i] = index
  129. end
  130. return peopleit
  131. end
  132.  
  133. function has_value(array,item)
  134. for i=1, table.getn(array) do
  135. if array[i] == item then
  136. return true
  137. end
  138. return false
  139. end
  140. end
  141. --Call Init
  142. init()
Advertisement
Add Comment
Please, Sign In to add comment