Иконка ресурса

FREE ItemCombiner : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Game.Rust;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("ItemCombiner", "TuNombre", "1.0.0")]
    [Description("Combina armas con skins específicas para obtener una tercera arma")]
    public class ItemCombiner : RustPlugin
    {
        private HashSet<ulong> playersPendingCombine = new HashSet<ulong>();

        // Skins que quieres combinar
        // private ulong skinA = 2970935600;
        // private ulong skinB = 2546031510;

        // // Arma que se combina y el resultado
        // private string weaponShortName = "rifle.ak";
        // private string resultWeaponShortName = "lmg.m249";

        // // Skin del resultado
        // private ulong resultSkin = 2469113740;
        private Dictionary<string, Dictionary<string, string> > interactions;

        private string configPath => $"{Interface.Oxide.DataDirectory}/Interactions.json";

        private Dictionary<string, Dictionary<string, string>> LoadInteractions(string filePath)
        {
            if (!File.Exists(filePath))
            {
                PrintError($"El archivo {filePath} no existe.");
                return new Dictionary<string, Dictionary<string, string>>();
            }

            try
            {
                string json = File.ReadAllText(filePath);
                // Aquí deserializamos directamente un Dictionary<string, ulong>
                var load_interactions = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(json);
                return load_interactions ?? new Dictionary<string, Dictionary<string, string>>();
            }
            catch (System.Exception ex)
            {
                PrintError($"Error cargando JSON: {ex.Message}");
                return new Dictionary<string, Dictionary<string, string>>();
            }
        }

        private void Init()
        {
            interactions = LoadInteractions(configPath);
        }


            object CanStackItem(Item source, Item target)
            {
                var player = source.GetOwnerPlayer();
                if (player == null) return null;

                string key = $"{source.info.shortname}_{source.skin}-{target.info.shortname}_{target.skin}";
                Puts(key);
                if (interactions.TryGetValue(key, out Dictionary<string, string> newSkin))
                {
                    playersPendingCombine.Add(player.userID);
                    // Pasamos la info necesaria a CombineItems usando el timer
                    timer.Once(0f, () => CombineItems(player, target.info.shortname, source.info.shortname, target.skin, source.skin, newSkin));
                    return null; // Bloquea el apilamiento normal
                }

                return null;
            }

       private void CombineItems(BasePlayer player, string targetShortName, string triggerShortName, ulong targetSkin, ulong triggerSkin, Dictionary<string, string> resultSkin)
            {
                if (player == null || !playersPendingCombine.Contains(player.userID)) return;

                playersPendingCombine.Remove(player.userID);

                var container = player.inventory.containerMain;

                var targetItem = FindItemBySkin(container, targetShortName, targetSkin);
                var triggerItem = FindItemBySkin(container, triggerShortName, triggerSkin);

                if (targetItem == null || triggerItem == null) return;

                targetItem.Remove();
                triggerItem.Remove();

                bool res_name = resultSkin.TryGetValue("resultItem", out string newitem_name);
                bool res_skin = resultSkin.TryGetValue("resultSkin", out string newitem_skin);
                Puts($"{res_name} {res_skin}");

                var newItem = ItemManager.CreateByName(newitem_name, 1);
                if (newItem == null) return;

                newItem.skin = ulong.Parse(newitem_skin);
                newItem.MarkDirty();
                newItem.MoveToContainer(container);

                player.ChatMessage($"Has combinado {targetShortName} (skin {targetSkin}) con {triggerShortName} (skin {triggerSkin}) y obtenido un nuevo item con skin {newitem_skin}.");
            }

        private Item FindItemBySkin(ItemContainer container, string shortName, ulong skin)
        {
            if (container == null) return null;

            foreach (var item in container.itemList)
            {
                if (item.info.shortname == shortName && item.skin == skin)
                    return item;
            }
            return null;
        }
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху