C#:
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("CloseDoors", "Papa", "1.1.0")]
[Description("Allows admins to close or open all player-placed doors on the server")]
public class CloseDoors : RustPlugin
{
[ChatCommand("closedoors")]
private void CloseAllDoorsCommand(BasePlayer player, string command, string[] args)
{
if (!player.IsAdmin)
{
SendReply(player, "You do not have permission to use this command.");
return;
}
int closedCount = 0;
foreach (var entity in BaseNetworkable.serverEntities)
{
var door = entity as Door;
if (door == null) continue;
if (door.OwnerID == 0) continue;
if (door.IsOpen())
{
door.SetOpen(false);
closedCount++;
}
}
SendReply(player, $"Closed {closedCount} open door(s).");
Puts($"Admin {player.displayName} used /closedoors. {closedCount} door(s) were closed.");
}
[ChatCommand("opendoors")]
private void OpenAllDoorsCommand(BasePlayer player, string command, string[] args)
{
if (!player.IsAdmin)
{
SendReply(player, "You do not have permission to use this command.");
return;
}
int openedCount = 0;
foreach (var entity in BaseNetworkable.serverEntities)
{
var door = entity as Door;
if (door == null) continue;
if (door.OwnerID == 0) continue;
if (!door.IsOpen())
{
door.SetOpen(true);
openedCount++;
}
}
SendReply(player, $"Opened {openedCount} closed door(s).");
Puts($"Admin {player.displayName} used /opendoors. {openedCount} door(s) were opened.");
}
}
}