From 815d94f74bff8e41aa051c1b86cbc18ed2814a55 Mon Sep 17 00:00:00 2001 From: bmgjet <50484759+bmgjet@users.noreply.github.com> Date: Sat, 19 Jun 2021 14:49:29 +1200 Subject: [PATCH] Add files via upload --- RocketFail.cs | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 RocketFail.cs diff --git a/RocketFail.cs b/RocketFail.cs new file mode 100644 index 0000000..5068c99 --- /dev/null +++ b/RocketFail.cs @@ -0,0 +1,126 @@ +using Newtonsoft.Json; +using System.Collections.Generic; +using UnityEngine; +using Random = System.Random; + +namespace Oxide.Plugins +{ + [Info("RocketFail", "bmgjet", "1.0.0")] + [Description("Player takes damage when launcher breaks.")] + public class RocketFail : RustPlugin + { + #region Vars + private const string permUse = "RocketFail.use"; + private PluginConfig config; + #endregion + + #region Language + protected override void LoadDefaultMessages() + { + lang.RegisterMessages(new Dictionary + { + {"exploded", "Weapon Exploded!"} + }, this); + } + + private void message(BasePlayer chatplayer, string key, params object[] args) + { + if (chatplayer == null) { return; } + var message = string.Format(lang.GetMessage(key, this, chatplayer.UserIDString), args); + chatplayer.ChatMessage(message); + } + #endregion + + #region Configuration + private class PluginConfig + { + [JsonProperty(PropertyName = "Explode min condition : ")] public float MinHealth { get; set; } + [JsonProperty(PropertyName = "HV hurt ammount : ")] public int HVHurt { get; set; } + [JsonProperty(PropertyName = "Fire hurt ammount : ")] public int FireHurt { get; set; } + [JsonProperty(PropertyName = "Exposive hurt ammount : ")] public int ExpHurt { get; set; } + [JsonProperty(PropertyName = "HE hurt ammount : ")] public int HeHurt { get; set; } + [JsonProperty(PropertyName = "Smoke hurt ammount : ")] public int SmokeHurt { get; set; } + [JsonProperty(PropertyName = "Bleed ammount : ")] public int BleedHurt { get; set; } + [JsonProperty(PropertyName = "Randomise launcher break : ")] public bool Randomise { get; set; } + [JsonProperty(PropertyName = "Condition to trigger randomise : ")] public float RandomiseTrigger { get; set; } + [JsonProperty(PropertyName = "Randomise 1 out of X chance to explode : ")] public int RandomiseChance { get; set; } + } + + private PluginConfig GetDefaultConfig() + { + return new PluginConfig + { + MinHealth = 5f, + HVHurt = 40, + FireHurt = 35, + ExpHurt = 70, + HeHurt = 50, + SmokeHurt = 15, + BleedHurt = 10, + Randomise = false, + RandomiseTrigger = 20, + RandomiseChance = 50 + }; + } + + protected override void LoadDefaultConfig() + { + Config.Clear(); + Config.WriteObject(GetDefaultConfig(), true); + config = Config.ReadObject(); + } + + protected override void SaveConfig() + { + Config.WriteObject(config, true); + } + #endregion + + #region Oxide Hooks + private void Init() + { + permission.RegisterPermission(permUse, this); + config = Config.ReadObject(); + if (config == null) { LoadDefaultConfig(); } + } + + private void OnRocketLaunched(BasePlayer player, BaseEntity baseEntity2) + { + if (player.IPlayer.HasPermission(permUse)) + { + var weapon = player.GetActiveItem().GetHeldEntity() as BaseProjectile; + if (weapon == null || baseEntity2 == null || player == null) return; + float weaponcondition = player.GetActiveItem().condition; + string Ammotype = baseEntity2.ShortPrefabName; + if (config.Randomise) + { + if (weaponcondition <= config.RandomiseTrigger) + { + Random random = new Random(); + if (random.Next(0, config.RandomiseChance) == random.Next(0, config.RandomiseChance)) { weaponcondition = 0; } + } + } + if (weaponcondition <= config.MinHealth) + { + int GiveDamage = 0; + switch (Ammotype) + { + case "rocket_hv": GiveDamage = config.HVHurt; break; + case "rocket_fire": GiveDamage = config.FireHurt; break; + case "rocket_basic": GiveDamage = config.ExpHurt; break; + case "40mm_grenade_he": GiveDamage = config.HeHurt; break; + case "40mm_grenade_smoke": GiveDamage = config.SmokeHurt; break; + } + var finaleffect = new Effect("assets/bundled/prefabs/fx/explosions/explosion_01.prefab", player, 0, Vector3.zero, Vector3.forward); + EffectNetwork.Send(finaleffect, player.net.connection); + message(player, "exploded"); + player.GetActiveItem().condition = 0; + weapon.UpdateItemCondition(); + player.Hurt(GiveDamage); + player.metabolism.bleeding.SetValue(config.BleedHurt); + } + } + } + #endregion + } +} \ No newline at end of file