task.wait(3)
local HttpService = game:GetService("HttpService")
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local rollFunc = ReplicatedStorage.RollFunc
local rollR = ReplicatedStorage.Roll
local Chances = require(script.Chances)
local itemRarities = require(script.ItemsRarities)
local recivedLim = game:GetService('ReplicatedStorage').RecivedLimited
local success, response = pcall(HttpService.GetAsync, HttpService, "https://api.rolimons.com/players/v1/playerassets/1")
if not success then
warn("Failed to retrieve player assets:", response)
return
end
local data = HttpService:JSONDecode(response)
if not data or not data.playerAssets then
warn("Invalid player assets data:", response)
return
end
local newAssets = {}
for id, _ in pairs(data.playerAssets) do
table.insert(newAssets, tonumber(id))
end
table.sort(newAssets)
-- Define function to batch process item details and retrieve RAP values
local cachedItemDetails = {} -- Cache for item details
local itemDetailsUrl = "https://www.rolimons.com/itemapi/itemdetails"
local batchSize = 100 -- Number of items to process per batch
local rapValues = {}
local function getItemDetails(itemId)
if cachedItemDetails[itemId] then
return cachedItemDetails[itemId]
else
local apiUrl = itemDetailsUrl .. "?itemids=" .. itemId
local success, response = pcall(HttpService.GetAsync, HttpService, apiUrl)
if success then
local decodedResponse = HttpService:JSONDecode(response)
if decodedResponse and decodedResponse.items then
cachedItemDetails[itemId] = decodedResponse.items[tostring(itemId)]
return cachedItemDetails[itemId]
else
warn("Invalid item details response for item ID:", itemId)
end
else
warn("Failed to retrieve item details for item ID:", itemId)
end
end
end
local function batchProcessItemDetails(itemIds)
local batchSize = 100 -- Number of items to process per batch
local numItems = #itemIds
local rapValues = {}
-- Iterate over items in batches
for i = 1, numItems, batchSize do
local batchIds = {}
for j = i, math.min(i + batchSize - 1, numItems) do
table.insert(batchIds, itemIds[j])
end
-- Process batch
for _, itemId in ipairs(batchIds) do
local itemData = getItemDetails(itemId)
if itemData then
local rap = itemData[3] or 0 -- Default to 0 if RAP is missing
table.insert(rapValues, rap)
else
table.insert(rapValues, 0) -- Placeholder for missing item data
end
end
end
return rapValues
end
-- Function to categorize items into rarity tiers based on RAP values
local function categorizeItemsByRarity(itemIds, rapValues)
-- Clear existing categories in itemRarities module
for rarity, _ in pairs(itemRarities) do
itemRarities[rarity] = {}
end
-- Categorize items into rarity tiers based on RAP thresholds
local numItems = #itemIds
for i = 1, numItems do
local itemId = itemIds[i]
local rap = rapValues[i]
if rap > 0 then
if rap <= 5000 then
table.insert(itemRarities.Common, itemId)
elseif rap <= 10000 then
table.insert(itemRarities.Uncommon, itemId)
elseif rap <= 25000 then
table.insert(itemRarities.Rare, itemId)
elseif rap <= 50000 then
table.insert(itemRarities.Epic, itemId)
elseif rap <= 100000 then
table.insert(itemRarities.Legendary, itemId)
elseif rap <= 250000 then
table.insert(itemRarities.Mythic, itemId)
elseif rap <= 500000 then
table.insert(itemRarities.Relic, itemId)
elseif rap <= 1000000 then
table.insert(itemRarities.Exotic, itemId)
else
table.insert(itemRarities.Stellar, itemId)
end
end
end
end
local function processLimitedItems()
local rapValues = batchProcessItemDetails(newAssets)
categorizeItemsByRarity(newAssets, rapValues)
end
-- Call the function to process limited items and update itemRarities module
processLimitedItems()
local selectedCategorys = {}
local function performMultipleRandomRolls(assets, numRolls)
local results = {}
-- Clear selectedCategorys table before performing new rolls
selectedCategorys = {}
for _ = 1, numRolls do
local totalWeight = 0
local randomValue = math.random() * 161.1601 -- Assuming your probabilities are in percentages
-- Determine the selected category based on the random value
for _, category in ipairs(Chances) do
totalWeight = totalWeight + category[2]
if randomValue <= totalWeight then
table.insert(selectedCategorys, category) -- Insert entire category into selectedCategorys
if #selectedCategorys > 5 then
table.remove(selectedCategorys, 1) -- Remove the oldest entry if more than 5 categories are stored
end
break
end
end
if selectedCategorys[#selectedCategorys][1] then
-- Retrieve the appropriate list of item IDs based on the selected category
local categoryItems = itemRarities[selectedCategorys[#selectedCategorys][1]]
if categoryItems and #categoryItems > 0 then
-- Select a random item ID from the category
local randomIndex = math.random(1, #categoryItems)
local selectedItemId = categoryItems[randomIndex]
table.insert(results, selectedItemId)
else
table.insert(results, nil) -- No items in the selected category
end
else
table.insert(results, nil) -- Invalid category selected
end
end
return results
end
rollFunc.OnServerInvoke = function(player)
local rolls = 5
local selectedAssetIds = performMultipleRandomRolls(newAssets, rolls)
-- Fetch item details
local success1, response1 = pcall(HttpService.GetAsync, HttpService, "https://www.rolimons.com/itemapi/itemdetails")
if not success1 then
warn("Failed to retrieve item details:", response1)
return
end
local decodedResponse = HttpService:JSONDecode(response1)
if not decodedResponse or not decodedResponse.items then
warn("Invalid item details response:", response1)
return
end
local rapValues = {}
local defValues = {}
for i = 1, 5 do
local itemId = selectedAssetIds[i]
if itemId then
local itemData = decodedResponse.items[tostring(itemId)]
if itemData then
local rap = itemData[3]
local defValue = itemData[5]
table.insert(rapValues, rap)
table.insert(defValues, defValue)
else
table.insert(rapValues, 0) -- Placeholder if data is missing
table.insert(defValues, 0)
end
else
table.insert(rapValues, 0) -- Placeholder for nil asset ID
table.insert(defValues, 0)
end
end
-- Fire client event with results
rollR:FireClient(player, selectedAssetIds,rapValues, selectedCategorys, defValues)
end