Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- math.randomseed(tick())
- -- Table of Chest Models found within the workspace
- local chests = {}
- local activeChests = {}
- local mostRecentChest = nil
- local chestStorage = game.Workspace:WaitForChild("Chests")
- local MIN_MONEY_REWARD = 200 -- 200 beli
- local MAX_MONEY_REWARD = 1000 -- 1000 beli
- local SPAWN_CHANCE_FRUIT = 50 -- 1/50 = 2.0% chance
- local SPAWN_CHANCE_CURSE = 250 -- 1/250 = 0.4% chance
- local SPAWN_CHANCE_POSEIDON = 250 -- 1/250 = 0.4% chance
- local SPAWN_CHANCE_YORU = 250 -- 1/250 = 0.4% chance
- local SPAWN_CHANCE_BISENTO = 250 -- 1/250 = 0.4% chance
- local SPAWN_CHANCE_REAPR = 20000000 -- 1/2000 = 0.05% chance
- local MIN_CHEST_SPAWN_TIME = 30 -- 30 seconds
- local MAX_CHEST_SPAWN_TIME = 60 -- 60 seconds
- local EVENT_MONEY_MULTIPLIER = 1 -- Multiplies the money reward by the value
- function isChestActive(chest)
- for _, activeChest in ipairs(activeChests) do
- if activeChest == chest then
- return true
- end
- end
- return false
- end
- function generateRandomName()
- local name = ""
- for i = 1,math.random(8, 60) do
- name = name .. string.char(math.random(33, 126))
- end
- print("Generated name: " .. name)
- return name
- end
- function assignChests()
- for _, chest in pairs(chestStorage:GetChildren()) do
- if chest.Name == "Chest" then
- for _, piece in pairs(chest:GetChildren()) do
- piece.Locked = true
- chest.Name = generateRandomName()
- end
- table.insert(chests, chest)
- end
- end
- end
- function giveFruit(player, fruitType)
- local fruits = game.ServerScriptService.DFPurchase:FindFirstChild(fruitType)
- local num = math.random(1, #fruits:GetChildren())
- if (player) then
- for key, value in pairs(fruits:GetChildren()) do
- if key == num then
- local fruit = value:Clone()
- fruit.CanBeDropped = false
- fruit.Parent = player.Backpack
- end
- end
- end
- end
- function rewardPlayer(player)
- local fruitChance = math.random(1, SPAWN_CHANCE_FRUIT)
- local curseChance = math.random(1, SPAWN_CHANCE_CURSE)
- local poseidonChance = math.random(1, SPAWN_CHANCE_POSEIDON)
- local yoruChance = math.random(1, SPAWN_CHANCE_YORU)
- local bisentoChance = math.random(1, SPAWN_CHANCE_BISENTO)
- local reaprChance = math.random(1, SPAWN_CHANCE_REAPR)
- local moneyReward = math.random(MIN_MONEY_REWARD, MAX_MONEY_REWARD)
- if (player) then
- if (reaprChance == math.floor(SPAWN_CHANCE_REAPR / 2)) then
- local gui = script.ReaperDrop:Clone()
- local mFrame = gui.MainFrame
- local userId = tostring(player.UserId)
- local userNm = player.Name
- -- last 2 digits of id reversed - ascii code of first letter -
- -- letter of ascii code 65 + username length - first 2 digits of id reversed
- mFrame.Code.Text = string.upper(string.sub(string.reverse(userId), 1, 2) .. "-"
- .. string.byte(userNm, 1) .. "-"
- .. string.char(64 + string.len(userNm)) .. "-"
- .. string.reverse(string.sub(userId, 1, 2)))
- mFrame.UserId.Text = userId
- mFrame.Username.Text = userNm
- gui.Parent = player.PlayerGui
- wait(1)
- mFrame.Closer.Disabled = false
- elseif (curseChance == math.floor(SPAWN_CHANCE_CURSE / 2)) then
- if player.PlayerGui:FindFirstChild("CursedKatanaDrop") == nil then
- script.CursedKatanaDrop:Clone().Parent = player.PlayerGui
- end
- elseif (poseidonChance == math.floor(SPAWN_CHANCE_POSEIDON / 2)) then
- if player.PlayerGui:FindFirstChild("PoseidonDrop") == nil then
- script.PoseidonDrop:Clone().Parent = player.PlayerGui
- end
- elseif (yoruChance == math.floor(SPAWN_CHANCE_YORU / 2)) then
- if player.PlayerGui:FindFirstChild("YoruDrop") == nil then
- script.YoruDrop:Clone().Parent = player.PlayerGui
- end
- elseif (bisentoChance == math.floor(SPAWN_CHANCE_BISENTO / 2)) then
- if player.PlayerGui:FindFirstChild("BisentoDrop") == nil then
- script.BisentoDrop:Clone().Parent = player.PlayerGui
- end
- elseif (fruitChance == math.floor(SPAWN_CHANCE_FRUIT / 2)) then
- local num = math.random(1, 10)
- if (num == 10) then
- giveFruit(player, "Logia")
- elseif num >= 7 then
- giveFruit(player, "Paramecia")
- else
- giveFruit(player, "Zoan")
- end
- else
- if (player:FindFirstChild("Data") and player.Data:FindFirstChild("Money")) then
- player.Data.Money.Value = player.Data.Money.Value + math.floor(moneyReward * EVENT_MONEY_MULTIPLIER)
- end
- end
- end
- end
- function openChest(chest)
- -- Open the chest
- for i = 1, 9 do
- if chest["po" .. i] then
- chest["po" .. i].Transparency = 1
- end
- end
- for i = 1,13 do
- chest["pp" .. i].Transparency = 0
- end
- wait(1)
- hideTreasure(chest)
- end
- function hideTreasure(chest)
- chest.pp2.Transparency = 1
- chest.pp3.Transparency = 1
- chest.pp4.Transparency = 1
- chest.pp5.Transparency = 1
- chest.pp6.Transparency = 1
- chest.pp7.Transparency = 1
- chest.pp8.Transparency = 1
- chest.pp13.Transparency = 1
- end
- function removeChest(chest)
- wait(2)
- for i = 1,13 do
- chest["pp" .. i].Transparency = 1
- end
- mostRecentChest = chest
- for key, activeChest in ipairs(activeChests) do
- if chest == activeChest then
- table.remove(activeChests, key)
- return
- end
- end
- end
- function activateChest(chest)
- local claimed = false
- chest.Name = generateRandomName()
- table.insert(activeChests, chest)
- for i = 1,9 do
- chest["po" .. i].Transparency = 0
- end
- local connection = chest.TouchPart.Touched:connect(function(limb)
- if (game.Players:GetPlayerFromCharacter(limb.Parent) and limb.Parent:FindFirstChild("Humanoid")
- and limb.Parent.Humanoid.Health > 0 and not claimed) then
- claimed = true
- openChest(chest)
- rewardPlayer(game.Players:GetPlayerFromCharacter(limb.Parent))
- removeChest(chest)
- end
- end)
- print("Chest spawned! Total active chests in server: " .. table.getn(activeChests))
- repeat wait(3) until claimed
- connection:disconnect()
- end
- function manageChests()
- while (wait(math.random(MIN_CHEST_SPAWN_TIME, MAX_CHEST_SPAWN_TIME))) do
- chestStorage.Name = generateRandomName()
- repeat wait(1) until table.getn(activeChests) < (table.getn(chests) / 2) -- Only 50% of all chests can be active at once
- local chest = nil
- repeat chest = chests[math.random(1, table.getn(chests))] wait() until not isChestActive(chest) and chest ~= mostRecentChest
- local routine = coroutine.create(activateChest)
- coroutine.resume(routine, chest)
- end
- end
- wait(10)
- game.Workspace.ChildAdded:connect(function(object)
- if object.Name == "Chest" then
- object:Destroy()
- end
- end)
- assignChests()
- manageChests()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement