Advertisement
KINGOFCOOL

Untitled

Jan 9th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.73 KB | None | 0 0
  1. --[[NOTES]]--
  2. --[[
  3.  
  4. This minigame script takes all of the minigames under game.Lighting.Choices as models.
  5. The minigames need to have the following things:
  6.  
  7. **A wait time of 7 seconds at the beginning in the game's game script. (states stuff to players)
  8. **A miniature game script (obviously)
  9. **An StringValue called Winner (tells who won this thingy)
  10. **A script or some method that can tell who won, and adds the winner's name to the StringValue "Winner"
  11. **A Color3 Value called Ambience (change the theme/element of the place)
  12. **A part(s) called Spawn (players will spawn here)
  13. **A StringValue called Objective (a game message)
  14. **A StringValue called Instructions (a hint)
  15. **An IntValue called TimeLimit (a time limit)
  16. **A BoolValue called KillAllIfNotFinished (check this if you want everyone to fail if time runs out)
  17.  
  18. Other things:
  19.  
  20. **People who are playing the minigames have the intvalue called "Playing" in their character.
  21. **Comes with a minigame choice system
  22. ]]--
  23. --[[DECLARATIONS]]--
  24.  
  25. chooser = game.Workspace.ChosenMinigame
  26. chooserdebounce = game.Workspace.MinigameChoices.Debounce
  27. elevator = game.Workspace["Choose Next Minigame (50 Coins)"].Head
  28. elevatordebounce = false
  29.  
  30. choosing = false
  31. finished = false
  32.  
  33. --toys = game.Workspace.Toys:clone()
  34.  
  35. local SlashSound = Instance.new("Sound")
  36. SlashSound.SoundId = "rbxasset://sounds\\swordslash.wav"
  37. SlashSound.Parent = game.Workspace
  38. SlashSound.Volume = .1
  39. SlashSound.Name = "Slash"
  40.  
  41. local Yay = Instance.new("Sound")
  42. Yay.SoundId = "http://www.roblox.com/asset/?id=1079839"
  43. Yay.Parent = game.Workspace
  44. Yay.Volume = .3
  45. Yay.Name = "Trumpets"
  46.  
  47. minigames = {}
  48. factor = 100
  49.  
  50. mm = game.Lighting.Choices:GetChildren()
  51. for i=1,#mm do
  52. if mm[i].className == "Model" and mm[i]:findFirstChild("PickMe") == nil then
  53. table.insert(minigames,mm[i])
  54. end
  55. end
  56.  
  57. numplayers = game.Workspace.NumPlayers
  58.  
  59. --[[STANDARD STATEMENTS]]--
  60.  
  61. function displayMSG(string, parent, time)
  62. local msg = Instance.new("Message")
  63. msg.Parent = parent
  64. msg.Text = string
  65. wait(time)
  66. msg:remove()
  67. end
  68.  
  69. function displayHINT(string, parent, time)
  70. local msg = Instance.new("Hint")
  71. msg.Parent = parent
  72. msg.Text = string
  73. if time ~= nil then
  74. wait(time)
  75. msg:remove()
  76. end
  77. end
  78.  
  79. function deleteTools()
  80. local stuff = game.Workspace:GetChildren()
  81. for i=1,#stuff do
  82. if stuff[i].className == "Tool" or stuff[i].className == "Hopperbin" then
  83. stuff[i]:remove()
  84. end
  85. end
  86. end
  87.  
  88. function deleteMSG()
  89. local stuff = game.Workspace:GetChildren()
  90. for i=1,#stuff do
  91. if stuff[i].className == "Message" or stuff[i].className == "Hint" then
  92. stuff[i]:remove()
  93. end
  94. end
  95. local players = game.Players:GetChildren()
  96. for i=1,#players do
  97. local m = players[i]:findFirstChild("Message")
  98. local h = players[i]:findFirstChild("Hint")
  99. local things = players[i]:GetChildren()
  100. for i=1,#things do
  101. if things[i].className == "Hint" or things[i].className == "Message" then
  102. things[i]:remove()
  103. end
  104. end
  105. if m ~= nil then m:remove() end
  106. if h ~= nil then h:remove() end
  107. end
  108. end
  109.  
  110.  
  111. --[[PLAYER STATEMENTS--]]
  112.  
  113.  
  114. function getWillingPlayers(places)
  115. local count = 0
  116. local players = game.Players:GetChildren()
  117. for i=1,#players do
  118. if players[i].Character ~= nil then
  119. if players[i].Character:findFirstChild("Spectating") == nil then
  120. count = count + 1
  121. local s = Instance.new("IntValue")
  122. s.Parent = players[i].Character
  123. s.Name = "Playing"
  124. placenum = #places
  125. u = i
  126. if u > placenum then u = 1 end
  127. players[i].Character:moveTo(Vector3.new(places[u].Position.x + math.random(-places[u].Size.x/3, places[u].Size.x/3), places[u].Position.y + 10, places[u].Position.z + math.random(-places[u].Size.z/3, places[u].Size.z/3)))
  128. players[i].Character.Torso.Velocity = Vector3.new(0,0,0)
  129.  
  130. local hoppers = players[i].Backpack:GetChildren()
  131. for x=1,#hoppers do
  132. local cams = hoppers[x]:findFirstChild("SpectateScript")
  133. if cams ~= nil then
  134. cams.Parent:remove()
  135. end
  136. end
  137.  
  138. if players[i]:findFirstChild("Reminder") then
  139. players[i].Reminder:remove()
  140. end
  141. --wait()
  142. end
  143. end
  144. end
  145.  
  146.  
  147. numplayers.Value = count
  148. end
  149.  
  150.  
  151. function checkPlayers()
  152. local count = 0
  153. print("Checking")
  154. local players = game.Players:GetChildren()
  155. for i=1,#players do
  156. if players[i].Character ~= nil then
  157. print("Past a threshold")
  158. if players[i].Character:findFirstChild("Playing") ~= nil then
  159. count = count + 1
  160. end
  161. end
  162. end
  163.  
  164. print("There are " .. count .. " players playing")
  165. if count < 1 or count == nil then
  166. print("Case 1")
  167. return 0
  168. elseif count > 1 then
  169. print("Case 2")
  170. return 1
  171. else
  172. print("Case 3")
  173. return 2
  174. end
  175. return 0
  176. end
  177.  
  178. function getMultiplePlayers()
  179.  
  180. local playersleft = {}
  181.  
  182. local players = game.Players:GetChildren()
  183. for i=1,#players do
  184. if players[i].Character ~= nil then
  185. if players[i].Character:findFirstChild("Playing") ~= nil then
  186. table.insert(playersleft, players[i])
  187. --players[i].leaderstats.Coins.Value = players[i].leaderstats.Coins.Value + (numplayers.Value * 5)
  188. end
  189. end
  190. end
  191.  
  192. local prize = math.ceil((factor/#playersleft) * (math.random(100, 140) * .01))
  193.  
  194. displayMSG("Multiple users have beaten the minigame!", game.Workspace, 3)
  195. displayMSG("They each get " .. prize .. " coins!", game.Workspace, 3)
  196.  
  197. for i=1,#playersleft do
  198. if playersleft[i] ~= nil then
  199. playersleft[i].leaderstats.Coins.Value = playersleft[i].leaderstats.Coins.Value + (prize)
  200. end
  201. end
  202.  
  203. end
  204.  
  205. function killAll()
  206. print("Kill em all!")
  207. local players = game.Players:GetChildren()
  208. for i=1,#players do
  209. if players[i].Character ~= nil then
  210. if players[i].Character:findFirstChild("Playing") ~= nil then
  211. print("...")
  212. players[i].Character.Humanoid.Health = 0
  213. end
  214. end
  215. end
  216. end
  217.  
  218. function reachForPlayers()
  219. if game.Players:findFirstChild("Player") ~= nil and game.Workspace.TestingMode.Value == true then return true end
  220.  
  221. guys = {}
  222.  
  223. local players = game.Players:GetChildren()
  224. for i=1,#players do
  225. if players[i].Character ~= nil then
  226. if players[i].Character:findFirstChild("Spectating") == nil then
  227. table.insert(guys, players[i])
  228. end
  229. end
  230. end
  231.  
  232. for i=1,#guys do
  233. print("There are " .. #guys .. " players here.")
  234. if #guys < 2 or #guys == nil then
  235. displayHINT("Two or more people are needed to play minigames.", game.Workspace, 3)
  236. return false
  237. else
  238. return true
  239. end
  240. end
  241. end
  242.  
  243. function checkNumber() --This function tells the amount of players that are playing the minigame every second. If it's 1 player, the player wins.
  244. local count = 0
  245. local players = game.Players:GetChildren()
  246. for i=1,#players do
  247. if players[i].Character ~= nil then
  248. --if players[i].Name == "Player" then break end
  249. --print("??")
  250. --print(#players)
  251. if players[i].Character:findFirstChild("Playing") ~= nil then
  252. --print("?")
  253. count = count + 1
  254. end
  255.  
  256. end
  257. end
  258.  
  259. if count < 1 or count == nil then --Everyone lost...
  260. time.Value = 0
  261. elseif count < 2 then--Someone is left
  262. for i=1,#players do--Find that player
  263. if players[i].Character ~= nil then
  264. if players[i].Character:findFirstChild("Playing") ~= nil then
  265. win.Value = players[i].Name
  266. end
  267. end
  268. end
  269. end
  270.  
  271.  
  272.  
  273. end
  274.  
  275. function checkPlayerSubScores()
  276. local players = game.Players:GetChildren()
  277. for i=1,#players do
  278. if players[i].Character ~= nil then
  279. --if players[i].Name == "Player" then break end
  280. end
  281. end
  282. end
  283.  
  284. --[[MINIGAME STATEMENTS]]--
  285.  
  286.  
  287. function chooseMinigame()
  288.  
  289. --print(table.maxn(minigames))
  290. --if table.maxn(minigames) < 1 then
  291. --refill list
  292. minigames = {}
  293.  
  294. mm = game.Lighting.Choices:GetChildren()
  295. for i=1,#mm do
  296. if mm[i].className == "Model" and mm[i]:findFirstChild("PickMe") == nil then
  297. table.insert(minigames,mm[i])
  298. end
  299. end
  300. --end
  301.  
  302. if game.Workspace.ChosenMinigame.Value == "None" then
  303. local randommultiplier = math.random(80,100)
  304. local t = .01
  305. local pick = math.random(1,#minigames)
  306. local times = 0
  307. while true do -- The following just makes minigame picking fun
  308. SlashSound:play()
  309. if pick > #minigames then
  310. pick = 1
  311. end
  312.  
  313. local m = (minigames[pick]) -- (colors[math.random(1,#colors)])
  314. displayHINT("--> " .. m.Name .. " <--", game.Workspace, t)
  315. times = times + 1
  316.  
  317. if times > 15 then
  318. t = t*2
  319. times = 0
  320. print("Slower")
  321. end
  322.  
  323. randommultiplier = randommultiplier - 1
  324.  
  325. if randommultiplier < 1 then
  326. print(minigames[pick].Name .. ", " .. m.Name)
  327. table.remove(minigames, pick) --no repeating
  328. return m
  329. end
  330.  
  331. pick = pick + 1
  332.  
  333. --SlashSound:stop()
  334. end
  335. else
  336.  
  337. local m = game.Lighting.Choices:findFirstChild(game.Workspace.ChosenMinigame.Value)
  338. return m
  339. end
  340. end
  341.  
  342. function loadMinigame(mg)
  343. m = mg:clone()
  344. m.GameScript.Disabled = false
  345. m.Parent = game.Workspace
  346. m:makeJoints()
  347. game.Lighting.Ambient = m.Ambience.Value
  348. game.Lighting.TimeOfDay = m.TimeOfDay.Value
  349. displayMSG(m.Objective.Value, game.Workspace, 4) -- Objective
  350. displayHINT(m.Instructions.Value, game.Workspace) -- Instructions
  351. return m
  352. end
  353.  
  354. function deleteMinigame(mg)
  355. if mg ~= nil then
  356. mg:remove()
  357. end
  358. game.Lighting.Ambient = Color3.new(100,100,100)
  359. game.Lighting.TimeOfDay = "14:00:00"
  360. game.Lighting.Brightness = 1
  361. end
  362. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  363. function playMinigame(mg)
  364. time = mg.TimeLimit.Value
  365. game.Workspace.Timer.Value = time
  366. time = game.Workspace.Timer
  367. win = mg.Winner
  368. win.Changed:connect(function(string) endMinigame(string) end)
  369. finished = false
  370. while time.Value > 0 do
  371. time.Value = time.Value - 1
  372. wait(1)
  373. --[[if win.Value ~= "?" then
  374. endMinigame(win.Value)
  375. break
  376. end]]
  377. --print("!")
  378. if game.Workspace.TestingMode.Value == false then
  379. checkNumber()
  380. end
  381. end
  382. if finished == false then
  383. if mg.KillAllIfNotFinished.Value == false then
  384. print("Don't kill everyone")
  385. wait(1)
  386. endMinigame(win.Value)
  387. else
  388. print("Kill everyone")
  389. killAll()
  390. wait(1)
  391. endMinigame("")
  392. end
  393. finished = true
  394. end
  395. end
  396. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  397. function endMinigame(winner) --winner is a string
  398. print("Woot")
  399. finished = true
  400. time.Value = 0
  401. --deleteMSG()
  402. print(winner)
  403. guy = game.Players:findFirstChild(winner)
  404. if guy ~= nil then
  405. print("1 person has won")
  406. guy.leaderstats.Coins.Value = guy.leaderstats.Coins.Value + factor
  407. displayMSG(winner .. " has beaten the minigame! Yay!", game.Workspace, 2)
  408. print("Give him/her coins")
  409. displayMSG(winner .. " has won " .. factor .. " coins!", game.Workspace, 3)
  410. else
  411. --checkPlayerSubScores()
  412. q = checkPlayers() -- is there more than one winner, or is there none?
  413. if q == 0 then
  414. displayMSG("Everyone has lost the game!", game.Workspace, 2)
  415. displayMSG("Coins are not awarded to anyone...", game.Workspace, 2)
  416. elseif q == 1 then
  417. getMultiplePlayers()
  418. print("There really are multiple players")
  419. else
  420. getMultiplePlayers()
  421. print("I hope that you're just testing...")
  422. end
  423. end
  424. end
  425.  
  426. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
  427. --[[ THE FOLLOWING IS FOR CHOOSING A MINIGAME INSTEAD OF RANDOM SELECTION. COMMENT OUT IF IT IS NOT NEEDED--]]
  428. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
  429.  
  430. function noMoreChoosing()
  431. elevatordebounce = true
  432. chooserdebounce.Value = true
  433. elevator.BrickColor = BrickColor.new(26)
  434. elevator.Parent.Part1.BrickColor = BrickColor.new(26)
  435. elevator.Parent.Part2.BrickColor = BrickColor.new(26)
  436. elevator.Parent.Part3.BrickColor = BrickColor.new(26)
  437. elevator.Parent.Name = ""
  438. end
  439.  
  440. function allowChoosing()
  441. elevatordebounce = false
  442. chooserdebounce.Value = false
  443. elevator.BrickColor = BrickColor.new(1)
  444. elevator.Parent.Part1.BrickColor = BrickColor.new(1)
  445. elevator.Parent.Part2.BrickColor = BrickColor.new(1)
  446. elevator.Parent.Part3.BrickColor = BrickColor.new(1)
  447. elevator.Parent.Name = "Choose Next Minigame (50 Coins)"
  448. end
  449.  
  450. function onChanged()
  451. if chooserdebounce.Value == true then
  452. local guy = elevator.Guy.Value
  453. if guy ~= nil then
  454. if guy.Character ~= nil then
  455. local player = game.Players:findFirstChild(guy.Name)
  456. if player then
  457. guy.Character:moveTo(game.Workspace.Z.Position)
  458. player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 50
  459. elevator.Guy.Value = nil
  460. end
  461. end
  462. end
  463. end
  464. end
  465.  
  466. game.Workspace.MinigameChoices.Debounce.Changed:connect(onChanged)
  467.  
  468. function onTouch(part)
  469. if part.Parent ~= nil then
  470. h = part.Parent:findFirstChild("Humanoid")
  471. if h ~= nil and elevatordebounce == false then
  472. if h.Parent:findFirstChild("Torso") ~= nil then
  473. player = game.Players:findFirstChild(h.Parent.Name)
  474. if player ~= nil then
  475. if player.leaderstats.Coins.Value >=50 then
  476.  
  477. elevatordebounce = true
  478. elevator.BrickColor = BrickColor.new(26)
  479. elevator.Parent.Part1.BrickColor = BrickColor.new(26)
  480. elevator.Parent.Part2.BrickColor = BrickColor.new(26)
  481. elevator.Parent.Part3.BrickColor = BrickColor.new(26)
  482. elevator.Parent.Name = ""
  483. chooserdebounce.Value = false
  484.  
  485. local bp = Instance.new("BodyPosition")
  486. bp.Parent = h.Parent.Torso
  487. bp.position = elevator.Position + Vector3.new(0,20,0)
  488. bp.maxForce = Vector3.new(1000000000,1000000000,1000000000)
  489. elevator.Parent.Barrier.CanCollide = false
  490. elevator.Parent.Barrier.Transparency = 1
  491.  
  492. elevator.Guy.Value = player
  493.  
  494. wait(1)
  495. if player ~= nil then
  496.  
  497. bp:remove()
  498. elevator.Parent.Barrier.CanCollide = true
  499. elevator.Parent.Barrier.Transparency = .5
  500.  
  501. local hinty = Instance.new("Message")
  502. hinty.Parent = game.Workspace
  503. hinty.Text = h.Parent.Name .. " is choosing the next minigame..."
  504. wait(4)
  505. hinty:remove()
  506. end
  507.  
  508. end
  509. end
  510. end
  511. end
  512. end
  513. end
  514.  
  515. elevator.Touched:connect(onTouch)
  516.  
  517.  
  518. function onControllerChanged()
  519. if game.Workspace.Controller.Value == nil then
  520. game.Workspace.Timer.Value = 0
  521. end
  522. end
  523.  
  524. game.Workspace.Controller.Changed:connect(onControllerChanged)
  525.  
  526. --[[ THE MAIN LOOP ]]--
  527.  
  528. allowChoosing()
  529.  
  530. while true do
  531. wait(3)
  532. if reachForPlayers() == true then
  533. wait(1)
  534.  
  535. if chooserdebounce.Value == false and elevatordebounce == true then
  536. displayHINT("The next minigame is being chosen by a player (20 more seconds for him/her to choose)...", game.Workspace, 20)
  537. noMoreChoosing()
  538. else
  539. noMoreChoosing()
  540. displayHINT("Choosing a minigame...", game.Workspace, 2)
  541. end
  542.  
  543. local m = chooseMinigame()
  544. game.Workspace.ChosenMinigame.Value = "None"
  545. displayHINT(" --> " .. m.Name .. " <-- ", game.Workspace, .8) -- sound laggg
  546. Yay:play()
  547. displayHINT("--> " .. m.Name .. " <--", game.Workspace, .4)
  548. displayHINT(" --> " .. m.Name .. " <-- ", game.Workspace, .4)
  549. displayHINT("--> " .. m.Name .. " <--", game.Workspace, .4) -- Just showing that it picked a minigame
  550. displayHINT(" --> " .. m.Name .. " <-- ", game.Workspace, .4)
  551. displayHINT("--> " .. m.Name .. " <--", game.Workspace, .4)
  552. displayHINT(" --> " .. m.Name .. " <-- ", game.Workspace, .4)
  553. wait(1)
  554. displayMSG(m.Name .. " will start soon.", game.Workspace, 3)
  555. --Hint(m.Name .. " ~~ Origin: " .. m.Origin.Value .. ".
  556.  
  557. if game.Workspace:findFirstChild("Toys") ~= nil then game.Workspace.Toys:remove() end
  558.  
  559. wait(1)
  560. print("Getting teh minigame")
  561. m = loadMinigame(m)
  562. print("Getting teh players")
  563. wait(1)
  564.  
  565. sp = {}
  566. local spawns = m:GetChildren()
  567. for i=1,#spawns do
  568. if spawns[i].Name == "Spawn" then
  569. table.insert(sp,spawns[i])
  570. end
  571. end
  572.  
  573. game.Workspace.Controller.Value = nil
  574.  
  575. getWillingPlayers(sp)
  576.  
  577. displayMSG("Ready?", game.Workspace, 2)
  578. displayMSG("Go!", game.Workspace, .5)
  579. wait(1) --The game script in the minigame would go now
  580.  
  581. --local t = toys:clone()
  582. --t.Parent = game.Workspace
  583.  
  584. allowChoosing()
  585.  
  586. playMinigame(m)
  587.  
  588. deleteMinigame(m)
  589.  
  590. game.Workspace.Controller.Value = nil
  591.  
  592. killAll()
  593.  
  594. deleteMSG()
  595.  
  596. deleteTools()
  597.  
  598. displayHINT("The next minigame will begin shortly.", game.Workspace, 30)
  599. print("Rinse, lather, and repeat")
  600.  
  601. game.Workspace.NumPlayers.Value = 0
  602. end
  603. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement