C#:
using UnityEngine;
using Oxide.Core;
using System;
using System.Linq;
using System.Diagnostics;
using System.Threading;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Oxide.Core.Plugins;
using Facepunch;
namespace Oxide.Plugins
{
[Info("Turret Power", "famusov", "0.0.1")]
public class TurretPower : RustPlugin
{
private PluginConfig config;
protected override void LoadDefaultConfig()
{
config = PluginConfig.DefaultConfig();
}
protected override void LoadConfig()
{
base.LoadConfig();
config = Config.ReadObject<PluginConfig>();
if (config.PluginVersion < Version)
UpdateConfigValues();
Config.WriteObject(config, true);
}
private void UpdateConfigValues()
{
PluginConfig baseConfig = PluginConfig.DefaultConfig();
if (config.PluginVersion < Version)
{
config.PluginVersion = Version;
if (Version == new VersionNumber(1, 0, 0))
{
//
}
PrintWarning("Config checked completed!");
}
config.PluginVersion = Version;
}
protected override void SaveConfig()
{
Config.WriteObject(config);
}
public class SettingsTurret
{
[JsonProperty("Запрещать ли включать турели в рейблоке ?")]
public Boolean BlockedTumblerRaidblock;
}
private class PluginConfig
{
[JsonProperty("Рейд-Блок")]
public SettingsTurret _SettingsTurret = new SettingsTurret();
[JsonProperty("Config version")]
public VersionNumber PluginVersion = new VersionNumber();
public static PluginConfig DefaultConfig()
{
return new PluginConfig()
{
_SettingsTurret = new SettingsTurret
{
BlockedTumblerRaidblock = true,
},
PluginVersion = new VersionNumber()
};
}
}
private void OnEntitySpawned(BaseNetworkable entity)
{
if (!(entity is SamSite || entity is AutoTurret)) return;
var turret = entity as IOEntity;
IOEntity _switch = GameManager.server.CreateEntity("assets/prefabs/deployable/playerioents/simpleswitch/switch.prefab") as IOEntity;
if (_switch == null) return;
_switch.enableSaving = true;
_switch.transform.localEulerAngles = new Vector3(0, 180, 180);
_switch.transform.localPosition = entity is SamSite ? new Vector3(0f, 1.5f, -0.95f) : new Vector3(0f, 1.37f, -0.31f);
_switch.SetParent(turret);
_switch.UpdateFromInput(30, 0);
_switch.Spawn();
_switch.SendNetworkUpdate();
turret.inputs[0].connectedTo.Set(_switch);
_switch.outputs[0].connectedTo.Set(turret);
turret.IOStateChanged(30, 0);
_switch.SetFlag(BaseEntity.Flags.Reserved11, true);
}
public Boolean IsRaidBlocked(BasePlayer player)
{
if (!config._SettingsTurret.BlockedTumblerRaidblock) return false;
String ret = Interface.Call("CanTeleport", player) as String;
return ret != null;
}
private object OnWireClear(BasePlayer player, IOEntity entity1, int connected, IOEntity entity2, bool flag)
{
if (entity1.HasFlag(BaseEntity.Flags.Reserved11) || entity2.HasFlag(BaseEntity.Flags.Reserved11))
return false;
return null;
}
private object OnWireConnect(BasePlayer player, IOEntity entity1, int inputs, IOEntity entity2, int outputs)
{
if (outputs == 3 || inputs == 0)
if (entity1.HasFlag(BaseEntity.Flags.Reserved11) || entity2.HasFlag(BaseEntity.Flags.Reserved11))
return false;
return null;
}
private void OnEntityTakeDamage(ElectricSwitch _switch, HitInfo info)
{
if (_switch == null || info == null) return;
if (_switch.HasFlag(BaseEntity.Flags.Reserved11))
info.damageTypes.ScaleAll(0f);
}
object OnSwitchToggle(IOEntity entity, BasePlayer player)
{
if (entity == null || player == null) return null;
if (entity.HasFlag(BaseEntity.Flags.Reserved11))
if (player.IsBuildingBlocked())
return false;
if (IsRaidBlocked(player))
{
player.ChatMessage($"Вы находитесь в зоне рейд-блока!\nЧтобы включить турель вам нужно выйти из зоны рейд-блока.");
return false;
}
return null;
}
}
}