Прошу прощения за путаницу. В Rust API обычно используется методError while compiling RustPlugin: 'BasePlayer' does not contain a definition for 'UserID' and no accessible extension method 'UserID' accepting a first argument of type 'BasePlayer' could be found (are you missing a using directive or an assembly reference?) | Line: 21, Pos: 40
UserIDString
для получения идентификатора игрока в виде строки. Попробуйте заменить UserID
на UserIDString
в коде: C#:
using System.Collections.Generic;
namespace YourNamespace
{
public class Plugin
{
private Dictionary<string, (string, List<(string, uint)>)> craftMenu;
void Init()
{
craftMenu = new Dictionary<string, (string, List<(string, uint>)>
{
{ "1", ("Horizontal Barrel", new List<(string, uint)> { ("Wood", 300), ("Metal", 75) }) }
};
}
void OnCommand(BasePlayer player, string command, string[] args)
{
if (command == "dlc")
{
string playerId = player.UserIDString;
if (craftMenu.ContainsKey(playerId))
{
var (itemName, craftingRequirements) = craftMenu[playerId];
string response = $"Craft Menu - {itemName}\n";
response += "---------------------------------\n";
foreach (var (resource, amount) in craftingRequirements)
{
response += $"{resource} x{amount}\n";
}
response += "---------------------------------\n";
SendReply(player, response);
}
else
{
SendReply(player, "No recipes available in the craft menu.");
}
}
}
void OnCraft(BasePlayer player, uint itemId)
{
string playerId = player.UserIDString;
if (craftMenu.ContainsKey(playerId))
{
var (_, craftingRequirements) = craftMenu[playerId];
bool hasRequirements = true;
foreach (var (resource, amount) in craftingRequirements)
{
if (!player.inventory.HasAmount(resource, amount))
{
hasRequirements = false;
break;
}
}
if (hasRequirements)
{
foreach (var (resource, amount) in craftingRequirements)
{
player.inventory.Take(resource, amount);
}
player.inventory.GiveItem(itemId);
SendReply(player, "Crafted successfully!");
}
else
{
SendReply(player, "Not enough resources to craft this item.");
}
}
}
}
}
Попробуйте использовать этот код и дайте мне знать, если у вас возникнут какие-либо дополнительные вопросы или проблемы.