Hello,
Would it be possible to add a delay when turning off/on over x amount of turrets? I see a previous comment about 50 turrets so I tried it, was losing around 15FPS. I added a delay of 750ms in the foreach loop and it seems much better - but I'm not a coder, so I don't know if this is a good way of doing it.
using System.Threading.Tasks;public async void ToggleTurretsInTcRange(BasePlayer player, string arg)
{
List<AutoTurret> turretList = Pool.GetList<AutoTurret>();
foreach (AutoTurret turret in BaseNetworkable.serverEntities.OfType<AutoTurret>())
{
if (turret?.GetBuildingPrivilege()?.IsAuthed(player) == true && turret.GetBuildingPrivilege() == player.GetBuildingPrivilege() == true)
{
turretList.Add(turret);
}
}
if (turretList.Count < 1)
{
return;
}
foreach (AutoTurret turret in turretList)
{
if (arg == "on")
{
PowerTurretOn(turret);
}
else
{
PowerTurretOff(turret);
}
await Task.Delay(750);
}
player.ChatMessage(_instance.Lang("TurretsToggled", player.UserIDString, turretList.Count));
Pool.FreeList(ref turretList);
}