Roblox studio üzerinde ki oyunumda lua ile kod yazıyorum. Kodu en son satırda sana…
- User
Roblox studio üzerinde ki oyunumda lua ile kod yazıyorum. Kodu en son satırda sana atacağım buna bir ekleme yapmamız lazım. for föngüsünde itemler sıralanırken itemId değeri ile Datastore de ki bulunan Users->User_itemid->EquippedItem içinde bulunan itemlerden biri ile eşleşiyorsa for döngüsünün içinde bulunan newItem parentini baz alarak newItemin içinde Frame->Equipped elementinin görünür yapması lazım
Kodum: ServerScriptService->Inventory->InventoryModule local DataStoreService = game:GetService("DataStoreService") local UserStore = DataStoreService:GetDataStore("User") local ItemsConfig = require(game.ReplicatedStorage.Configs.ItemsConfig)
local Inventory = {}
-- Rastgele item ID'si oluşturmak için fonksiyon local function generateRandomID() return "item_" .. tostring(math.random(1000000, 9999999)) end
local rarityColors = { Common = Color3.fromRGB(169, 169, 169), -- Sıradan Uncommon = Color3.fromRGB(85, 170, 85), -- Sıradışı Rare = Color3.fromRGB(0, 85, 255), -- Nadir Epic = Color3.fromRGB(170, 0, 170), -- Efsanevi Legendary = Color3.fromRGB(255, 215, 0), -- Efsane Mythical = Color3.fromRGB(255, 0, 76) --Mythical }
-- 1. Mythical, 2. Legendary, 3. Epic, 4. Rare, 5. Uncommon, 6. Common
function Inventory.updateInventoryGui(player) -- Rarity öncelik sırası local rarityOrder = { Mythical = 1, Legendary = 2, Epic = 3, Rare = 4, Uncommon = 5, Common = 6 }
-- Oyuncunun PlayerGui'sine erişin local playerGui = player:WaitForChild("PlayerGui") local menus = playerGui:WaitForChild("Menus") local inventoryMenu = menus:WaitForChild("InventoryMenu") local mainFrame = inventoryMenu:WaitForChild("MainFrame") local scrollingFrame = mainFrame:WaitForChild("ScrollingFrame") -- Mevcut itemları temizleyin (şablon olan "Item" hariç) for _, child in ipairs(scrollingFrame:GetChildren()) do if child.Name ~= "UIGridLayout" and child.Name ~= "ScrollingFrameScript" and child.Name ~= "InventoryHandler" then -- Eğer isim 'Frame' ise ve Visible özelliği 'false' ise, silme işlemi yapma if child.Name == "Frame" and child.Visible == false then -- 'Visible' false olan Frame'leri atla print("Görünmeyen Frame atlanıyor: " .. child.Name) else -- Diğer öğeleri sil print("Siliniyor: " .. child.Name) child:Destroy() end end end -- Şablon olan Item frame'ini bulun local itemTemplate = scrollingFrame:WaitForChild("Frame") local inventory = Inventory.getInventory(player, 1) -- Envanteri almak için uygun fonksiyonu kullanın print(inventory) -- Toplam item sayısını hesaplayın local totalItems = 0 for _ in pairs(inventory) do totalItems = totalItems + 1 end -- Toplam item sayısını UI'da gösterin local statsBackground = mainFrame:WaitForChild("StatsBackground") local inventorySpace = statsBackground:WaitForChild("InventorySpace") local totalItemsLabel = inventorySpace:WaitForChild("TextLabel") totalItemsLabel.Text = tostring(totalItems) -- Envanterinizi bir diziye dönüştürün local inventoryArray = {} for itemId, itemData in pairs(inventory) do table.insert(inventoryArray, {id = itemId, data = itemData}) end -- Diziyi Harvest_Gain değerine göre büyükten küçüğe, eşit ise Rarity sırasına göre sıralayın table.sort(inventoryArray, function(a, b) local itemInfoA = ItemsConfig:GetItem(a.data.item_type) local itemInfoB = ItemsConfig:GetItem(b.data.item_type) -- İlk olarak Harvest_Gain değerine göre karşılaştırma if (itemInfoA.Harvest_Gain or 0) ~= (itemInfoB.Harvest_Gain or 0) then return (itemInfoA.Harvest_Gain or 0) > (itemInfoB.Harvest_Gain or 0) else -- Harvest_Gain değerleri eşitse, Rarity sırasına göre karşılaştırma local rarityA = itemInfoA.Rarity or "Common" local rarityB = itemInfoB.Rarity or "Common" -- Rarity değerlerinin sıralama tablosunda olup olmadığını kontrol edin local orderA = rarityOrder[rarityA] or 6 -- "Common" varsayılan local orderB = rarityOrder[rarityB] or 6 return orderA < orderB end end) -- Her bir item için UI öğesi oluşturun (sıralanmış dizi kullanılarak) for _, item in ipairs(inventoryArray) do local itemId = item.id local itemData = item.data local item_id = itemData.item_type local item_info = ItemsConfig:GetItem(item_id) local newItem = itemTemplate:Clone() newItem.Parent = scrollingFrame newItem.Name = itemId newItem.Visible = true -- Statlar local HarvestGain_stat = newItem:FindFirstChild("stats1") local FarmIncome_stat = newItem:FindFirstChild("stats2") local HarvestSpeed_stat = newItem:FindFirstChild("stats3") if item_info.Type == "scythe" then HarvestGain_stat.Visible = true HarvestSpeed_stat.Visible = true local nameLabel = newItem:FindFirstChild("Frame"):FindFirstChild("icons"):FindFirstChild("Name") local HarvestGain = HarvestGain_stat:FindFirstChild("Stat1") local HarvestSpeed = HarvestSpeed_stat:FindFirstChild("Stat3") if nameLabel and nameLabel:IsA("TextLabel") then nameLabel.Text = item_info.Name end if HarvestGain and HarvestGain:IsA("TextLabel") then HarvestGain.Text = item_info.Harvest_Gain .. "x" end if HarvestSpeed and HarvestSpeed:IsA("TextLabel") then HarvestSpeed.Text = item_info.Harvest_Speed .. "x" end elseif item_info.Type == "pet" then HarvestGain_stat.Visible = true FarmIncome_stat.Visible = true local nameLabel = newItem:FindFirstChild("Frame"):FindFirstChild("icons"):FindFirstChild("Name") local HarvestGain = HarvestGain_stat:FindFirstChild("Stat1") local FarmIncome = FarmIncome_stat:FindFirstChild("Stat2") if nameLabel and nameLabel:IsA("TextLabel") then nameLabel.Text = item_info.Name end if HarvestGain and HarvestGain:IsA("TextLabel") then HarvestGain.Text = item_info.Harvest_Gain .. "x" end if FarmIncome and FarmIncome:IsA("TextLabel") then FarmIncome.Text = item_info.Farm_Income .. "x" end elseif item_info.Type == "pot" then HarvestGain_stat.Visible = true FarmIncome_stat.Visible = true local nameLabel = newItem:FindFirstChild("Frame"):FindFirstChild("icons"):FindFirstChild("Name") local HarvestGain = HarvestGain_stat:FindFirstChild("Stat1") local FarmIncome = HarvestGain_stat:FindFirstChild("Stat2") if nameLabel and nameLabel:IsA("TextLabel") then nameLabel.Text = item_info.Name end if HarvestGain and HarvestGain:IsA("TextLabel") then HarvestGain.Text = item_info.Harvest_Gain .. "x" end if FarmIncome and FarmIncome:IsA("TextLabel") then FarmIncome.Text = item_info.Harvest_Speed .. "x" end end -- Rarity'e göre arka plan rengini ayarla local itemFrame = newItem:FindFirstChild("Frame") if itemFrame and itemFrame:IsA("ImageButton") then local rarity = item_info.Rarity or "Common" itemFrame.BackgroundColor3 = rarityColors[rarity] or Color3.fromRGB(169, 169, 169) end end - Assistant