using System.Collections.Generic;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("GuiMenu", "YourNameHere", "0.1.0")]
[Description("Creates a GUI menu on the server")]
public class GuiMenu : RustPlugin
{
private Dictionary<ulong, GuiMenuData> playerMenus = new Dictionary<ulong, GuiMenuData>();
private class GuiMenuData
{
public string[] options;
public string[] responses;
public int currentOption;
public ulong targetPlayerID;
public ulong sourcePlayerID;
public GuiMenuData(string[] options, string[] responses, ulong targetPlayerID, ulong sourcePlayerID)
{
this.options = options;
this.responses = responses;
this.currentOption = 0;
this.targetPlayerID = targetPlayerID;
this.sourcePlayerID = sourcePlayerID;
}
}
private void OnPlayerConnected(BasePlayer player)
{
CuiHelper.DestroyUi(player, "GuiMenu");
}
[ChatCommand("menu")]
private void GuiMenuCommand(BasePlayer player, string command, string[] args)
{
if (args.Length < 3)
{
player.ChatMessage("Usage: /menu <option1,option2,option3,...> <response1,response2,response3,...> <player name>");
return;
}
string[] options = args[0].Split(',');
string[] responses = args[1].Split(',');
string targetPlayerName = args[2];
BasePlayer targetPlayer = BasePlayer.Find(targetPlayerName);
if (targetPlayer == null)
{
player.ChatMessage("Player not found.");
return;
}
ulong targetPlayerID = targetPlayer.userID;
ulong sourcePlayerID = player.userID;
GuiMenuData menuData = new GuiMenuData(options, responses, targetPlayerID, sourcePlayerID);
playerMenus[player.userID] = menuData;
ShowGuiMenu(player, menuData);
}
private void ShowGuiMenu(BasePlayer player, GuiMenuData menuData)
{
CuiElementContainer container = new CuiElementContainer();
float x = 1280f / 2560f;
float y = 720f / 1440f;
float spacing = 0.05f;
for (int i = 0; i < menuData.options.Length; i++)
{
if (i == menuData.currentOption)
{
container.Add(new CuiButton
{
Button = { Color = "1 1 1 1", Command = $"gui_menu_select {i}" },
RectTransform = { AnchorMin = $"{x - 0.2f} {y - spacing * i}", AnchorMax = $"{x + 0.2f} {y - spacing * i + 0.04f}" },
Text = { Text = menuData.options[i], FontSize = 14, Align = TextAnchor.MiddleCenter }
}, "Overlay", "GuiMenuOption" + i);
}
else
{
container.Add(new CuiButton
{
Button = { Color = "0.5 0.5 0.5 1", Command = $"gui_menu_select {i}" },
RectTransform = { AnchorMin = $"{x - 0.2f} {y - spacing * i}", AnchorMax = $"{x + 0.2f} {y - spacing * i + 0.04f}" },
Text = { Text = menuData.options[i], FontSize = 14, Align = TextAnchor.MiddleCenter }
}, "Overlay", "GuiMenuOption" + i);
}
}
CuiHelper.AddUi(player, container, "GuiMenu");
}
[ChatCommand("menu_up")]
private void GuiMenuUpCommand(BasePlayer player, string command, string[] args)
{
if (!playerMenus.ContainsKey(player.userID))
{
return;
}
GuiMenuData menuData = playerMenus[player.userID];
menuData.currentOption = (menuData.currentOption + 1) % menuData.options.Length;
CuiHelper.DestroyUi(player, "GuiMenu");
ShowGuiMenu(player, menuData);
}
[ChatCommand("menu_down")]
private void GuiMenuDownCommand(BasePlayer player, string command, string[] args)
{
if (!playerMenus.ContainsKey(player.userID))
{
return;
}
GuiMenuData menuData = playerMenus[player.userID];
menuData.currentOption = (menuData.currentOption - 1 + menuData.options.Length) % menuData.options.Length;
CuiHelper.DestroyUi(player, "GuiMenu");
ShowGuiMenu(player, menuData);
}
[