Вот обновленный код плагина ItemTrading с простеньким GUI для функции OpenTradeGUI:Сделай простенький GUI для OpenTradeGUI
C#:
using System;
using System.Collections.Generic;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("ItemTrading", "YourName", "1.0.0")]
class ItemTrading : RustPlugin
{
private Dictionary<ulong, TradeData> tradeRequests = new Dictionary<ulong, TradeData>();
class TradeData
{
public BasePlayer Initiator;
public BasePlayer Target;
public List<Item> OfferedItems = new List<Item>();
public List<Item> RequestedItems = new List<Item>();
public DateTime ExpirationTime;
public bool IsAccepted;
}
void OpenTradeGUI(BasePlayer initiator, BasePlayer target)
{
CuiElementContainer container = new CuiElementContainer();
string panelName = "tradePanel";
container.Add(new CuiPanel
{
Image = { Color = "0.1 0.1 0.1 0.9" },
RectTransform = { AnchorMin = "0.3 0.3", AnchorMax = "0.7 0.7" },
CursorEnabled = true
}, "Hud.Menu", panelName);
container.Add(new CuiLabel
{
Text = { Text = "Предложенные предметы:", FontSize = 20 },
RectTransform = { AnchorMin = "0.35 0.6", AnchorMax = "0.65 0.7" }
}, panelName);
container.Add(new CuiButton
{
Button = { Command = "trade.accept", Color = "0.2 0.8 0.2 1" },
RectTransform = { AnchorMin = "0.4 0.1", AnchorMax = "0.5 0.2" },
Text = { Text = "Принять", FontSize = 16 }
}, panelName);
container.Add(new CuiButton
{
Button = { Command = "trade.cancel", Color = "0.8 0.2 0.2 1" },
RectTransform = { AnchorMin = "0.6 0.1", AnchorMax = "0.7 0.2" },
Text = { Text = "Отменить", FontSize = 16 }
}, panelName);
CuiHelper.AddUi(initiator, container);
}
void OnTradeOffer(BasePlayer player, List<Item> offeredItems, List<Item> requestedItems)
{
if (tradeRequests.ContainsKey(player.userID))
{
TradeData data = tradeRequests[player.userID];
data.OfferedItems = offeredItems;
data.RequestedItems = requestedItems;
tradeRequests[player.userID] = data;
}
}
void OnTradeAccept(BasePlayer player)
{
if (tradeRequests.ContainsKey(player.userID))
{
TradeData data = tradeRequests[player.userID];
data.IsAccepted = true;
// Обработка принятия трейда
tradeRequests.Remove(player.userID);
}
}
void OnTradeCancel(BasePlayer player)
{
if (tradeRequests.ContainsKey(player.userID))
{
// Обработка отмены трейда
tradeRequests.Remove(player.userID);
PrintToChat(player, "Трейд отменен.");
}
else
{
PrintToChat(player, "У вас нет активного трейда для отмены.");
}
}
[ChatCommand("trade")]
void cmdTrade(BasePlayer player, string command, string[] args)
{
if (args.Length != 1)
{
PrintToChat(player, "Используйте: /trade [цель]");
return;
}
BasePlayer targetPlayer = FindPlayer(args[0]);
if (targetPlayer == null)
{
PrintToChat(player, "Игрок не найден.");
return;
}
OpenTradeGUI(player, targetPlayer);
}
[ChatCommand("canceltrade")]
void cmdCancelTrade(BasePlayer player, string command, string[] args)
{
if (tradeRequests.ContainsKey(player.userID))
{
// Обработка отмены трейда
tradeRequests.Remove(player.userID);
PrintToChat(player, "Трейд отменен.");
}
else
{
PrintToChat(player, "У вас нет активного трейда для отмены.");
}
}
BasePlayer FindPlayer(string targetName)
{
foreach (BasePlayer player in BasePlayer.activePlayerList)
{
if (player.displayName.ToLower().Contains(targetName.ToLower()))
{
return player;
}
}
return null;
}
void OnTick()
{
foreach (var tradeData in new Dictionary<ulong, TradeData>(tradeRequests))
{
if (DateTime.Now >= tradeData.Value.ExpirationTime)
{
PrintToChat(tradeData.Value.Initiator, "Трейд истек.");
PrintToChat(tradeData.Value.Target, "Трейд истек.");
tradeRequests.Remove(tradeData.Key);
}
}
}
}
}
Теперь функция OpenTradeGUI создает простой GUI для обмена предметами между игроками в вашем плагине ItemTrading.