Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1.  
  2. math.randomseed(tick())
  3.  
  4. -- Table of Chest Models found within the workspace
  5. local chests = {}
  6. local activeChests = {}
  7. local mostRecentChest = nil
  8. local chestStorage = game.Workspace:WaitForChild("Chests")
  9.  
  10. local MIN_MONEY_REWARD = 200 -- 200 beli
  11. local MAX_MONEY_REWARD = 1000 -- 1000 beli
  12. local SPAWN_CHANCE_FRUIT = 50 -- 1/50 = 2.0% chance
  13. local SPAWN_CHANCE_CURSE = 250 -- 1/250 = 0.4% chance
  14. local SPAWN_CHANCE_POSEIDON = 250 -- 1/250 = 0.4% chance
  15. local SPAWN_CHANCE_YORU = 250 -- 1/250 = 0.4% chance
  16. local SPAWN_CHANCE_BISENTO = 250 -- 1/250 = 0.4% chance
  17. local SPAWN_CHANCE_REAPR = 20000000 -- 1/2000 = 0.05% chance
  18. local MIN_CHEST_SPAWN_TIME = 30 -- 30 seconds
  19. local MAX_CHEST_SPAWN_TIME = 60 -- 60 seconds
  20. local EVENT_MONEY_MULTIPLIER = 1 -- Multiplies the money reward by the value
  21.  
  22. function isChestActive(chest)
  23. for _, activeChest in ipairs(activeChests) do
  24. if activeChest == chest then
  25. return true
  26. end
  27. end
  28. return false
  29. end
  30.  
  31. function generateRandomName()
  32. local name = ""
  33. for i = 1,math.random(8, 60) do
  34. name = name .. string.char(math.random(33, 126))
  35. end
  36. print("Generated name: " .. name)
  37. return name
  38. end
  39.  
  40. function assignChests()
  41. for _, chest in pairs(chestStorage:GetChildren()) do
  42. if chest.Name == "Chest" then
  43. for _, piece in pairs(chest:GetChildren()) do
  44. piece.Locked = true
  45. chest.Name = generateRandomName()
  46. end
  47. table.insert(chests, chest)
  48. end
  49. end
  50. end
  51.  
  52. function giveFruit(player, fruitType)
  53. local fruits = game.ServerScriptService.DFPurchase:FindFirstChild(fruitType)
  54. local num = math.random(1, #fruits:GetChildren())
  55. if (player) then
  56. for key, value in pairs(fruits:GetChildren()) do
  57. if key == num then
  58. local fruit = value:Clone()
  59. fruit.CanBeDropped = false
  60. fruit.Parent = player.Backpack
  61. end
  62. end
  63. end
  64. end
  65.  
  66. function rewardPlayer(player)
  67.  
  68. local fruitChance = math.random(1, SPAWN_CHANCE_FRUIT)
  69. local curseChance = math.random(1, SPAWN_CHANCE_CURSE)
  70. local poseidonChance = math.random(1, SPAWN_CHANCE_POSEIDON)
  71. local yoruChance = math.random(1, SPAWN_CHANCE_YORU)
  72. local bisentoChance = math.random(1, SPAWN_CHANCE_BISENTO)
  73. local reaprChance = math.random(1, SPAWN_CHANCE_REAPR)
  74. local moneyReward = math.random(MIN_MONEY_REWARD, MAX_MONEY_REWARD)
  75.  
  76. if (player) then
  77. if (reaprChance == math.floor(SPAWN_CHANCE_REAPR / 2)) then
  78. local gui = script.ReaperDrop:Clone()
  79. local mFrame = gui.MainFrame
  80. local userId = tostring(player.UserId)
  81. local userNm = player.Name
  82. -- last 2 digits of id reversed - ascii code of first letter -
  83. -- letter of ascii code 65 + username length - first 2 digits of id reversed
  84. mFrame.Code.Text = string.upper(string.sub(string.reverse(userId), 1, 2) .. "-"
  85. .. string.byte(userNm, 1) .. "-"
  86. .. string.char(64 + string.len(userNm)) .. "-"
  87. .. string.reverse(string.sub(userId, 1, 2)))
  88. mFrame.UserId.Text = userId
  89. mFrame.Username.Text = userNm
  90. gui.Parent = player.PlayerGui
  91. wait(1)
  92. mFrame.Closer.Disabled = false
  93. elseif (curseChance == math.floor(SPAWN_CHANCE_CURSE / 2)) then
  94. if player.PlayerGui:FindFirstChild("CursedKatanaDrop") == nil then
  95. script.CursedKatanaDrop:Clone().Parent = player.PlayerGui
  96. end
  97. elseif (poseidonChance == math.floor(SPAWN_CHANCE_POSEIDON / 2)) then
  98. if player.PlayerGui:FindFirstChild("PoseidonDrop") == nil then
  99. script.PoseidonDrop:Clone().Parent = player.PlayerGui
  100. end
  101. elseif (yoruChance == math.floor(SPAWN_CHANCE_YORU / 2)) then
  102. if player.PlayerGui:FindFirstChild("YoruDrop") == nil then
  103. script.YoruDrop:Clone().Parent = player.PlayerGui
  104. end
  105. elseif (bisentoChance == math.floor(SPAWN_CHANCE_BISENTO / 2)) then
  106. if player.PlayerGui:FindFirstChild("BisentoDrop") == nil then
  107. script.BisentoDrop:Clone().Parent = player.PlayerGui
  108. end
  109. elseif (fruitChance == math.floor(SPAWN_CHANCE_FRUIT / 2)) then
  110. local num = math.random(1, 10)
  111. if (num == 10) then
  112. giveFruit(player, "Logia")
  113. elseif num >= 7 then
  114. giveFruit(player, "Paramecia")
  115. else
  116. giveFruit(player, "Zoan")
  117. end
  118. else
  119. if (player:FindFirstChild("Data") and player.Data:FindFirstChild("Money")) then
  120. player.Data.Money.Value = player.Data.Money.Value + math.floor(moneyReward * EVENT_MONEY_MULTIPLIER)
  121. end
  122. end
  123. end
  124. end
  125.  
  126. function openChest(chest)
  127. -- Open the chest
  128. for i = 1, 9 do
  129. if chest["po" .. i] then
  130. chest["po" .. i].Transparency = 1
  131. end
  132. end
  133. for i = 1,13 do
  134. chest["pp" .. i].Transparency = 0
  135. end
  136. wait(1)
  137. hideTreasure(chest)
  138. end
  139.  
  140. function hideTreasure(chest)
  141. chest.pp2.Transparency = 1
  142. chest.pp3.Transparency = 1
  143. chest.pp4.Transparency = 1
  144. chest.pp5.Transparency = 1
  145. chest.pp6.Transparency = 1
  146. chest.pp7.Transparency = 1
  147. chest.pp8.Transparency = 1
  148. chest.pp13.Transparency = 1
  149. end
  150.  
  151. function removeChest(chest)
  152. wait(2)
  153. for i = 1,13 do
  154. chest["pp" .. i].Transparency = 1
  155. end
  156. mostRecentChest = chest
  157. for key, activeChest in ipairs(activeChests) do
  158. if chest == activeChest then
  159. table.remove(activeChests, key)
  160. return
  161. end
  162. end
  163. end
  164.  
  165. function activateChest(chest)
  166.  
  167. local claimed = false
  168.  
  169. chest.Name = generateRandomName()
  170.  
  171. table.insert(activeChests, chest)
  172.  
  173. for i = 1,9 do
  174. chest["po" .. i].Transparency = 0
  175. end
  176.  
  177. local connection = chest.TouchPart.Touched:connect(function(limb)
  178. if (game.Players:GetPlayerFromCharacter(limb.Parent) and limb.Parent:FindFirstChild("Humanoid")
  179. and limb.Parent.Humanoid.Health > 0 and not claimed) then
  180. claimed = true
  181. openChest(chest)
  182. rewardPlayer(game.Players:GetPlayerFromCharacter(limb.Parent))
  183. removeChest(chest)
  184. end
  185. end)
  186.  
  187. print("Chest spawned! Total active chests in server: " .. table.getn(activeChests))
  188.  
  189. repeat wait(3) until claimed
  190.  
  191. connection:disconnect()
  192. end
  193.  
  194. function manageChests()
  195. while (wait(math.random(MIN_CHEST_SPAWN_TIME, MAX_CHEST_SPAWN_TIME))) do
  196.  
  197. chestStorage.Name = generateRandomName()
  198.  
  199. repeat wait(1) until table.getn(activeChests) < (table.getn(chests) / 2) -- Only 50% of all chests can be active at once
  200.  
  201. local chest = nil
  202.  
  203. repeat chest = chests[math.random(1, table.getn(chests))] wait() until not isChestActive(chest) and chest ~= mostRecentChest
  204.  
  205. local routine = coroutine.create(activateChest)
  206. coroutine.resume(routine, chest)
  207. end
  208. end
  209.  
  210. wait(10)
  211.  
  212. game.Workspace.ChildAdded:connect(function(object)
  213. if object.Name == "Chest" then
  214. object:Destroy()
  215. end
  216. end)
  217.  
  218. assignChests()
  219. manageChests()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement