Advertisement
Guest User

Death notes by Zubastic

a guest
Sep 22nd, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 35.18 KB | None | 0 0
  1. ]using System.Text.RegularExpressions;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using System;
  5. using System.Data;
  6. using UnityEngine;
  7. using Oxide.Core;
  8. using Oxide.Core.Plugins;
  9. using Oxide.Core.Libraries;
  10. using ProtoBuf;
  11. using System.Linq;
  12.  
  13. namespace Oxide.Plugins
  14. {
  15.     [Info("Death Notes", "LaserHydra", "3.3.41", ResourceId = 819)]
  16.     [Description("Broadcasts players/animals deaths to chat")]
  17.     class DeathNotes : RustPlugin
  18.     {
  19.         #region Settings
  20.         bool debugging = false;
  21.         string prefix = "";
  22.         string profile = "0";
  23.         List<string> metabolism = new List<string>();
  24.         List<string> playerDamageTypes = new List<string>();
  25.         List<string> barricadeDamageTypes = new List<string>();
  26.         List<string> traps = new List<string>();
  27.        
  28.         [PluginReference]
  29.         Plugin PopupNotifications;
  30.        
  31.         private readonly WebRequests webRequests = Interface.GetMod().GetLibrary<WebRequests>("WebRequests");
  32.         #endregion
  33.        
  34.         #region Commands
  35.         //    Toggle Debug-Mode
  36.         [ConsoleCommand("deathnotes.debug")]
  37.         void ToggleDebug(ConsoleSystem.Arg arg)
  38.         {
  39.             if(arg?.connection?.authLevel < 2) return;
  40.             if(debugging) debugging = false;
  41.             else debugging = true;
  42.         }
  43.        
  44.         //    Info Commands
  45.         [ChatCommand("deathnotes")]
  46.         void DeathnotesInfo(BasePlayer player, string cmd, string[] args)
  47.         {
  48.             ShowInfo(player);
  49.         }
  50.         #endregion
  51.        
  52.         #region Hooks
  53.         void Loaded()
  54.         {
  55.             if(!permission.PermissionExists("deathnotes.debug")) permission.RegisterPermission("deathnotes.debug", this);
  56.            
  57.             LoadDefaultConfig();
  58.            
  59.             if(!PopupNotifications)
  60.             {
  61.                 Puts("Popup Notifications can only be used if PopupNotifications is installed! Get it here: http://oxidemod.org/plugins/popup-notifications.1252/");
  62.             }
  63.            
  64.             prefix = "<color=" + Config["Colors", "Prefix"].ToString() + ">" + Config["Settings", "Prefix"].ToString() + "</color> ";
  65.             if((bool)Config["Settings", "EnablePluginIcon"]) profile = "76561198206240711";
  66.             metabolism = "Drowned Heat Cold Thirst Poison Hunger Radiation Bleeding Fall Generic".Split(' ').ToList();
  67.             playerDamageTypes = "Slash Blunt Stab Bullet".Split(' ').ToList();
  68.             barricadeDamageTypes = "Slash Stab".Split(' ').ToList();
  69.             traps = "Landmine.prefab Beartrap.prefab Floor_spikes.prefab".Split(' ').ToList();
  70.         }
  71.  
  72.         protected override void LoadDefaultConfig()
  73.         {
  74.             //  Settings
  75.             StringConfig("Settings", "Prefix", "DEATH NOTES<color=white>:</color>");
  76.             BoolConfig("Settings", "BroadcastToConsole", true);
  77.             BoolConfig("Settings", "UsePopupNotifications", false);
  78.             BoolConfig("Settings", "ShowSuicides", true);
  79.             BoolConfig("Settings", "ShowMetabolismDeaths", true);
  80.             BoolConfig("Settings", "ShowExplosionDeaths", true);
  81.             BoolConfig("Settings", "ShowTrapDeaths", true);
  82.             BoolConfig("Settings", "ShowAnimalDeaths", true);
  83.             BoolConfig("Settings", "ShowBarricadeDeaths", true);
  84.             BoolConfig("Settings", "ShowPlayerKills", true);
  85.             BoolConfig("Settings", "ShowAnimalKills", true);
  86.             BoolConfig("Settings", "MessageInRadius", false);
  87.             IntConfig("Settings", "MessageRadius", 300);
  88.             BoolConfig("Settings", "EnablePluginIcon", false);
  89.  
  90.             //  Animals
  91.            
  92.             StringConfig("Animals", "Stag", "Олень" );
  93.             StringConfig("Animals", "Boar", "Кабанчик" );
  94.             StringConfig("Animals", "Bear", "Медведь" );
  95.             StringConfig("Animals", "Chicken", "Петух" );
  96.             StringConfig("Animals", "Wolf", "Волк" );
  97.             StringConfig("Animals", "Horse", "Лошадь" );
  98.            
  99.             //  Colors
  100.             StringConfig("Colors", "Message", "#E0E0E0");
  101.             StringConfig("Colors", "Prefix", "grey");
  102.             StringConfig("Colors", "Animal", "#4B75FF");
  103.             StringConfig("Colors", "Bodypart", "#4B75FF");
  104.             StringConfig("Colors", "Weapon", "#4B75FF");
  105.             StringConfig("Colors", "Victim", "#4B75FF");
  106.             StringConfig("Colors", "Attacker", "#4B75FF");
  107.             StringConfig("Colors", "Distance", "#4B75FF");
  108.  
  109.             //  Messages
  110.             MessageConfig("Radiation", new List<string>{"{victim} не знает, что от радиации умирают"});
  111.             MessageConfig("Hunger", new List<string>{"{victim} умер от голода."});
  112.             MessageConfig("Thirst", new List<string>{"{victim} умер от жажды."});
  113.             MessageConfig("Drowned", new List<string>{"{victim} покормил рыбок."});
  114.             MessageConfig("Cold", new List<string>{"{victim} замерз до смерти."});
  115.             MessageConfig("Heat", new List<string>{"{victim} сгорел заживо."});
  116.             MessageConfig("Fall", new List<string>{"{victim} упал с большой высоты."});
  117.             MessageConfig("Bleeding", new List<string>{"{victim} умер от кровотечения."});
  118.             MessageConfig("Explosion", new List<string>{"{victim} взорвался."});
  119.             MessageConfig("Poision", new List<string>{"{victim} отравился."});
  120.             MessageConfig("Suicide", new List<string>{"{victim} самоубился."});
  121.             MessageConfig("Generic", new List<string>{"{victim} умер."});
  122.             MessageConfig("Unknown", new List<string>{"{victim} умер неизвестным науке способом."});
  123.             MessageConfig("Trap", new List<string>{"{victim} попался на {attacker}."});
  124.             MessageConfig("Barricade", new List<string>{"{victim} умер на {attacker}."});
  125.             MessageConfig("Stab", new List<string>{"{attacker} заколотил {victim} до смерти с помощью {weapon} попаданием в {bodypart}."});
  126.             MessageConfig("StabSleep", new List<string>{"{attacker} заколотил {victim} до смерти, пока он спал."});
  127.             MessageConfig("Slash", new List<string>{"{attacker} зарезал {victim} до смерти с помощью {weapon} попаданием в {bodypart}."});
  128.             MessageConfig("SlashSleep", new List<string>{"{attacker} зарезал {victim} до смерти, пока он спал."});
  129.             MessageConfig("Blunt", new List<string>{"{attacker} забил {victim} до смерти с помощьб {weapon} поподанием {bodypart}."});
  130.             MessageConfig("BluntSleep", new List<string>{"{attacker} забил {victim} с помощью {weapon} пока он спал"});
  131.             MessageConfig("Bullet", new List<string>{"{attacker} застрелил {victim} с помощью {weapon}, попав в {bodypart} с расстояния {distance}метров."});
  132.             MessageConfig("BulletSleep", new List<string>{"{attacker} застрелил {victim}, пока он спал. (Попал в {bodypart} с помощью {weapon}, с расстояния {distance}метров)"});
  133.             MessageConfig("Arrow", new List<string>{"{attacker} пронзил {victim} попав в {bodypart} с помощью стрелы с расстояния {distance}метров"});
  134.             MessageConfig("ArrowSleep", new List<string>{"{attacker} пронзил {victim} с помощью стрелы с расстояния {distance}метров, пока он спал."});
  135.             MessageConfig("Bite", new List<string>{"A {attacker} убил {victim}."});
  136.             MessageConfig("BiteSleep", new List<string>{"A {attacker} убил {victim}, пока он спал."});
  137.             MessageConfig("AnimalDeath", new List<string>{"{attacker} убил {victim} с помощью {weapon} с расстояния {distance}метров."});
  138.             MessageConfig("HelicopterDeath", new List<string>{"{attacker} убил {victim} с помощью {weapon} расстояния {distance}m."});
  139.         }
  140.        
  141.        
  142.         void OnEntityDeath(BaseCombatEntity vic, HitInfo hitInfo)
  143.         {
  144.             string weapon = "Unknown";
  145.             string attachments = "Unknown";
  146.             string msg = "Unknown";
  147.             string bodypart = "Unknown";
  148.             string dmg = "Unknown";
  149.             string victim = "Unknown";
  150.             string attacker = "Unknown";
  151.             bool sleeping = false;
  152.             string codeLocation = "OnEntityDeath Beginning";
  153.            
  154.             //###################################################//
  155.             //##############  LOCATION: Beginning  ##############//
  156.             //###################  PART: Main  ##################//
  157.             //###################################################//
  158.            
  159.             DebugMessage("PART: Main | LOCATION: Beginning");
  160.            
  161.             //    OnEntityDeath Beginning | Main: Declaration
  162.             codeLocation = "OnEntityDeath Beginning | Main: Declaration";
  163.             DebugMessage("AT: " + codeLocation);
  164.             try
  165.             {
  166.                 if(hitInfo == null) return;
  167.                
  168.                 dmg = FirstUpper(vic.lastDamage.ToString() ?? "Unknown");
  169.                 if((bool) string.IsNullOrEmpty(dmg)) dmg = "Unknown";
  170.                
  171.                 bodypart = StringPool.Get(hitInfo.HitBone) ?? "Unknown";
  172.                 if((bool) string.IsNullOrEmpty(bodypart)) bodypart = "Unknown";
  173.             }
  174.             catch(Exception ex)
  175.             {
  176.                 LogError(codeLocation, ex);
  177.                 return;
  178.             }
  179.            
  180.             //    OnEntityDeath Beginning | Main: Getting Attacker
  181.             codeLocation = "OnEntityDeath End | Message: Sending & New2Config";
  182.             DebugMessage("AT: " + codeLocation);
  183.             try
  184.             {
  185.                 if(hitInfo.Initiator != null)
  186.                 {
  187.                     if(hitInfo.Initiator.ToPlayer() != null)
  188.                     {
  189.                         attacker = hitInfo.Initiator.ToPlayer().displayName;
  190.                     }
  191.                     else
  192.                     {
  193.                         attacker = FirstUpper(hitInfo.Initiator.LookupShortPrefabName());
  194.                     }
  195.                 }
  196.                 else
  197.                 {
  198.                     attacker = "None";
  199.                 }
  200.             }
  201.             catch (Exception ex)
  202.             {
  203.                 LogError(codeLocation, ex);
  204.                 return;
  205.             }
  206.            
  207.             //###################################################//
  208.             //################  LOCATION: Middle  ###############//
  209.             //###################################################//
  210.            
  211.             DebugMessage("PART: Main | LOCATION: Middle");
  212.            
  213.             //    OnEntityDeath Middle | Main: Getting Victim
  214.             codeLocation = "OnEntityDeath Middle | Main: Getting Victim";
  215.             DebugMessage("AT: " + codeLocation);
  216.             try
  217.             {
  218.                 if(!vic.ToString().Contains("corpse"))
  219.                 {
  220.                     if(vic != null)
  221.                     {
  222.                         if(vic.ToPlayer() != null)
  223.                         {
  224.                             victim = vic.ToPlayer().displayName;
  225.                             sleeping = (bool)vic.ToPlayer().IsSleeping();
  226.                            
  227.                             //    Is it Suicide or Metabolism?
  228.                             if(dmg == "Suicide" && (bool)Config["Settings", "ShowSuicides"]) msg = dmg;
  229.                             if(metabolism.Contains(dmg) && (bool)Config["Settings", "ShowMetabolismDeaths"]) msg = dmg;
  230.                            
  231.                             //    Is Attacker a Player?
  232.                             if(hitInfo.Initiator != null && hitInfo.Initiator.ToPlayer() != null && playerDamageTypes.Contains(dmg) && hitInfo.WeaponPrefab.ToString().Contains("grenade") == false && hitInfo.WeaponPrefab.ToString().Contains("survey") == false)
  233.                             {
  234.                                 if(hitInfo.WeaponPrefab.ToString().Contains("hunting") || hitInfo.WeaponPrefab.ToString().Contains("bow"))
  235.                                 {
  236.                                     if(sleeping) msg = "ArrowSleep";
  237.                                     else msg = "Arrow";
  238.                                 }
  239.                                 else
  240.                                 {
  241.                                     if(sleeping) msg = dmg + "Sleep";
  242.                                     else msg = dmg;
  243.                                 }
  244.                             }
  245.                             //    Is Attacker an explosive?
  246.                             else if(hitInfo.WeaponPrefab != null || dmg == "Explosion" && (bool)Config["Settings", "ShowExplosionDeaths"])
  247.                             {
  248.                                 if(hitInfo.WeaponPrefab.ToString().Contains("grenade") == false && hitInfo.WeaponPrefab.ToString().Contains("survey") == false && dmg != "Explosion") return;
  249.                            
  250.                                 msg = "Explosion";
  251.                             }
  252.                             //    Is Attacker a trap?
  253.                             else if(traps.Contains(attacker) && (bool)Config["Settings", "ShowTrapDeaths"])
  254.                             {
  255.                                 msg = "Trap";
  256.                             }
  257.                             //    Is Attacker a Barricade?
  258.                             else if(barricadeDamageTypes.Contains(dmg) && (bool)Config["Settings", "ShowBarricadeDeaths"])
  259.                             {
  260.                                 msg = "Barricade";
  261.                             }
  262.                             //    Is Attacker an Animal?
  263.                             else if(dmg == "Bite" && (bool)Config["Settings", "ShowAnimalKills"])
  264.                             {
  265.                                 if(sleeping) msg = "BiteSleep";
  266.                                 else msg = "Bite";
  267.                             }
  268.                             //    Is Attacker an Heli?
  269.                             else if(hitInfo.Initiator.LookupShortPrefabName().ToString().Contains("patrolhelicopter"))
  270.                             {
  271.                                 msg = "HelicopterDeath";
  272.                             }
  273.                         }
  274.                         //    Victim is an Animal
  275.                         else if(vic.ToString().Contains("animals") && (bool)Config["Settings", "ShowAnimalDeaths"])
  276.                         {
  277.                             victim = FirstUpper(vic.LookupShortPrefabName());  
  278.                             msg = "AnimalDeath";
  279.                             if(dmg == "Explosion") msg = "Explosion";
  280.                         }
  281.                     }
  282.                 }
  283.             }
  284.             catch (Exception ex)
  285.             {
  286.                 LogError(codeLocation, ex);
  287.                 return;
  288.             }
  289.             //###################################################//
  290.             //#################  LOCATION: End  #################//
  291.             //#################  PART: Message  #################//
  292.             //###################################################//
  293.            
  294.             DebugMessage("PART: Message | LOCATION: End");
  295.            
  296.             if(msg != null)
  297.             {
  298.                 //    OnEntityDeath End | Message: Silencer Check
  299.                 codeLocation = "OnEntityDeath End | Message: Silencer Check";
  300.                 DebugMessage("AT: " + codeLocation);
  301.                 try
  302.                 {
  303.                     weapon = hitInfo?.Weapon?.GetItem().info?.displayName?.english?.ToString();
  304.                     if(weapon != null && weapon.Contains("Semi-Automatic Pistol")) weapon = "Semi-Automatic Pistol";
  305.                    
  306.                     if (hitInfo.Weapon?.GetItem()?.contents?.itemList != null)
  307.                     {
  308.                         List<string> contents = new List<string>();
  309.                         foreach (var content in hitInfo.Weapon.GetItem().contents.itemList)
  310.                         {
  311.                             contents.Add(content.info.displayName.english);
  312.                         }
  313.                        
  314.                         attachments = ArrayToString(contents.ToArray(), 0, " + ");
  315.                     }
  316.                 }
  317.                 catch(Exception ex)
  318.                 {
  319.                     LogError(codeLocation, ex);
  320.                     return;
  321.                 }
  322.                
  323.                 string formattedDistance = "0";
  324.                 string formattedVictim = "Unknown";
  325.                 string formattedAttacker = "Unknown";
  326.                 string formattedAnimal = "Unknown";
  327.                 string formattedBodypart = "Unknown";
  328.                 string formattedWeapon = "Unknown";
  329.                 string rawVictim = "Unknown";
  330.                 string rawAttacker = "Unknown";
  331.                 string rawAnimal = "Unknown";
  332.                 string rawBodypart = "Unknown";
  333.                 string rawWeapon = "Unknown";
  334.                
  335.                 string deathmsg = "";
  336.                 string rawmsg = "";
  337.                
  338.                 //    OnEntityDeath End | Message: Declaration
  339.                 codeLocation = "OnEntityDeath End | Message: Declaration";
  340.                 DebugMessage("AT: " + codeLocation);
  341.                 try
  342.                 {
  343.                     if(hitInfo.WeaponPrefab != null && hitInfo.WeaponPrefab.ToString().Contains("f1")) weapon = "Граната F1";
  344.                     else if(hitInfo.WeaponPrefab != null && hitInfo.WeaponPrefab.ToString().Contains("beancan")) weapon = "Бобовая граната";
  345.                     else if(hitInfo.WeaponPrefab != null && hitInfo.WeaponPrefab.ToString().Contains("timed")) weapon = "С4";
  346.                     else if(hitInfo.WeaponPrefab != null && hitInfo.WeaponPrefab.ToString().Contains("rocket")) weapon = "Ракетница";
  347.                     else if(hitInfo.WeaponPrefab != null && hitInfo.WeaponPrefab.ToString().Contains("survey")) weapon = "Геологический заряд";
  348.                     formattedVictim = GetFormattedVictim(victim ?? "Unknown", false);
  349.                     rawVictim = GetFormattedVictim(victim ?? "Unknown", true);
  350.                    
  351.                     if(hitInfo.Initiator != null)
  352.                     {
  353.                         if(attachments != "" && attachments != "Unknown")
  354.                         {
  355.                             formattedWeapon = GetFormattedWeapon(weapon + " (" + attachments + ")" ?? "Unknown");
  356.                             rawWeapon = weapon + " (" + attachments + ")" ?? "Unknown";
  357.                         }
  358.                         else
  359.                         {
  360.                             formattedWeapon = GetFormattedWeapon(weapon ?? "Unknown");
  361.                             rawWeapon = weapon ?? "Unknown";
  362.                         }
  363.                        
  364.                         formattedBodypart = GetFormattedBodypart(bodypart ?? "Unknown", false);
  365.                         formattedAnimal = GetFormattedAnimal(attacker ?? "Unknown", false);
  366.                         formattedAttacker = GetFormattedAttacker(attacker ?? "Unknown", false);
  367.                         formattedDistance = GetFormattedDistance(GetDistance(vic, hitInfo.Initiator) ?? "0");
  368.                        
  369.                         rawBodypart = GetFormattedBodypart(bodypart ?? "Unknown", true);
  370.                         rawAnimal = GetFormattedAnimal(attacker ?? "Unknown", true);
  371.                         rawAttacker = GetFormattedAttacker(attacker ?? "Unknown", true);
  372.                     }
  373.                     deathmsg = GetRandomMessage(msg) ?? GetRandomMessage("Unknown");
  374.                     rawmsg = GetRandomMessage(msg) ?? GetRandomMessage("Unknown");
  375.                    
  376.                     deathmsg = deathmsg.Replace("{victim}", formattedVictim);
  377.                     rawmsg = rawmsg.Replace("{victim}", rawVictim);
  378.                    
  379.                     if(hitInfo.Initiator != null)
  380.                     {
  381.                         if(msg == "Bite") deathmsg = deathmsg.Replace("{attacker}", formattedAnimal);
  382.                         else deathmsg = deathmsg.Replace("{attacker}", formattedAttacker);
  383.                        
  384.                         if(msg == "Bite") rawmsg = rawmsg.Replace("{attacker}", rawAnimal);
  385.                         else rawmsg = rawmsg.Replace("{attacker}", rawAttacker);
  386.                     }
  387.                 }
  388.                 catch(Exception ex)
  389.                 {
  390.                     LogError(codeLocation, ex);
  391.                     return;
  392.                 }
  393.                
  394.                 //    OnEntityDeath End | Message: Check for needed vars
  395.                 codeLocation = "OnEntityDeath End | Message: Check for needed vars";
  396.                 DebugMessage("AT: " + codeLocation);
  397.                 try
  398.                 {
  399.                     if (vic.ToString().Contains("animals") && hitInfo.Initiator == null)
  400.                     {
  401.                         return;
  402.                     }
  403.                    
  404.                     if (vic.ToString().Contains("animals") && hitInfo.Initiator.ToString().Contains("animals"))
  405.                     {
  406.                         return;
  407.                     }
  408.                    
  409.                     if(vic.ToPlayer() == null && hitInfo.Initiator == null)
  410.                     {
  411.                         return;
  412.                     }
  413.                 }
  414.                 catch (Exception ex)
  415.                 {
  416.                     LogError(codeLocation, ex);
  417.                     return;
  418.                 }
  419.                
  420.                 if(formattedBodypart != null) deathmsg = deathmsg.Replace("{bodypart}", formattedBodypart);
  421.                 if(hitInfo.Initiator != null) deathmsg = deathmsg.Replace("{distance}", formattedDistance);
  422.                 if(hitInfo.Weapon != null || hitInfo.WeaponPrefab != null) deathmsg = deathmsg.Replace("{weapon}", formattedWeapon);
  423.                
  424.                 if(formattedBodypart != null) rawmsg = rawmsg.Replace("{bodypart}", rawBodypart);
  425.                 if(hitInfo.Initiator != null) rawmsg = rawmsg.Replace("{distance}", GetDistance(vic, hitInfo.Initiator));
  426.                 if(hitInfo.Weapon != null || hitInfo.WeaponPrefab != null) rawmsg = rawmsg.Replace("{weapon}", rawWeapon);
  427.                
  428.                 if (msg.Contains("HelicopterDeath"))
  429.                 {
  430.                     deathmsg = deathmsg.Replace("{weapon}", ("<color=" + Config["Colors", "Attacker"].ToString() + ">" + ((dmg == "Bullet") ? "Heli Machine Gun" : "Heli Rocket Launcher") + "</color>"));
  431.                     rawmsg = rawmsg.Replace("{weapon}", (dmg == "Bullet") ? "Heli Machine Gun" : "Heli Rocket Launcher");
  432.                 }
  433.                 //    OnEntityDeath End | Message: Sending & New2Config
  434.                 codeLocation = "OnEntityDeath End | Message: Sending & New2Config";
  435.                 DebugMessage("AT: " + codeLocation);
  436.                 try
  437.                 {
  438.                     if(victim == "Unknown" && BasePlayer.Find(victim) == null) return;
  439.                     if((bool) string.IsNullOrEmpty(rawBodypart)) rawBodypart = "Unknown";
  440.                     if((bool) string.IsNullOrEmpty(weapon)) weapon = "Unknown";
  441.                     if(msg != "AnimalDeath") AddNewToConfig(rawBodypart, weapon);
  442.                     BroadcastDeath(prefix + GetFormattedMessage(deathmsg), rawmsg, vic);
  443.                 }
  444.                 catch (Exception ex)
  445.                 {
  446.                     LogError(codeLocation, ex);
  447.                     return;
  448.                 }
  449.             }
  450.         }
  451.         #endregion
  452.    
  453.    
  454.         #region FormattingMethods      
  455.         string GetRandomMessage(string msg)
  456.         {
  457.             DebugMessage("GetRandomMessage(" + msg + ")");
  458.             List<object> messages = Config["Messages", msg] as List<object>;
  459.            
  460.             string rndmMsg = "";
  461.             int rndm = Convert.ToInt32(Oxide.Core.Random.Range(0, Convert.ToInt32(messages.Count())));
  462.             rndmMsg = messages[rndm]?.ToString() ?? "{victim} died by an unknown reason";
  463.             return rndmMsg;
  464.         }
  465.        
  466.         string FirstUpper(string s)
  467.         {
  468.             DebugMessage("FirstUpper(" + s + ")");
  469.             if (string.IsNullOrEmpty(s))
  470.             {
  471.                 return string.Empty;
  472.             }
  473.            
  474.             return char.ToUpper(s[0]) + s.Substring(1);
  475.         }
  476.          
  477.         string GetFormattedAttacker(string attacker, bool raw)
  478.         {
  479.             DebugMessage("GetFormattedAttacker(" + attacker + ", " + raw.ToString() + ")");
  480.             attacker = attacker.Replace(".prefab", "");
  481.             attacker = attacker.Replace("Beartrap", "Капкан");
  482.             attacker = attacker.Replace("Patrolhelicopter", "Вертолёт");
  483.             attacker = attacker.Replace("Floor_spikes", "Деревянные колья");
  484.             attacker = attacker.Replace("Gates.external.high.wood", "Деревянные ворота");
  485.             attacker = attacker.Replace("Wall.external.high.stone", "Высокая каменная стена");
  486.             attacker = attacker.Replace("Barricade.woodwire", "Деревянная барикада с шипами");
  487.             attacker = attacker.Replace("Wall.external.high.wood", "Высокая деревянная стена");
  488.             attacker = attacker.Replace("Barricade.wood", "Деревянная баррикада");
  489.             attacker = attacker.Replace("Barricade.metal", "Металлическая баррикада");
  490.             if(!raw)
  491.             {
  492.                 if (attacker.Contains("Helicopter"))
  493.                 {
  494.                     attacker = "<color=orange>" + attacker + "</color>";
  495.                 }
  496.                 else
  497.                 {
  498.                     attacker = "<color=" + Config["Colors", "Attacker"].ToString() + ">" + attacker + "</color>";
  499.                 }
  500.             }
  501.             return attacker;
  502.         }
  503.        
  504.         string GetFormattedVictim(string victim, bool raw)
  505.         {
  506.             DebugMessage("GetFormattedVictim(" + victim + ", " + raw.ToString() + ")");
  507.             victim = victim.Replace(".prefab", "");
  508.             if(Config["Animals", victim] != null) victim = (string)Config["Animals", victim];
  509.             if(!raw) victim = "<color=" + Config["Colors", "Victim"].ToString() + ">" + victim + "</color>";
  510.             return victim;
  511.         }
  512.        
  513.         string GetFormattedDistance(string distance)
  514.         {
  515.             DebugMessage("GetFormattedDistance(" + distance + ")");
  516.             distance = "<color=" + Config["Colors", "Distance"].ToString() + ">" + distance + "</color>";
  517.             return distance;
  518.         }
  519.        
  520.         string GetFormattedMessage(string message)
  521.         {
  522.             DebugMessage("GetFormattedMessage(" + message + ")");
  523.             message = "<color=" + Config["Colors", "Message"].ToString() + ">" + message + "</color>";
  524.             return message;
  525.         }
  526.        
  527.         string GetFormattedWeapon(string weapon)
  528.         {
  529.             DebugMessage("GetFormattedWeapon(" + weapon + ")");
  530.             ConfigWeapon(weapon);
  531.             weapon = "<color=" + Config["Colors", "Weapon"].ToString() + ">" + Config["Weapons", weapon] + "</color>";
  532.             return weapon;
  533.         }
  534.        
  535.         string GetFormattedAnimal(string animal, bool raw)
  536.         {
  537.             DebugMessage("GetFormattedAnimal(" + animal + ")");
  538.             animal = animal.Replace(".prefab", "");
  539.             if(!raw) animal = "<color=" + Config["Colors", "Animal"].ToString() + ">" + Config["Animals", animal] + "</color>";
  540.             return animal;
  541.         }
  542.        
  543.         string GetFormattedBodypart(string bodypart, bool raw)
  544.         {
  545.             DebugMessage("GetFormattedBodypart(" + bodypart + ", " + raw.ToString() + ")");
  546.             for(int i = 0; i < 10; i++)
  547.             {
  548.                 bodypart = bodypart.Replace(i.ToString(), "");
  549.             }
  550.             bodypart = bodypart.Replace(".prefab", "");
  551.             bodypart = bodypart.Replace("L", "");
  552.             bodypart = bodypart.Replace("R", "");
  553.             bodypart = bodypart.Replace("_", "");
  554.             bodypart = bodypart.Replace(".", "");
  555.             bodypart = bodypart.Replace("right", "");
  556.             bodypart = bodypart.Replace("left", "");
  557.             bodypart = bodypart.Replace("tranform", "");
  558.             bodypart = bodypart.Replace("lowerjaweff", "jaw");
  559.             bodypart = bodypart.Replace("rarmpolevector", "arm");
  560.             bodypart = bodypart.Replace("connection", "");
  561.             bodypart = bodypart.Replace("uppertight", "tight");
  562.             bodypart = bodypart.Replace("fatjiggle", "");
  563.             bodypart = bodypart.Replace("fatend", "");
  564.             bodypart = bodypart.Replace("seff", "");
  565.            
  566.             bodypart = FirstUpper(bodypart);
  567.            
  568.             ConfigBodypart(bodypart);
  569.            
  570.             if(!raw) bodypart = "<color=" + Config["Colors", "Bodypart"].ToString() + ">" + Config["Bodyparts", bodypart].ToString() + "</color>";
  571.            
  572.             return bodypart;
  573.         }
  574.         #endregion
  575.        
  576.         #region UsefulMethods
  577.         //--------------------------->   Webrequest   <---------------------------//
  578.        
  579.         void ShowInfo(BasePlayer player)
  580.         {
  581.             webRequests.EnqueueGet("http://oxidemod.org/plugins/death-notes.819/", (code, response) => VersionRecieved(code, response, player), this);
  582.         }
  583.        
  584.         void VersionRecieved(int code, string response, BasePlayer player)
  585.         {
  586.             if (response == null || code != 200)
  587.             {
  588.                 Puts("Web Request failed.");
  589.             }
  590.            
  591.             string version = "0.0.0";
  592.             Match match = new Regex(@"<h\d>Version (\d+(?:\.\d+){1,3})<\/h\d>").Match(response);
  593.             if(match.Success) version = match.Groups[1].ToString();
  594.            
  595.             SendChatMessage(player, "<size=25><color=grey>Death Notes</color></size><color=grey> by LaserHydra\nInstalled Version:</color> " + this.Version + "\n<color=grey>Latest Version:</color> " + version, null, profile);
  596.         }
  597.        
  598.         //---------------------------->   Converting   <----------------------------//
  599.  
  600.         string ArrayToString(string[] array, int first, string seperator)
  601.         {
  602.             string output = String.Join(seperator, array.Skip(first).ToArray());
  603.            
  604.             return output;
  605.         }
  606.        
  607.         //------------------------------>   Config   <------------------------------//
  608.        
  609.         void AddNewToConfig(string bodypart, string weapon)
  610.         {
  611.             ConfigWeapon(weapon);
  612.             ConfigBodypart(bodypart);
  613.            
  614.             SaveConfig();
  615.         }
  616.        
  617.         void MessageConfig(string MsgName, List<string> Data)
  618.         {
  619.             if (Config["Messages", MsgName] == null) Config["Messages", MsgName] = Data;
  620.         }
  621.        
  622.         void ConfigWeapon(string weapon)
  623.         {
  624.             if (Config["Weapons", weapon] == null) Config["Weapons", weapon] = weapon;
  625.         }
  626.        
  627.         void ConfigBodypart(string bodypart)
  628.         {
  629.             if (Config["Bodyparts", bodypart] == null) Config["Bodyparts", bodypart] = bodypart;
  630.         }
  631.        
  632.         void StringConfig(string GroupName, string DataName, string Data)
  633.         {
  634.             if (Config[GroupName, DataName] == null) Config[GroupName, DataName] = Data;
  635.         }
  636.  
  637.         void BoolConfig(string GroupName, string DataName, bool Data)
  638.         {
  639.             if (Config[GroupName, DataName] == null) Config[GroupName, DataName] = Data;
  640.         }
  641.  
  642.         void IntConfig(string GroupName, string DataName, int Data)
  643.         {
  644.             if (Config[GroupName, DataName] == null) Config[GroupName, DataName] = Data;
  645.         }
  646.  
  647.         //------------------------------>   Vector3   <------------------------------//
  648.        
  649.         string GetDistance(BaseCombatEntity victim, BaseEntity attacker)
  650.         {
  651.             string distance = Convert.ToInt32(Vector3.Distance(victim.transform.position, attacker.transform.position)).ToString();
  652.             return distance;
  653.         }
  654.        
  655.         //---------------------------->   Chat Sending   <----------------------------//
  656.  
  657.         void BroadcastChat(string prefix, string msg = null)
  658.         {
  659.  
  660.             if (msg != null)
  661.             {
  662.                 PrintToChat("<color=orange>" + prefix + "</color>: " + msg);
  663.             }
  664.             else
  665.             {
  666.                 msg = prefix;
  667.                 PrintToChat(msg);
  668.             }
  669.         }
  670.  
  671.         void SendChatMessage(BasePlayer player, string prefix, string msg = null, string userid = "0")
  672.         {
  673.             if (player?.net == null) return;
  674.             if (msg != null)
  675.             {
  676.                 player.SendConsoleCommand("chat.add", userid, "<color=orange>" + prefix + "</color>: " + msg, 1.0);
  677.             }
  678.             else
  679.             {
  680.                 msg = prefix;
  681.                 player.SendConsoleCommand("chat.add", userid, msg, 1.0);
  682.             }
  683.         }
  684.        
  685.         void BroadcastDeath(string deathmessage, string rawmessage, BaseEntity victim)
  686.         {
  687.             DebugMessage("Chatmsg: " + deathmessage + ", Rawmsg: " + rawmessage);
  688.             if((bool)Config["Settings", "MessageInRadius"])
  689.             {
  690.                 foreach(BasePlayer player in BasePlayer.activePlayerList)
  691.                 {
  692.                     if(Convert.ToInt32(GetDistance(player, victim)) <= (int)Config["Settings", "MessageRadius"]) player.SendConsoleCommand("chat.add", profile, deathmessage, 1.0);
  693.                 }
  694.             }
  695.             else ConsoleSystem.Broadcast("chat.add", profile, deathmessage, 1.0);
  696.            
  697.             if((bool)Config["Settings", "UsePopupNotifications"]) PopupNotifications?.Call("CreatePopupNotification", deathmessage);
  698.            
  699.             if((bool)Config["Settings", "BroadcastToConsole"]) Puts(rawmessage);
  700.             ConVar.Server.Log("oxide/logs/DeathNotes_Kills.txt", rawmessage);
  701.         }
  702.        
  703.         void LogError(string where, Exception ex)
  704.         {
  705.             ConVar.Server.Log("oxide/logs/DeathNotes_ErrorLog.txt", "FAILED AT: " + where + " | " + ex.ToString() + "\n");
  706.             //Puts("FAILED AT: " + where + " | " + ex.StackTrace.ToString());
  707.         }
  708.        
  709.         void DebugMessage(string message)
  710.         {
  711.             if(debugging == false) return;
  712.             Puts(message);
  713.            
  714.             foreach(var cur in BasePlayer.activePlayerList)
  715.             {
  716.                 if(cur.displayName == "John[BOT]") continue;
  717.                 if(permission.UserHasPermission(cur.userID.ToString(), "deathnotes.debug")) cur.SendConsoleCommand("echo '<color=red>" + message + "</color>'");
  718.             }
  719.         }
  720.  
  721.         //---------------------------------------------------------------------------//
  722.         #endregion
  723.     }
  724. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement