这是我为游戏中的某个插件编写的一些代码,如果有人能帮助的话,将不胜感激。
namespace Oxide.Plugins
{
[Info("Fake Player Add Plugin", "NOT asmr", 0.0)]
class FakePlayerAddPlugin : CSharpPlugin
{
public int MaximumFakePlayer = 50; //if server has more than x legit players, dont add fakes.
public int PlayerFakeAdd = 43; //how many fake players to add
public float PlayerCheckDelay = 120f; //how often to check for player changes in seconds
void Loaded()
{
Puts("FakePlayerAddPlugin Loaded!");
}
float lasttime = 0f;
void OnFrame(float delta)
{
if (lasttime + PlayerCheckDelay > Time.realtimeSinceStartup) return;
lasttime = Time.realtimeSinceStartup;
var pcount = BasePlayer.activePlayerList?.Count(n => n.IsValid()) ?? 0;
var fcount = BasePlayer.activePlayerList?.Count(n => n == null) ?? 0;
if (pcount >= MaximumFakePlayer)
{
RemoveFakePlayers();
return;
}
if (PlayerFakeAdd > 0 && fcount != PlayerFakeAdd)
{
RemoveFakePlayers();
AddFakePlayers(PlayerFakeAdd);
}
}
public void RemoveFakePlayers()
{
BasePlayer.activePlayerList.RemoveAll(n => n == null);
}
public void AddFakePlayers(int amount)
{
for (int i = 0; i < amount; i++)
{
BasePlayer.activePlayerList.Add(null);
}
}
}
}
我回想的是“成员'System.Collections.Generic.List.Count'不能用作方法或委托”。