C#:
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("FriendlyTraps", "wGw", "1.0.0")]
[Description("Landmines and bear traps skip players authorized on the Tool Cupboard that covers them.")]
public class FriendlyTraps : RustPlugin
{
private Configuration _config;
private class Configuration
{
[JsonProperty("Plugin Version")]
public string PluginVersion = "";
[JsonProperty("Landmines skip TC-authed")]
public bool LandminesSkipAuthed = true;
[JsonProperty("Bear traps skip TC-authed")]
public bool BearTrapsSkipAuthed = true;
}
protected override void LoadDefaultConfig() => _config = new Configuration();
protected override void LoadConfig()
{
base.LoadConfig();
try
{
_config = Config.ReadObject<Configuration>();
if (_config == null) throw new System.Exception();
}
catch
{
PrintError("Config corrupt - loading defaults.");
LoadDefaultConfig();
}
_config.PluginVersion = Version.ToString();
SaveConfig();
}
protected override void SaveConfig() => Config.WriteObject(_config, true);
private object OnTrapTrigger(Landmine mine, GameObject obj)
{
if (!_config.LandminesSkipAuthed || mine == null || obj == null)
return null;
return ShouldSkip(mine, obj) ? true : null;
}
private object OnTrapTrigger(BearTrap trap, GameObject obj)
{
if (!_config.BearTrapsSkipAuthed || trap == null || obj == null)
return null;
return ShouldSkip(trap, obj) ? true : null;
}
private static bool ShouldSkip(BaseEntity trap, GameObject obj)
{
if (trap.OwnerID == 0)
return false;
BasePlayer player = obj.ToBaseEntity() as BasePlayer;
if (player == null)
return false;
BuildingPrivlidge priv = trap.GetBuildingPrivilege();
if (priv != null)
return priv.IsAuthed(player);
return (ulong)player.userID == trap.OwnerID;
}
}
}