【发布时间】:2021-12-29 00:54:44
【问题描述】:
我正在尝试获取 player.userID 在列表中显示的次数,但我似乎无法弄清楚如何,我已经在互联网上搜索了一个小时。
class ConfigData
{
[JsonProperty(PropertyName = "Ban")]
public uint ban = 3;
[JsonProperty(PropertyName = "Kick")]
public uint kick = 2;
[JsonProperty(PropertyName = "Banned Message")]
public string kickMessage = "You are banned";
}
class StoredData
{
public List<ulong> Reports = new List<ulong>();
public List<ulong> Banned = new List<ulong>();
public List<ulong> Kicked = new List<ulong>();
}
void OnPlayerConnected(BasePlayer player)
{
int count = storedData.Reports.Count(reportedID => reportedID == player.userID);
Puts($"{player.userID} has {count} reports");
if (count >= configData.ban)
{
storedData.Banned.Add(player.userID);
SaveData();
return;
}
if (storedData.Banned.Contains(player.userID))
{
Network.Net.sv.Kick(player.net.connection, rust.QuoteSafe(configData.kickMessage));
return;
}
else
{
return;
}
}
如果需要,我可以发布完整的代码。
【问题讨论】:
-
你不是说
>= configData.ban吗? -
storedData.Reports是什么列表?这些项目是否具有UserId属性? -
不,如果它的 == 到那个,那么它会禁止玩家,但计数会这样说。 i.imgur.com/UrvJLCQ.png
-
@TheReality 欢迎来到 Stack Overflow。请通过tour 了解 Stack Overflow 的工作原理,并阅读How to Ask 以了解如何提高问题的质量。然后edit你的问题将你的源代码包含为一个工作minimal reproducible example,它可以被其他人编译和测试。
-
数据是一个ulong列表
标签: c# find-occurrences