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

FREE CHit : 1.0.1 1.0.1

Нет прав для скачивания
C#:
using System;
using System.Globalization;
using UnityEngine;
using Oxide.Game.Rust.Cui;
using VLB;
namespace Oxide.Plugins {
    [Info("CHit", "TF Crazy", "1.0.1")]
    [Description("Display hit damage")]
    public class CHit : RustPlugin {
#region Fields
        private static string permUse = "chit.use";
#endregion
#region Server
        /// <summary>Iniialize</summary>
        private void OnServerInitialized() => permission.RegisterPermission(permUse, this);
        /// <summary>Display hit damage</summary>
        /// <param name="player">BasePlayer: Contain information about the player</param>
        /// <param name="info">HitInfo: Contain information about hit impact</param>
        private void OnPlayerAttack(BasePlayer player, HitInfo info) {
            if (player == null || player.IsNpc) return;
            if (info == null || info.HitEntity == null || info.HitEntity.IsDestroyed) return;
            if (!permission.UserHasPermission(player.UserIDString, permUse)) return;
            NextTick(() => {
                var posX = (UnityEngine.Random.Range(42.5f, 57.5f) / 100f);
                var posY = (UnityEngine.Random.Range(42.5f, 57.5f) / 100f);
                var container = new CuiElementContainer();
                var layer = $"CHit.{DateTime.Now}";
                float damage = (float)Math.Round(info.damageTypes.Total());
                string color = UI.Color("#ffffff", 1f);
                if (damage >= 1) {
                    if (damage >= 50) color = UI.Color("#cd4632", 1f);
                    UI.CreateTextElement(ref container, layer, color, $"{damage}", 15, posX, posY, 0.05f, 0.05f);
                }
                CuiHelper.AddUi(player, container);
                CuiHelper.DestroyUi(player, layer);
            }
            );
        }
#endregion
#region UI
        public class UI {
            /// <summary>Create text element</summary>
            /// <param name="container">ref CuiElementContainer: Contain container element</param>
            /// <param name="panel">String: Panel name</param>
            /// <param name="color">String: Color in rust format "r g b a"</param>
            /// <param name="text">String: Text to display</param>
            /// <param name="size">Int: Text size</param>
            /// <param name="x">Float: Anchor x</param>
            /// <param name="y">Float: Anchor y</param>
            /// <param name="width">Float: Width of element</param>
            /// <param name="height">Float: Height of element</param>
            /// <param name="align">TextAnchor: Text alignement</param>
            /// <param name="parent">String: Overlay layer</param>
            /// <param name="fadeout">Float: Fade effect</param>
            /// <param name="font">String: Font name</param>
            static public void CreateTextElement(ref CuiElementContainer container, string panel, string color, string text, int size, float x, float y, float width, float height, TextAnchor align = TextAnchor.MiddleCenter, string parent = "Hud", float fadeout = 1.5f, string font = "robotocondensed-bold.ttf") {
                string aMin = $"{x} {y}";
                string aMax = $"{x + width} {y + height}";
                CuiElement element = new CuiElement {
                    Name = panel, Parent = parent, FadeOut = fadeout, Components = {
                        new CuiTextComponent {
                            Text = text, Color = color, Font = font, FontSize = size, Align = align
                        }
                        , new CuiRectTransformComponent() {
                            AnchorMin = aMin, AnchorMax = aMax
                        }
                    }
                }
                ;
                container.Add(element);
            }
            /// <summary>Convert Hex color to Rust format</summary>
            /// <param name="hexColor">String: Hex code color</param>
            /// <param name="alpha">Float: opacity</param>
            /// <returns>Return string</returns>
            static public string Color(string hexColor, float alpha) {
                if (hexColor.StartsWith("#")) hexColor = hexColor.TrimStart('#');
                int red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
                int green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
                int blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
                return $"{(double)red / 255} {(double)green / 255} {(double)blue / 255} {alpha}";
            }
        }
#endregion
    }
}

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