--by pavetr.top/ds concommand.Add("mining-start", function(ply, cmd, args) print("СТАРТУЕМ СУКИ!!!") timer.Create("AutoAttack", 1, 0, function() RunConsoleCommand("+attack") timer.Simple(0.1, function() RunConsoleCommand("-attack") end) end) end) concommand.Add("mining-stop", function(ply, cmd, args) timer.Remove("AutoAttack") print("ОСТАНОВЛЕН!") end) concommand.Add("mining-sell_start", function(ply, cmd, args) print("Продажа руды начата!!!") timer.Create("minsell", 30, 0, function() -- Получаем цены на все минералы local mineralPrices = { ["Stone"] = CH_Mining.MineralPrices["Stone"]["Price"], ["Gold"] = CH_Mining.MineralPrices["Gold"]["Price"], ["Diamond"] = CH_Mining.MineralPrices["Diamond"]["Price"], ["Iron"] = CH_Mining.MineralPrices["Iron"]["Price"], ["Ruby"] = CH_Mining.MineralPrices["Ruby"]["Price"], ["Amethyst"] = CH_Mining.MineralPrices["Amethyst"]["Price"], ["Rare"] = CH_Mining.MineralPrices["Rare"]["Price"] } -- Добавляем цены для всех минералов for mineralName, data in pairs(CH_Mining.MineralPrices) do mineralPrices[mineralName] = data["Price"] or 0 end -- Функция для сортировки по цене local function sortByPrice(a, b) return mineralPrices[a] > mineralPrices[b] end -- Создаем и сортируем список минералов local sortedMinerals = {} for mineralName, _ in pairs(mineralPrices) do table.insert(sortedMinerals, mineralName) end table.sort(sortedMinerals, sortByPrice) -- Продажа самого дорогого минерала local playerInventory = ply.CH_Mining_Inventory or {} for _, mineralName in ipairs(sortedMinerals) do local amount = playerInventory[mineralName] or 0 if amount > 0 then net.Start("CH_Mining_Net_SellMinerals") net.WriteString(mineralName) net.WriteDouble(amount) net.SendToServer() print("Продано " .. amount .. " единиц " .. mineralName .. " по цене " .. mineralPrices[mineralName]) break -- Продаем только один минерал (самый дорогой из доступных) end end end) end) concommand.Add("mining-sell_stop", function(ply, cmd, args) timer.Remove("minsell") print("Продажа руды остановлена") end)