using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using Oxide; using UnityEngine; namespace Oxide.Plugins { [Info("HealerArea", "Zayasik", "1.0.1")] [Description("Healing mates in the area")] class HealerArea : RustPlugin { private Configuration config = Configuration.DefaultConfig(); private Dictionary Perms = new Dictionary(); private Dictionary playerTimers = new Dictionary(); private class Configuration { public bool isEffect { get; set; } = true; public string ChatCommand { get; set; } = "heal_area"; [JsonProperty(PropertyName = "Permissions Groups")] public Dictionary Perms = new Dictionary { {"default", new HealerTypeInfo { priority = 0, HealInterval = 5, HealRadius = 5, InstantlyHeal = 5, PendingHeal = 10 } } }; public static Configuration DefaultConfig() { return new Configuration(); } } private class HealerTypeInfo { public int priority { get; set; } public float HealInterval { get; set; } public float HealRadius { get; set; } public float InstantlyHeal { get; set; } public float PendingHeal { get; set; } } protected override void LoadDefaultConfig() { SaveConfig(); } protected override void LoadConfig() { base.LoadConfig(); config = Config.ReadObject(); Perms = config.Perms; } protected override void SaveConfig() { config.Perms = Perms; Config.WriteObject(config, true); } private void Init() { RegisterPerms(); RegisterCommands(); SaveConfig(); } private void RegisterCommands() { cmd.AddChatCommand(config.ChatCommand, this, "StartHealer"); } private void RegisterPerms() { foreach (var group in permission.GetGroups()) { if (group != "admin" && group != "default") { if (!Perms.ContainsKey(group)) { Perms.Add(group, new HealerTypeInfo { priority = 1, HealInterval = 5, HealRadius = 5, InstantlyHeal = 5, PendingHeal = 10 }); } } } permission.RegisterPermission("healerarea.use", this); } private string GetPlayerPermsGroup(ulong _playerID) { var _groups = permission.GetUserGroups(_playerID.ToString()); var _priority = _groups .Where(x => x != "admin") .OrderByDescending(x => Perms[x].priority) .FirstOrDefault(); return _priority ?? "default"; } private void StartHealer(BasePlayer player) { if (permission.UserHasPermission(player.UserIDString, "healerarea.use")) { if (player != null && player.IsAlive()) { if (playerTimers.ContainsKey(player)) { playerTimers[player].Destroy(); playerTimers.Remove(player); SendReply(player, "Healer is stopped"); } else { playerTimers.Add(player, timer.Every(Perms[GetPlayerPermsGroup(player.userID)].HealInterval, () => HealArea(player))); SendReply(player, "Healer is started"); } } } else { SendReply(player, "You don't have permission to use this command"); } } private void OnPlayerDisconnected(BasePlayer player, string reason) { if (playerTimers.ContainsKey(player)) { playerTimers[player].Destroy(); playerTimers.Remove(player); } } private List? GetTeamPlayersInRange(BasePlayer _player, float _radius) { var _players = Facepunch.Pool.Get>(); var _colliders = Physics.OverlapSphere(_player.transform.position, _radius, LayerMask.GetMask("Player (Server)")); foreach (var _collider in _colliders) { BasePlayer? _mate = _collider.GetComponent(); if (_mate != null && _player != null && _mate.userID != _player.userID) { if (_mate.Team != null && _player.Team != null && _mate.Team == _player.Team) { _players.Add(_mate); } } } return _players; } private void HealArea(BasePlayer _player) { var _group = GetPlayerPermsGroup(_player.userID); var _healer = Perms[_group]; var _players = GetTeamPlayersInRange(_player, _healer.HealRadius); try { if (_players != null && _players.Count >= 1) { foreach (var _mate in _players) { if (_mate.IsAlive()) { _mate.Heal(_healer.InstantlyHeal); _mate.metabolism.pending_health.Add(_healer.PendingHeal); } } if (config.isEffect) { Effect.server.Run("assets/bundled/prefabs/fx/explosions/water_bomb.prefab", _player.transform.position, Vector3.up); } } } finally { Facepunch.Pool.FreeUnmanaged(ref _players); } } } }