C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Oxide.Core.Plugins;
using Newtonsoft.Json;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Oxide.Core.Plugins;
using UnityEngine;
using Oxide.Core;
using System.Collections.Generic;
using System.Linq;
using Network;
using System;
using Oxide.Core.Libraries.Covalence;
using System.Globalization;
using System.IO;
using Oxide.Core.Configuration;
using Oxide.Game.Rust.Cui;
using Steamworks.ServerList;
using Rust;
using ProtoBuf;
using ConVar;
using Oxide.Core.Libraries;
using CompanionServer.Handlers;
using System.Runtime;
using Facepunch;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Rust;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using UnityEngine;
using static ConsoleSystem;
using System.Reflection;
using System.Collections;
using Oxide.Game.Rust.Libraries;
namespace Oxide.Plugins {
[Info("SimplePVE", "Ifte", "1.2.0")]
[Description("An easy simple PVE plugin for your server to modify or change PVE rules.")]
public class SimplePVE : RustPlugin {
/// <summury>
/// UPDATES
/// -------
/// 1.0.1 - Added RaidableBases Support && fixes some bugs
/// 1.0.2 - Fixes minor issues
/// 1.0.3 - Fixed ZoneManager glitch
/// 1.0.6 - Fixed Bugs
/// 1.0.8 - Patch for September update, fixed few issues, added some new configurations
/// 1.0.9 - Fixed Player Rules conflicts
/// 1.1.0 - Added new Cuis, PVE rules control, create edit schedules
/// 1.1.1 - Added Twig damage config, Fixed ToolCupboard damage, Fixed Vending No Access
/// 1.1.2 - Fixed MLRS damages conflicts, Fixed Now TC authed player can access loot boxes, Fixed NPC raiders cant damage building, Zombie Horde Compatible
/// 1.1.3 - Fixed RaidableBases TC bug, Code Cleanup, Optimization on Hooks
/// 1.1.4 - Patch for latest oxide update, Bug fixes, Design changes
/// 1.1.5 - Fix a bug, it was my mistake obs need more testing
/// 1.1.6 - Fixed Loot Rules & PVE Rules
/// 1.1.7 - Added new permission (simplepve.admindamage), Updated allow twig damage even if he is not owner or teammates but twig is on his tc area, Armored Train support, Admin Damage permission, Samsite to AttackHeli/HotAirBaloon, Fixed Ladder not be able distroy in your tc range, Fixed now you can damage entity that is on ur tc range & entity out of tc range can be distroyed
/// 1.1.8 - Added Discord Embed messages, OnEntityTakeDamage force override with different plugins, New Config for Discord Embed Messaged, New API (GetPVPStartTimeRemaining(), GetPVPEndTimeRemaining), Excluse Specific Zones from PVE Rules
/// 1.1.9 - Fixed Modular cars Collision damage, Fixed bradley fire damage, Fixed patrol heli fire & explosion damage, Added campfire damages, Fixed Tesla Damages
/// 1.1.10 - Added SupplyDrop Loot Rule, Fixed TeslaCoil damages players, Added TeslaCoil without owner can damage players(For RaidableBases), Added Racked Weapon Support, Added Damage block from ReactiveTarget(ComputerStation Turrets), Added Anti-Ladder/Twig placement on other player base(Teams/Clan Exception), Added new rules in ZoneRules config, Added PVP delay time when exiting a pvp zone, Added Legay Wooden Shelter Support
/// --------
/// 1.2.0 - Latest with NewUI, Added new schedule system with weekdays support.Added config for Commands to execute when pvp purge starts and ends(Only from schedules)
///
/// TO DO LIST
/// ----------
/// Add more new features
/// More Rules to control
///
/// BUGS
/// ------
///
/// </summury>>
#region Varriables
[PluginReference]
Plugin ZoneManager, ImageLibrary, Clans, Friends, RaidableBases, Convoy, HeliSignals, AbandonedBases;
private Configuration config;
private bool update = true;
private bool PVPRun = false;
private bool ChangedConfig = false;
private bool DiscordMessageSent = false;
private Dictionary<ulong, PVPDelay> pvp_delays = new Dictionary<ulong, PVPDelay>();
enum PVERules {
GRules, PRules, NRules, ERules, LRules, ZRules
}
private class PVPDelay {
public string ZoneID;
public Timer DelayTimer;
}
//permissions
private const string PvEAdminPerms = "simplepve.admin";
private const string PvEAdminLootPerms = "simplepve.adminloot";
private const string PvEAdminDamagePerms = "simplepve.admindamage";
#endregion
#region Configs
private class Configuration {
[JsonProperty(PropertyName = "PVE Enabled")]
public bool pveEnabledConfig {
get;
set;
}
[JsonProperty(PropertyName = "PVP delay time in seconds(If enabled from ZoneRules)")]
public int pvpdelaytime {
get;
set;
}
[JsonProperty(PropertyName = "General Rules")]
public GRules gRules {
get;
set;
}
public class GRules {
[JsonProperty("Allow Friendly Fire")]
public bool aFriendlyFire {
get;
set;
}
[JsonProperty("Allow Suicide")]
public bool allowSuicide {
get;
set;
}
[JsonProperty("Kill Sleepers")]
public bool killSleepers {
get;
set;
}
[JsonProperty("Player Radiation Damage")]
public bool pRadiation {
get;
set;
}
}
[JsonProperty(PropertyName = "Player Rules")]
public PlayerRules playerRules {
get;
set;
}
public class PlayerRules {
[JsonProperty("Player Can Hurt Players")]
public bool pCanHurtp {
get;
set;
}
[JsonProperty("Player Can Hurt Animals")]
public bool pCanHurta {
get;
set;
}
[JsonProperty("Player Can Hurt NPC")]
public bool pCanHurtn {
get;
set;
}
[JsonProperty("Player Can Damage(Helicopters, Vehicles)")]
public bool pCanDamEntitys {
get;
set;
}
[JsonProperty("Player Can Damage Other Player Buildings")]
public bool pCanDamOtherpBuildings {
get;
set;
}
[JsonProperty("Player Can Damage Own Buildings")]
public bool pCanDamageOwnBuildings {
get;
set;
}
[JsonProperty("Player Can Damage Own Teammates Building")]
public bool pCanDamOwnTeamamtesBuilding {
get;
set;
}
[JsonProperty("Player Can Damage Other Player Twigs")]
public bool PallowTwigDamage {
get;
set;
}
}
[JsonProperty(PropertyName = "Npc Rules")]
public NpcRules npcRules {
get;
set;
}
public class NpcRules {
[JsonProperty("Npc Can Hurt Players")]
public bool NpcHurtP {
get;
set;
}
[JsonProperty("Animal Can Hurt Players")]
public bool AnimalCanHurtP {
get;
set;
}
[JsonProperty("Patrol Heli Can Hurt Player")]
public bool PatrolHurtP {
get;
set;
}
[JsonProperty("Patrol Heli Can Hurt Buildings")]
public bool PatrolHurtB {
get;
set;
}
[JsonProperty("Player SamSite Ignore Players")]
public bool PSamigP {
get;
set;
}
[JsonProperty("Npc SamSite Ignore Players")]
public bool NSamigP {
get;
set;
}
[JsonProperty("Bradley Can Hurt Players")]
public bool bradleyHurtP {
get;
set;
}
}
[JsonProperty(PropertyName = "Entity Rules")]
public EntityRules entityRules {
get;
set;
}
public class EntityRules {
[JsonProperty("Walls Entitys Can Hurt Players(Example: High External Wall)")]
public bool WallHurtP {
get;
set;
}
[JsonProperty("Barricade Entitys Can Hurt Players(Example: Wooden Barricade)")]
public bool BarrHurtP {
get;
set;
}
[JsonProperty("MLRS Rocket Can Damage Players or Buildings")]
public bool MlrsHurtPB {
get;
set;
}
[JsonProperty("Vehicle Entitys Can Hurt Players(Example: Cars, Mini, ScrapHeli)")]
public bool VehicleHurtP {
get;
set;
}
[JsonProperty("Disable Traps(BearTrap, LandMine, GunTrap, FlameTurret, AutoTurret)")]
public bool trapD {
get;
set;
}
[JsonProperty("Enable Vehicle Collsion Damage")]
public bool enableVehicleCollsionD {
get;
set;
}
}
[JsonProperty(PropertyName = "Loot Rules")]
public LootRules lootRules {
get;
set;
}
public class LootRules {
[JsonProperty("Use Loot Protection")]
public bool useLP {
get;
set;
}
[JsonProperty("Admin Can Loot All")]
public bool adminCanLootAll {
get;
set;
}
[JsonProperty("Teams Can Access Loot")]
public bool teamsAccessLoot {
get;
set;
}
[JsonProperty("Player can loot other player in PVP Zones")]
public bool pclpvpzones {
get;
set;
}
[JsonProperty("Anyone can open Player called SupplyDrops")]
public bool anyoneOpenSupplyDrop {
get;
set;
}
}
[JsonProperty(PropertyName = "Zone Rules")]
public ZoneRules zoneRules {
get;
set;
}
public class ZoneRules {
[JsonProperty("Use ZoneManager")]
public bool zoneManager {
get;
set;
}
[JsonProperty("Disable PVE Rules In Zones")]
public bool disableRulesZone {
get;
set;
}
[JsonProperty("Enable PVP Delay from ZoneManager")]
public bool enablePVPDelay {
get;
set;
}
}
[JsonProperty(PropertyName = "Notifications")]
public DisplayNotify displayNotify {
get;
set;
}
public class DisplayNotify {
[JsonProperty("Prefix")]
public string prefix {
get;
set;
}
[JsonProperty("Chat Avatar")]
public ulong chatAvatar {
get;
set;
}
[JsonProperty("Show PVE Icon Overlay")]
public bool showPvEOverlay {
get;
set;
}
[JsonProperty("Show PVE Warning Messages")]
public bool showDamageM {
get;
set;
}
[JsonProperty("PVE Warning Type(Chat/UI/Both)")]
public string showDamageMType {
get;
set;
}
[JsonProperty("PVE Warning Chat Message")]
public string showDamageMTypeMessage {
get;
set;
}
[JsonProperty("PVE Warning UI Settings")]
public WarningUI warningUI {
get;
set;
}
public class WarningUI {
[JsonProperty("Anchor Min")]
public string WarningAMin {
get;
set;
}
[JsonProperty("Anchor Max")]
public string WarningAMax {
get;
set;
}
[JsonProperty("Warning Image URL")]
public string WarningImgUrl {
get;
set;
}
}
[JsonProperty("Show Loot Protection Messages")]
public bool LPMessagesOn {
get;
set;
}
[JsonProperty("Loot Protection Type(Chat/UI/Both)")]
public string LPType {
get;
set;
}
[JsonProperty("Loot Protection Chat Message")]
public string LPChatMessage {
get;
set;
}
[JsonProperty("Loot Protection UI Settings")]
public LPUISetting lPUISetting {
get;
set;
}
public class LPUISetting {
[JsonProperty("Anchor Min")]
public string WarningAMin {
get;
set;
}
[JsonProperty("Anchor Max")]
public string WarningAMax {
get;
set;
}
[JsonProperty("Warning Loot UI Image URL")]
public string WarningImgUrl {
get;
set;
}
}
[JsonProperty("PVE/PVP Icon UI Settings")]
public PEPUISetting pUISetting {
get;
set;
}
public class PEPUISetting {
[JsonProperty("Anchor Min")]
public string pepAMin {
get;
set;
}
[JsonProperty("Anchor Max")]
public string pepAMax {
get;
set;
}
[JsonProperty("Offset Min")]
public string pepOMin {
get;
set;
}
[JsonProperty("Offset Max")]
public string pepOMax {
get;
set;
}
}
}
[JsonProperty(PropertyName = "Schedules Setting")]
public Sche sche {
get;
set;
}
public class Sche {
[JsonProperty("UTC Time Difference")]
public int utcTimeDif {
get;
set;
}
[JsonProperty("Enable Weekly Schedule Only")]
public bool enableweeklysch {
get;
set;
}
[JsonProperty("PVP On Notify Message")]
public string pvpOnMessage {
get;
set;
}
[JsonProperty("PVE On Notify Message")]
public string pveOnMessage {
get;
set;
}
}
[JsonProperty(PropertyName = "Discord Setting")]
public DiscordSetting discordSetting {
get;
set;
}
public class DiscordSetting {
[JsonProperty("Enable Discord Notification")]
public bool enableDiscordNotify {
get;
set;
}
[JsonProperty("Discord Webhook URL")]
public string discordWebhookURL {
get;
set;
}
[JsonProperty("Enable Message Before PVP Time Start")]
public bool messageBeforeStart {
get;
set;
}
[JsonProperty("Before PVP Time Start Minutes")]
public int messageBeforeStartMinutes {
get;
set;
}
[JsonProperty("PVP Message Embed Color(Hexa)")]
public string pvpmessageEmbed {
get;
set;
}
[JsonProperty("Before PVP Time Start Message Content")]
public string[] pvpTimeMessage {
get;
set;
}
[JsonProperty("Enable Message Before PVE Time Start")]
public bool messageBeforeStartPVE {
get;
set;
}
[JsonProperty("Before PVE Time Start Minutes")]
public int messageBeforeStartMinutesPVE {
get;
set;
}
[JsonProperty("PVE Message Embed Color")]
public string pvemessageEmbed {
get;
set;
}
[JsonProperty("Before PVE Time Start Message Content")]
public string[] pveTimeMessage {
get;
set;
}
}
[JsonProperty(PropertyName = "Commands when PVP Purge Starts")]
public List<string> commandsExefrompvpstart {
get;
set;
}
[JsonProperty(PropertyName = "Commands when PVP Purge Ends")]
public List<string> commandsExefrompvpends {
get;
set;
}
[JsonProperty(PropertyName = "Exclude Zone IDs From Rules")]
public string[] excludedZoneIDs {
get;
set;
}
public static Configuration CreateConfig() {
return new Configuration {
pveEnabledConfig = true, pvpdelaytime = 5, zoneRules = new ZoneRules {
zoneManager = true, disableRulesZone = true, enablePVPDelay = true,
}
, gRules = new GRules {
aFriendlyFire = true, allowSuicide = true, killSleepers = false, pRadiation = true,
}
, playerRules = new PlayerRules {
pCanHurtp = false, pCanHurta = true, pCanHurtn = true, pCanDamEntitys = true, pCanDamOtherpBuildings = false, pCanDamageOwnBuildings = true, pCanDamOwnTeamamtesBuilding = true, PallowTwigDamage = true,
}
, npcRules = new NpcRules {
NpcHurtP = true, AnimalCanHurtP = true, PatrolHurtP = true, PatrolHurtB = true, PSamigP = true, NSamigP = true, bradleyHurtP = true
}
, entityRules = new EntityRules {
WallHurtP = true, BarrHurtP = true, MlrsHurtPB = false, VehicleHurtP = false, trapD = true, enableVehicleCollsionD = true,
}
, lootRules = new LootRules {
useLP = true, adminCanLootAll = true, teamsAccessLoot = true, pclpvpzones = false, anyoneOpenSupplyDrop = false
}
, displayNotify = new DisplayNotify {
showDamageM = true, prefix = "<color=#00ffff>[SimplePVE]</color>: ", chatAvatar = 0, showDamageMType = "Both", showDamageMTypeMessage = "PVE enabled on this server, blocking damage.", warningUI = new DisplayNotify.WarningUI {
WarningAMin = "0.786 0.722", WarningAMax = "0.99 0.815", WarningImgUrl = "https://i.postimg.cc/0jZNDr9x/Add-a-subheading-2.png"
}
, showPvEOverlay = true, LPMessagesOn = true, LPType = "Both", LPChatMessage = "This entity is protected!", lPUISetting = new DisplayNotify.LPUISetting {
WarningAMin = "0.786 0.722", WarningAMax = "0.99 0.815", WarningImgUrl = "https://i.postimg.cc/SxSsS67s/Add-a-subheading-1.png"
}
, pUISetting = new DisplayNotify.PEPUISetting {
pepAMin = "0.5 0", pepAMax = "0.5 0", pepOMin = "190 30", pepOMax = "250 60"
}
}
, sche = new Sche {
utcTimeDif = 360, enableweeklysch = true, pvpOnMessage = "<#990000>PVP enabled on the server.Now you can raid others bases and fight!</color>", pveOnMessage = "<#008000>PVE enabled.Raid and fight is now prohibited!</color>",
}
, discordSetting = new DiscordSetting {
enableDiscordNotify = false, discordWebhookURL = string.Empty, messageBeforeStart = false, messageBeforeStartMinutes = 30, pvpmessageEmbed = "#990000", pvpTimeMessage = new string[] {
"🔔 **Attention Rust Survivors!**", "", "PVP purge approaching!", "In {Minutes} Minutes🕒", "", "Prepare yourselves for intense battles! ⚔️",
}
, messageBeforeStartPVE = false, messageBeforeStartMinutesPVE = 30, pvemessageEmbed = "#32CD32", pveTimeMessage = new string[] {
"🔔 **Attention Rust Survivors!**", "", "PVP purge ending soon!", "In {Minutes} Minutes🕒", "", "Make your final moves wisely!", "Collect your victories and gear up for the next day!"
}
}
, commandsExefrompvpstart = new List<string> {
}
, commandsExefrompvpends = new List<string> {
}
, excludedZoneIDs = new string[] {
"69", "6969"
}
}
;
}
}
protected override void LoadConfig() {
base.LoadConfig();
config = Config.ReadObject<Configuration>();
}
protected override void LoadDefaultConfig() {
config = Configuration.CreateConfig();
}
protected override void SaveConfig() {
Config.WriteObject(config, true);
}
#endregion
#region Commands Pack
[Command("simplepve")]
private void CommandEnable(IPlayer p, string cmd, string[] args) {
if (!p.HasPermission(PvEAdminPerms)) {
p.Message("You don't have permission to use this command.");
return;
}
if (config.pveEnabledConfig) {
config.pveEnabledConfig = false;
SaveConfig();
p.Message("SimplePVE disabled");
if (!config.pveEnabledConfig) {
NotSubscribe();
foreach (var player in BasePlayer.activePlayerList) {
RemovePVEPanel(player);
RemovePVPPanel(player);
ShowPVPUi(player);
}
}
}
else {
config.pveEnabledConfig = true;
SaveConfig();
p.Message("SimplePVE enabled");
if (config.pveEnabledConfig) {
Subscribe();
foreach (var player in BasePlayer.activePlayerList) {
RemovePVPPanel(player);
RemovePVEPanel(player);
ShowPVEUI(player);
}
}
}
}
[Command("rsp")]
private void ReloadPlugin(IPlayer player, string cmd, string[] args) {
if (!player.HasPermission(PvEAdminPerms)) {
player.Message("You don't have permission to use this command.");
return;
}
player.Command("oxide.reload SimplePVE");
player.Message("SimplePVE reloaded.");
}
[ChatCommand("sprules")]
private void SimplePVEGui(BasePlayer player, string cmd, string[] args) {
if (!permission.UserHasPermission(player.UserIDString, PvEAdminPerms)) {
player.ChatMessage("You don't have permission to use this command.");
return;
}
SimplePVEMainGui(player);
PVERulesUI(player, PVERules.GRules);
}
[ChatCommand("notest")]
private void SimplePVEGuiClose(BasePlayer player, string cmd, string[] args) {
CuiHelper.DestroyUi(player, "SimplePVECUI");
}
[ConsoleCommand("spvecui")]
private void SPVECUICMD(ConsoleSystem.Arg args) {
var player = args?.Player();
string command = args.Args[0];
switch (command) {
case "pverules" : PVERulesUI(player, PVERules.GRules);
break;
case "pveschedules" : var time = DateTime.Now;
PVESchedules(player);
break;
case "grules" : PVERulesUI(player, PVERules.GRules);
break;
case "prules" : PVERulesUI(player, PVERules.PRules);
break;
case "nrules" : PVERulesUI(player, PVERules.NRules);
break;
case "erules" : PVERulesUI(player, PVERules.ERules);
break;
case "lrules" : PVERulesUI(player, PVERules.LRules);
break;
case "zrules" : PVERulesUI(player, PVERules.ZRules);
break;
case "closeall" : CuiHelper.DestroyUi(player, "SimplePVECUI");
if (ChangedConfig == true) {
Server.Command($"o.reload {Name}");
ChangedConfig = false;
}
break;
}
}
[ConsoleCommand("grulesSetting")]
private void GrulesCcmd(ConsoleSystem.Arg args) {
var player = args?.Player();
string propertyName = args.Args[0];
SetProperty(propertyName);
SaveConfig();
PVERulesUI(player, PVERules.GRules);
}
[ConsoleCommand("prulesSetting")]
private void PrulesCcmd(ConsoleSystem.Arg args) {
var player = args?.Player();
string propertyName = args.Args[0];
SetProperty(propertyName);
SaveConfig();
PVERulesUI(player, PVERules.PRules);
}
[ConsoleCommand("nrulesSetting")]
private void NrulesCcmd(ConsoleSystem.Arg args) {
var player = args?.Player();
string propertyName = args.Args[0];
SetProperty(propertyName);
SaveConfig();
PVERulesUI(player, PVERules.NRules);
}
[ConsoleCommand("erulesSetting")]
private void ErulesCcmd(ConsoleSystem.Arg args) {
var player = args?.Player();
string propertyName = args.Args[0];
SetProperty(propertyName);
SaveConfig();
PVERulesUI(player, PVERules.ERules);
}
[ConsoleCommand("lrulesSetting")]
private void LrulesCcmd(ConsoleSystem.Arg args) {
var player = args?.Player();
string propertyName = args.Args[0];
SetProperty(propertyName);
SaveConfig();
PVERulesUI(player, PVERules.LRules);
}
[ConsoleCommand("zrulesSetting")]
private void ZrulesCcmd(ConsoleSystem.Arg args) {
var player = args?.Player();
string propertyName = args.Args[0];
SetProperty(propertyName);
SaveConfig();
PVERulesUI(player, PVERules.ZRules);
}
private void SetProperty(string propertyName) {
if (config == null) return;
PropertyInfo gRulesProperty = typeof(Configuration.GRules).GetProperty(propertyName);
PropertyInfo pRulesProperty = typeof(Configuration.PlayerRules).GetProperty(propertyName);
PropertyInfo nRulesProperty = typeof(Configuration.NpcRules).GetProperty(propertyName);
PropertyInfo eRulesProperty = typeof(Configuration.EntityRules).GetProperty(propertyName);
PropertyInfo lRulesProperty = typeof(Configuration.LootRules).GetProperty(propertyName);
PropertyInfo zRulesProperty = typeof(Configuration.ZoneRules).GetProperty(propertyName);
ChangedConfig = true;
if (gRulesProperty != null) {
bool currentValue = (bool)gRulesProperty.GetValue(config.gRules);
bool newValue = !currentValue;
gRulesProperty.SetValue(config.gRules, newValue);
}
else if (pRulesProperty != null) {
bool currentValue = (bool)pRulesProperty.GetValue(config.playerRules);
bool newValue = !currentValue;
pRulesProperty.SetValue(config.playerRules, newValue);
}
else if (nRulesProperty != null) {
bool currentValue = (bool)nRulesProperty.GetValue(config.npcRules);
bool newValue = !currentValue;
nRulesProperty.SetValue(config.npcRules, newValue);
}
else if (eRulesProperty != null) {
bool currentValue = (bool)eRulesProperty.GetValue(config.entityRules);
bool newValue = !currentValue;
eRulesProperty.SetValue(config.entityRules, newValue);
}
else if (lRulesProperty != null) {
bool currentValue = (bool)lRulesProperty.GetValue(config.lootRules);
bool newValue = !currentValue;
lRulesProperty.SetValue(config.lootRules, newValue);
}
else if (zRulesProperty != null) {
bool currentValue = (bool)zRulesProperty.GetValue(config.zoneRules);
bool newValue = !currentValue;
zRulesProperty.SetValue(config.zoneRules, newValue);
}
SaveConfig();
}
#endregion
#region Plugin Loads
void Init() {
Puts("Cleaning up..");
Puts("Garbage drop...");
Puts("Config clean....");
Puts("Initializing rules.....");
//permission
permission.RegisterPermission(PvEAdminPerms, this);
permission.RegisterPermission(PvEAdminLootPerms, this);
permission.RegisterPermission(PvEAdminDamagePerms, this);
//Commands
AddCovalenceCommand("simplepve", "CommandEnable");
AddCovalenceCommand("rsp", "ReloadPlugin");
NotSubscribe();
}
private void OnServerInitialized() {
if (config.pveEnabledConfig) {
Subscribe();
}
else {
NotSubscribe();
}
foreach (var player in BasePlayer.activePlayerList) {
OnPlayerConnected(player);
}
//Images load from ImageLibrary
LoadImages();
timer.In(1f, OnServerInitializedLate);
}
private void OnServerInitializedLate() {
//Start Schedules
ServerMgr.Instance.StartCoroutine(Schedules());
}
private void Loaded() {
LoadSchTime();
}
private void Unload() {
NotSubscribe();
foreach (var player in BasePlayer.activePlayerList) {
RemovePVEPanel(player);
RemovePVPPanel(player);
RemoveUIWarning(player);
RemoveWarningLoot(player);
CuiHelper.DestroyUi(player, "SimplePVECUI");
}
update = false;
ChangedConfig = false;
DiscordMessageSent = false;
}
private void Subscribe() {
Subscribe(nameof(OnEntitySpawned));
Subscribe(nameof(OnEntityTakeDamage));
if (config.lootRules.useLP) {
Subscribe(nameof(CanLootEntity));
Subscribe(nameof(CanLootPlayer));
Subscribe(nameof(CanAdministerVending));
Subscribe(nameof(OnOvenToggle));
Subscribe(nameof(CanBuild));
Subscribe(nameof(OnRackedWeaponMount));
Subscribe(nameof(OnRackedWeaponSwap));
Subscribe(nameof(OnRackedWeaponTake));
Subscribe(nameof(OnRackedWeaponUnload));
Subscribe(nameof(OnRackedWeaponLoad));
}
if (config.entityRules.trapD) {
Subscribe(nameof(OnTrapTrigger));
Subscribe(nameof(CanBeTargeted));
}
if (config.npcRules.NSamigP || config.npcRules.PSamigP) {
Subscribe(nameof(OnSamSiteTarget));
}
}
private void NotSubscribe() {
Unsubscribe(nameof(OnEntityTakeDamage));
Unsubscribe(nameof(CanLootEntity));
Unsubscribe(nameof(CanLootPlayer));
Unsubscribe(nameof(CanAdministerVending));
Unsubscribe(nameof(OnOvenToggle));
Unsubscribe(nameof(OnTrapTrigger));
Unsubscribe(nameof(CanBeTargeted));
Unsubscribe(nameof(OnSamSiteTarget));
Unsubscribe(nameof(OnEntitySpawned));
Unsubscribe(nameof(CanBuild));
//Racked
Unsubscribe(nameof(OnRackedWeaponMount));
Unsubscribe(nameof(OnRackedWeaponSwap));
Unsubscribe(nameof(OnRackedWeaponTake));
Unsubscribe(nameof(OnRackedWeaponUnload));
Unsubscribe(nameof(OnRackedWeaponLoad));
}
#endregion
#region PVE Rules
private bool Debug = false;
private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hit) {
if (!config.pveEnabledConfig || entity == null || entity.IsDestroyed || entity.IsDead() || hit == null || (hit.InitiatorPlayer != null && permission.UserHasPermission(hit.InitiatorPlayer.UserIDString, PvEAdminDamagePerms))) {
return null;
}
if (Interface.CallHook("CanEntityTakeDamage", new object[] {
entity, hit
}
) is bool val) {
if (val) {
return null;
}
noDamage(hit);
if (hit.InitiatorPlayer?.userID.IsSteamId() == true) {
ShowWarningAlert(hit.InitiatorPlayer);
}
return true;
}
if (Interface.CallHook("IsHeliSignalObject", entity.skinID) != null) return null;
if (entity is PatrolHelicopter || entity.ShortPrefabName.Contains("patrolheli") || entity is BradleyAPC || entity.ShortPrefabName.Contains("bradley")) {
//if (Debug) Puts($"Attacker: {hit.Initiator} & Victim: {entity.ShortPrefabName} & Rules No rules");
return null;
}
if (!CheckIncludes(entity, hit)) {
noDamage(hit);
if (hit.InitiatorPlayer?.userID.IsSteamId() == true) {
ShowWarningAlert(hit.InitiatorPlayer);
}
if (Debug) Puts($"Attacker: {hit.Initiator.ShortPrefabName} Himself & Damaged: {entity.ShortPrefabName}");
return true;
}
if (Debug) Puts($"Attacker: {hit.Initiator.ShortPrefabName} Himself & Damaged: {entity.ShortPrefabName}");
return null;
}
private bool CheckIncludes(BaseCombatEntity entity, HitInfo hit) {
var damageType = hit.damageTypes.GetMajorityDamageType();
if (damageType == DamageType.Suicide) {
if (entity is BasePlayer victim1 && victim1.userID.IsSteamId() && config.gRules.allowSuicide) {
if (Debug) Puts($"Attacker: Himself & Damages From: Suicide & Rules {config.gRules.allowSuicide}");
return true;
}
else {
if (entity is BasePlayer) entity.SendMessage("Suicide is disabled on this server!");
return false;
}
}
if (damageType == DamageType.Radiation || damageType == DamageType.RadiationExposure) {
if (entity is BasePlayer && config.gRules.pRadiation) {
if (Debug) Puts($"Attacker: {damageType} & Damages From: Rad & Rules {config.gRules.pRadiation}");
return true;
}
}
if (damageType == DamageType.Fall || damageType == DamageType.Drowned || damageType == DamageType.Decay || damageType == DamageType.Cold || damageType == DamageType.Hunger || damageType == DamageType.Poison || damageType == DamageType.Thirst ) //ew
{
return true;
}
if (config.zoneRules.zoneManager && ZoneManager != null) {
var weapon = hit.Initiator ?? hit.Weapon ?? hit.WeaponPrefab;
Initiator(hit, weapon);
List<string> entityLoc = GetAllZones(entity);
List<string> iniLoc = GetAllZones(weapon);
if (CheckExclusion(entityLoc, iniLoc)) {
if (Debug) Puts($"Attacker: {weapon.ShortPrefabName} & Victim: {entity.ShortPrefabName} & Rules {config.zoneRules.disableRulesZone}");
return config.zoneRules.disableRulesZone;
}
}
if (entity is DecayEntity) {
if (hit.Initiator is BasePlayer) {
BasePlayer player = hit.Initiator as BasePlayer;
if (player.userID.IsSteamId() && entity.ShortPrefabName.Contains("cupboard")) {
if (entity.OwnerID == player.userID || IsAlliedWithPlayer(entity.OwnerID, player.userID)) {
if (Debug) Puts($"Attacker: {player.ShortPrefabName} & Victim: {entity.ShortPrefabName} & Rules {config.playerRules.pCanDamageOwnBuildings}");
return config.playerRules.pCanDamageOwnBuildings || config.playerRules.pCanDamOwnTeamamtesBuilding;
}
else if (entity.OwnerID == 0) {
if (Debug) Puts($"Attacker: {player.ShortPrefabName} & Victim: {entity.ShortPrefabName} & Rules Entity is server");
return true;
}
else {
if (Debug) Puts($"Attacker: {player.ShortPrefabName} & Victim: {entity.ShortPrefabName} & Rules {config.playerRules.pCanDamOtherpBuildings}");
return config.playerRules.pCanDamOtherpBuildings;
}
}
}
}
if (entity is BasePlayer && hit.Initiator is BasePlayer) {
BasePlayer attacker = hit.Initiator as BasePlayer;
BasePlayer victim = entity as BasePlayer;
//check friendly fire
if (attacker.userID.IsSteamId() && victim.userID.IsSteamId() && IsAlliedWithPlayer(attacker.userID, victim.userID)) {
if (config.gRules.aFriendlyFire) {
if (Debug) Puts($"Attacker: {attacker.ShortPrefabName} & Victim: {victim.ShortPrefabName} & Rules {config.gRules.aFriendlyFire}");
return true;
}
else {
if (Debug) Puts($"Attacker: {attacker.ShortPrefabName} & Victim: {victim.ShortPrefabName} & Rules {config.gRules.aFriendlyFire}");
return false;
}
}
//check sleepers
else if (attacker.userID.IsSteamId() && victim.userID.IsSteamId() && !IsAlliedWithPlayer(attacker.userID, victim.userID)) {
if (victim.IsSleeping()) {
if (config.gRules.killSleepers) {
if (Debug) Puts($"Attacker: {attacker.ShortPrefabName} & Victim: {victim.ShortPrefabName} & Rules {config.gRules.killSleepers}");
return true;
}
else {
if (Debug) Puts($"Attacker: {attacker.ShortPrefabName} & Victim: {victim.ShortPrefabName} & Rules {config.gRules.killSleepers}");
return false;
}
}
else if (inPVPBase.Contains(attacker.userID) && inPVPBase.Contains(victim.userID)) //fix raidable bases pvp base
{
if (Debug) Puts($"Attacker: {attacker.ShortPrefabName} & Victim: {victim.ShortPrefabName} & Rules In PVP RaidableBases");
return true;
}
else if (config.zoneRules.enablePVPDelay && CheckPVPDelay(victim, attacker)) {
return true;
}
//player can hurt players
else if (config.playerRules.pCanHurtp == true && victim.IsConnected) {
if (Debug) Puts($"Attacker: {attacker.ShortPrefabName} & Victim: {victim.ShortPrefabName} & Rules {config.playerRules.pCanHurtp}");
return true;
}
else {
if (Debug) Puts($"Attacker: {attacker.ShortPrefabName} & Victim: {victim.ShortPrefabName} & Rules damages for player type");
return false;
}
}
}
if (hit.Initiator is BasePlayer attacker1) {
if (attacker1.userID.IsSteamId()) {
if (IsHostileEntity(entity)) {
if (Debug) Puts($"Attacker: {attacker1.ShortPrefabName} & Victim: {entity.ShortPrefabName} & Rules {config.playerRules.pCanHurtn}");
return config.playerRules.pCanHurtn;
}
else if (IsFriendlyEntity(entity)) {
if (Debug) Puts($"Attacker: {attacker1.ShortPrefabName} & Victim: {entity.ShortPrefabName} & Rules {config.playerRules.pCanHurta}");
return config.playerRules.pCanHurta;
}
else if (IsDamagingEntity(entity)) {
if (Debug) Puts($"Attacker: {attacker1.ShortPrefabName} & Victim: {entity.ShortPrefabName} & Rules {config.playerRules.pCanDamEntitys}");
BuildingPrivlidge privs = entity.GetBuildingPrivilege();
if (privs != null) {
foreach (ulong auth in privs.authorizedPlayers.Select(x => x.userid).ToArray()) {
if (attacker1.userID == auth) {
return config.playerRules.pCanDamageOwnBuildings;
}
else {
return false;
}
}
}
else {
return config.playerRules.pCanDamEntitys;
}
}
//twig
if (entity is BuildingBlock && attacker1.userID.IsSteamId()) {
var twig = entity as BuildingBlock;
if (twig.grade == BuildingGrade.Enum.Twigs) {
if (entity.OwnerID == 0) return true;
if (entity.OwnerID == attacker1.userID || IsAlliedWithPlayer(entity.OwnerID, attacker1.userID) || BuildingAuth(twig, attacker1)) //|| BuildingAuth(twig, attacker1) //allow twig damage even if he is not owner or teammates but twig is on his tc area
{
if (Debug) Puts($"Attacker: {attacker1.ShortPrefabName} & Victim: {entity.ShortPrefabName} & Rules {config.playerRules.PallowTwigDamage}");
return true;
}
else {
if (Debug) Puts($"Attacker: {attacker1.ShortPrefabName} & Victim: {entity.ShortPrefabName} & Rules {config.playerRules.PallowTwigDamage}");
return config.playerRules.PallowTwigDamage;
}
}
}
//check wooden shelter
if (entity.ShortPrefabName.Contains("legacy.shelter.wood")) {
if (entity
// ... [Code preview truncated due to length. Full source in attached file] ...