Иконка ресурса

FREE LocalChatExtension : 1.0.0 1.0.0

Нет прав для скачивания
C#:
//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($"<color=#D8FF90>[PRIVAT]</color> <color=#FFCD00>{player.Name} {lang.GetMessage("TargetWhisper", this, target.Id)}:</color> <color=#FFDF5D>{msg}</color>");
                player.Message($"<color=#D8FF90>[PRIVAT]</color> <color=#FFCD00>{lang.GetMessage("SenderWhisper", this, player.Id)} {target.Name}:</color> <color=#FFDF5D>{msg}</color>");
            }
            else player.Reply(lang.GetMessage("NoPlayerFound", this, player.Id));
        }

        private object OnBetterChat(Dictionary<string, object> 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<string> blockedReceivers = (List<string>)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<string, object> usernameSettings = (Dictionary<string, object>)messageData["UsernameSettings"];
            Dictionary<string, object> messageSettings = (Dictionary<string, object>)messageData["MessageSettings"];
            Dictionary<string, object> formatSettings = (Dictionary<string, object>)messageData["FormatSettings"];

            if (Range == 15f)
            {
                usernameSettings["Color"] = "#CDCDCD";
                messageSettings["Color"] = "#CDCDCD";
                formatSettings["Chat"] = $"<color=#D8FF90>[L]</color> {{Title}} {{Username}} <color=#CDCDCD>{lang.GetMessage("Range15", this, sender.Id)}:</color> {{Message}}";
                formatSettings["Console"] = $"[LOCAL] {{Username}} {lang.GetMessage("Range15", this, sender.Id)}: {{Message}}";

            } else if (Range == 7f)
            {
                messageSettings["Color"] = "#BDBDBD";
                usernameSettings["Color"] = "#BDBDBD";
                formatSettings["Chat"] = $"<color=#D8FF90>[L]</color> {{Title}} {{Username}} <color=#BDBDBD>{lang.GetMessage("Range7", this, sender.Id)}:</color> {{Message}}";
                formatSettings["Console"] = $"[LOCAL] {{Username}} {lang.GetMessage("Range7", this, sender.Id)}: {{Message}}";
            } else if (Range == 3f)
            {
                messageSettings["Color"] = "#6F6F6F";
                usernameSettings["Color"] = "#6F6F6F";
                formatSettings["Chat"] = $"<color=#D8FF90>[L]</color> {{Title}} {{Username}} <color=#6F6F6F>{lang.GetMessage("Range3", this, sender.Id)}:</color> {{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<string, string>
            {
                ["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
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху