//Requires: BetterChat using Newtonsoft.Json; using System.Collections.Generic; using System; using Oxide.Core.Libraries.Covalence; using Oxide.Core.Plugins; using Oxide.Game.Rust.Libraries; using UnityEngine; using Oxide.Core.Configuration; using Oxide.Core; namespace Oxide.Plugins { [Info("Local Chat and Extensions", "Bodymenn", "1.0.0")] [Description("Defaults chat to local, with customizable chat range with more Features like Privat Messages")] public class LocalChatExtension : CovalencePlugin { [PluginReference] private Plugin BetterChat; private DynamicConfigFile LocalRange; public static float ToSingle(double value) { return (float)value; } void Init() { LocalRange = Interface.Oxide.DataFileSystem.GetDatafile("LocalChatExtension"); } void OnServerSave() { LocalRange.Save(); } void Unload() { LocalRange.Save(); } void OnServerInitialized(bool initial) { if (BetterChat == null) { LogError("No BetterChat found, install BetterChat to work with this Plugin"); } } [Command("trange"), Permission("localchatextension.trange")] private void trangeCommand(IPlayer player, string command, string[] args) { if (LocalRange[player.Id] == null) { LocalRange[player.Id] = 15f; } float localRange = Convert.ToSingle(LocalRange[player.Id]); if (localRange == 15f) { LocalRange[player.Id] = 7f; player.Reply($"{lang.GetMessage("Trange", this, player.Id)} '{lang.GetMessage("Range7", this, player.Id)}'"); } else if (localRange == 7f) { LocalRange[player.Id] = 3f; player.Reply($"{lang.GetMessage("Trange", this, player.Id)} '{lang.GetMessage("Range3", this, player.Id)}'"); } else if (localRange == 3f) { LocalRange[player.Id] = 15f; player.Reply($"{lang.GetMessage("Trange", this, player.Id)} '{lang.GetMessage("Range15", this, player.Id)}'"); } } [Command("w")] private void whisperCommand(IPlayer player, string command, string[] args) { if (args.Length <= 1) return; if (BasePlayer.Find(args[0]) == null) { player.Reply(lang.GetMessage("NoPlayerFound", this, player.Id)); return; } IPlayer target = BasePlayer.Find(args[0]).IPlayer; if (target.IsConnected) { string msg = string.Join(" ", args).Substring(args[0].Length).Substring(1); target.Message($"[PRIVAT] {player.Name} {lang.GetMessage("TargetWhisper", this, target.Id)}: {msg}"); player.Message($"[PRIVAT] {lang.GetMessage("SenderWhisper", this, player.Id)} {target.Name}: {msg}"); } else player.Reply(lang.GetMessage("NoPlayerFound", this, player.Id)); } private object OnBetterChat(Dictionary messageData) { string message = (string)messageData["Message"]; if (message == null) return null; IPlayer sender = (IPlayer)messageData["Player"]; if (sender == null) return null; if ((ConVar.Chat.ChatChannel)messageData["ChatChannel"] == ConVar.Chat.ChatChannel.Team) return messageData; if (message.StartsWith("@")) { if (message.Length <= 1) return null; messageData["Message"] = message.Substring(1); return messageData; } List blockedReceivers = (List)messageData["BlockedReceivers"]; if (LocalRange[sender.Id] == null) { LocalRange[sender.Id] = 15f; } foreach (IPlayer player in covalence.Players.Connected) { BasePlayer baseTarget = player.Object as BasePlayer; BasePlayer baseSender = sender.Object as BasePlayer; if(Vector3.Distance(baseTarget.ServerPosition, baseSender.ServerPosition) > Convert.ToSingle(LocalRange[sender.Id])) { blockedReceivers.Add(player.Id); } } float Range = Convert.ToSingle(LocalRange[sender.Id]); Dictionary usernameSettings = (Dictionary)messageData["UsernameSettings"]; Dictionary messageSettings = (Dictionary)messageData["MessageSettings"]; Dictionary formatSettings = (Dictionary)messageData["FormatSettings"]; if (Range == 15f) { usernameSettings["Color"] = "#CDCDCD"; messageSettings["Color"] = "#CDCDCD"; formatSettings["Chat"] = $"[L] {{Title}} {{Username}} {lang.GetMessage("Range15", this, sender.Id)}: {{Message}}"; formatSettings["Console"] = $"[LOCAL] {{Username}} {lang.GetMessage("Range15", this, sender.Id)}: {{Message}}"; } else if (Range == 7f) { messageSettings["Color"] = "#BDBDBD"; usernameSettings["Color"] = "#BDBDBD"; formatSettings["Chat"] = $"[L] {{Title}} {{Username}} {lang.GetMessage("Range7", this, sender.Id)}: {{Message}}"; formatSettings["Console"] = $"[LOCAL] {{Username}} {lang.GetMessage("Range7", this, sender.Id)}: {{Message}}"; } else if (Range == 3f) { messageSettings["Color"] = "#6F6F6F"; usernameSettings["Color"] = "#6F6F6F"; formatSettings["Chat"] = $"[L] {{Title}} {{Username}} {lang.GetMessage("Range3", this, sender.Id)}: {{Message}}"; formatSettings["Console"] = $"[LOCAL] {{Username}} {lang.GetMessage("Range3", this, sender.Id)}: {{Message}}"; } messageData["FormatSettings"] = formatSettings; messageData["UsernameSettings"] = usernameSettings; messageData["MessageSettings"] = messageSettings; messageData["BlockedReceivers"] = blockedReceivers; return messageData; } #region Localization protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { ["NoPlayerFound"] = "The player with the name or part of this name could not be found.", ["Range15"] = "shout", ["Range7"] = "says", ["Range3"] = "whispers", ["TargetWhisper"] = "whispers to you", ["SenderWhisper"] = "You whisper", ["Trange"] = "You switched to" }, this); } #endregion } }