Esempio n. 1
0
        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo)
        {
            var tick = DateTime.Now;

            try
            {
                if (!hitInfo.damageTypes.Has(Rust.DamageType.Decay))
                {
                    return;
                }

                var block = entity as BuildingBlock;
                if (entity.LookupShortPrefabName().StartsWith("campfire_deployed"))
                {
                    ProcessCampfireDamage(hitInfo);
                }
                else if (block != null)
                {
                    ProcessBuildingDamage(block, hitInfo);
                }
                else
                {
                    Puts($"Unsupported decaying entity detected: {entity.LookupShortPrefabName()} --- please notify author");
                }
            }
            finally
            {
                var ms = (DateTime.Now - tick).TotalMilliseconds;
                if (ms > 10)
                {
                    Puts($"NoDecay.OnEntityTakeDamage took {ms} ms to execute.");
                }
            }
        }
Esempio n. 2
0
        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            if (!Economics)
            {
                return;
            }
            if (!entity.GetComponent("BaseNPC"))
            {
                return;
            }
            if (!info.Initiator?.ToPlayer())
            {
                return;
            }

            var player = info.Initiator?.ToPlayer();
            var animal = UppercaseFirst(entity.LookupShortPrefabName().Replace(".prefab", ""));

            int amount;

            if (!config.Settings.Rewards.TryGetValue(animal, out amount) || amount <= 0)
            {
                return;
            }

            Economics.CallHook("Deposit", player.userID, amount);

            if (config.Settings.ShowMessages)
            {
                PrintToChat(player, string.Format(config.Messages[PluginMessage.ReceivedForKill], amount, animal.ToLower()));
            }
        }
Esempio n. 3
0
        private object CanBeTargeted(BaseCombatEntity target, MonoBehaviour turret)
        {
            if (!(turret is AutoTurret))
            {
                return(null);
            }

            if (animalOverride == true && target.GetComponent <BaseNPC>() != null)
            {
                if (animals.Count > 0)
                {
                    if (animals.Contains(target.LookupShortPrefabName().Replace(".prefab", "").ToLower()))
                    {
                        return(false);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(false);
                }
            }

            if (target.ToPlayer() == null)
            {
                return(null);
            }

            BasePlayer targetPlayer = target.ToPlayer();

            if (targetPlayer.IsAlive() && !targetPlayer.IsSleeping())
            {
                var isInvisible = Vanish?.Call("IsInvisible", target);
                if (isInvisible != null && (bool)isInvisible)
                {
                    return(null);
                }

                var isStealthed = Skills?.Call("isStealthed", target);
                if (isStealthed != null && (bool)isStealthed)
                {
                    return(false);
                }
            }

            if (adminOverride && targetPlayer.IsConnected() && targetPlayer.net.connection.authLevel > 0)
            {
                return(false);
            }
            else if (sleepOverride && targetPlayer.IsSleeping())
            {
                return(false);
            }

            return(null);
        }
Esempio n. 4
0
        private static void TryReturnLadder(BasePlayer player, BaseCombatEntity entity)
        {
            var item = ItemManager.CreateByName(Regex.Replace(entity.LookupShortPrefabName(), @"\.prefab$", string.Empty));

            if (item != null)
            {
                player.GiveItem(item);
            }
        }
Esempio n. 5
0
        public bool IsBlocked(BaseCombatEntity entity)
        {
            if (entity is BuildingBlock)
            {
                return(true);
            }

            string prefabName = entity.LookupShortPrefabName();

            foreach (string p in prefabs)
            {
                if (prefabName.IndexOf(p) != -1)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 6
0
        string GetVictim(BaseCombatEntity vic)
        {
            string victim = "Unknown Victim";

            if (vic != null)
            {
                if (vic.ToPlayer() != null)
                {
                    victim = vic.ToPlayer().displayName;
                }
                else
                {
                    victim = FirstUpper(vic.LookupShortPrefabName() ?? "Unknown Victim");
                    victim = victim.Replace(".prefab", "");
                }
            }

            return(victim);
        }
Esempio n. 7
0
        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo)
        {
            var tick = DateTime.Now;
            try
            {
                if (!hitInfo.damageTypes.Has(Rust.DamageType.Decay)) return;

                var block = entity as BuildingBlock;
                if (entity.LookupShortPrefabName().StartsWith("campfire_deployed"))
                    ProcessCampfireDamage(hitInfo);
                else if (block != null)
                    ProcessBuildingDamage(block, hitInfo);
                else
                    Puts($"Unsupported decaying entity detected: {entity.LookupShortPrefabName()} --- please notify author");
            }
            finally
            {
                var ms = (DateTime.Now - tick).TotalMilliseconds;
                if (ms > 10) Puts($"NoDecay.OnEntityTakeDamage took {ms} ms to execute.");
            }
        }
Esempio n. 8
0
        string GetVictim(BaseCombatEntity vic)
        {
            string victim = "Unknown Victim";

            if(vic != null)
            {
                if(vic.ToPlayer() != null)
                {
                    victim = vic.ToPlayer().displayName;
                }
                else
                {
                    victim = FirstUpper(vic.LookupShortPrefabName() ?? "Unknown Victim");
                    victim = victim.Replace(".prefab", "");
                }
            }

            return victim;
        }
Esempio n. 9
0
        void OnEntityDeath(BaseCombatEntity vic, HitInfo hitInfo)
        {
            if (hitInfo == null)
            {
                return;
            }

            string weapon = "";
            string msg    = null;

            string dmg = FirstUpper(vic.lastDamage.ToString());

            if (dmg == null || dmg == "")
            {
                dmg = "None";
            }

            string bodypart = GetFormattedBodypart(StringPool.Get(hitInfo.HitBone), true);

            if (bodypart == null || bodypart == "")
            {
                bodypart = "None";
            }

            string victim   = "";
            string attacker = null;
            bool   sleeping = false;

            try
            {
                if (hitInfo.Initiator != null)
                {
                    if (hitInfo.Initiator.ToPlayer() != null)
                    {
                        attacker = hitInfo.Initiator.ToPlayer().displayName;
                    }
                    else
                    {
                        attacker = FirstUpper(hitInfo.Initiator.LookupShortPrefabName());
                    }
                }
                else
                {
                    attacker = "None";
                }
            }
            catch (Exception ex)
            {
                ConVar.Server.Log("Oxide/Logs/DeathNotes_ErrorLog.txt", "Failed at getting attacker: " + ex.Message.ToString());
                return;
            }

            try
            {
                if (!vic.ToString().Contains("corpse"))
                {
                    if (vic != null)
                    {
                        if (vic.ToPlayer() != null)
                        {
                            victim = vic.ToPlayer().displayName;

                            sleeping = (bool)vic.ToPlayer().IsSleeping();

                            //	Is it Suicide or Metabolism?
                            if (dmg == "Suicide" && (bool)Config["Settings", "ShowSuicides"])
                            {
                                msg = dmg;
                            }
                            if (metabolism.Contains(dmg) && (bool)Config["Settings", "ShowMetabolismDeaths"])
                            {
                                msg = dmg;
                            }

                            //	Is Attacker a Player?
                            if (hitInfo.Initiator != null && hitInfo.Initiator.ToPlayer() != null && playerDamageTypes.Contains(dmg) && hitInfo.WeaponPrefab.ToString().Contains("grenade") == false)
                            {
                                if (hitInfo.WeaponPrefab.ToString().Contains("hunting") || hitInfo.WeaponPrefab.ToString().Contains("bow"))
                                {
                                    if (sleeping)
                                    {
                                        msg = "ArrowSleep";
                                    }
                                    else
                                    {
                                        msg = "Arrow";
                                    }
                                }
                                else
                                {
                                    if (sleeping)
                                    {
                                        msg = dmg + "Sleep";
                                    }
                                    else
                                    {
                                        msg = dmg;
                                    }
                                }
                            }
                            //	Is Attacker an explosive?
                            else if (dmg == "Explosion" || dmg == "Stab" && (bool)Config["Settings", "ShowExplosionDeaths"])
                            {
                                msg = "Explosion";
                            }
                            //	Is Attacker a trap?
                            else if (traps.Contains(attacker) && (bool)Config["Settings", "ShowTrapDeaths"])
                            {
                                msg = "Trap";
                            }
                            //	Is Attacker a Barricade?
                            else if (barricadeDamageTypes.Contains(dmg) && (bool)Config["Settings", "ShowBarricadeDeaths"])
                            {
                                msg = "Barricade";
                            }
                            //	Is Attacker an Animal?
                            else if (dmg == "Bite" && (bool)Config["Settings", "ShowAnimalKills"])
                            {
                                if (sleeping)
                                {
                                    msg = "BiteSleep";
                                }
                                else
                                {
                                    msg = "Bite";
                                }
                            }
                        }
                        //	Victim is an Animal
                        else if (vic.ToString().Contains("animals") && (bool)Config["Settings", "ShowAnimalDeaths"])
                        {
                            victim = FirstUpper(vic.LookupShortPrefabName());
                            msg    = "AnimalDeath";
                            if (dmg == "Explosion")
                            {
                                msg = "Explosion";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ConVar.Server.Log("Oxide/Logs/DeathNotes_ErrorLog.txt", "Failed at getting victim: " + ex.Message.ToString());
                return;
            }

            if (msg != null)
            {
                if (hitInfo.Weapon != null)
                {
                    weapon = hitInfo.Weapon.GetItem().info.displayName.english.ToString();
                }
                if (weapon.Contains("Semi-Automatic Pistol"))
                {
                    weapon = "Semi-Automatic Pistol";
                }

                string formattedDistance = "";

                if (hitInfo.Initiator != null)
                {
                    formattedDistance = GetFormattedDistance(GetDistance(vic, hitInfo.Initiator));
                }

                string formattedVictim   = GetFormattedVictim(victim, false);
                string formattedAttacker = GetFormattedAttacker(attacker, false);
                string formattedAnimal   = GetFormattedAnimal(attacker);
                string formattedBodypart = GetFormattedBodypart(bodypart, false);
                string formattedWeapon   = GetFormattedWeapon(weapon);

                string rawVictim   = GetFormattedVictim(victim, true);
                string rawAttacker = GetFormattedAttacker(attacker, true);
                string rawAnimal   = attacker;
                string rawBodypart = GetFormattedBodypart(bodypart, true);
                string rawWeapon   = weapon;



                string deathmsg = Config["Messages", msg].ToString();
                string rawmsg   = Config["Messages", msg].ToString();

                deathmsg = deathmsg.Replace("{victim}", formattedVictim);
                rawmsg   = rawmsg.Replace("{victim}", rawVictim);


                if (hitInfo.Initiator != null)
                {
                    if (msg == "Bite")
                    {
                        deathmsg = deathmsg.Replace("{attacker}", formattedAnimal);
                    }
                    else
                    {
                        deathmsg = deathmsg.Replace("{attacker}", formattedAttacker);
                    }

                    if (msg == "Bite")
                    {
                        rawmsg = rawmsg.Replace("{attacker}", rawAnimal);
                    }
                    else
                    {
                        rawmsg = rawmsg.Replace("{attacker}", rawAttacker);
                    }
                }

                try
                {
                    if (vic.ToString().Contains("animals") && hitInfo.Initiator == null)
                    {
                        return;
                    }

                    if (vic.ToString().Contains("animals") && hitInfo.Initiator.ToString().Contains("animals"))
                    {
                        return;
                    }

                    if (vic.ToPlayer() == null && hitInfo.Initiator == null)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ConVar.Server.Log("Oxide/Logs/DeathNotes_ErrorLog.txt", "Failed at checking for victim & attacker: " + ex.Message.ToString());
                    return;
                }


                if (formattedBodypart != null)
                {
                    deathmsg = deathmsg.Replace("{bodypart}", formattedBodypart);
                }
                if (hitInfo.Initiator != null)
                {
                    deathmsg = deathmsg.Replace("{distance}", formattedDistance);
                }
                if (hitInfo.Weapon != null)
                {
                    deathmsg = deathmsg.Replace("{weapon}", formattedWeapon);
                }


                if (formattedBodypart != null)
                {
                    rawmsg = rawmsg.Replace("{bodypart}", rawBodypart);
                }
                if (hitInfo.Initiator != null)
                {
                    rawmsg = rawmsg.Replace("{distance}", GetDistance(vic, hitInfo.Initiator));
                }
                if (hitInfo.Weapon != null)
                {
                    rawmsg = rawmsg.Replace("{weapon}", rawWeapon);
                }

                try
                {
                    if (msg != "AnimalDeath")
                    {
                        AddNewToConfig(rawBodypart, weapon);
                    }
                    BroadcastDeath(prefix + " " + GetFormattedMessage(deathmsg), rawmsg, vic);
                }
                catch (Exception ex)
                {
                    ConVar.Server.Log("Oxide/Logs/DeathNotes_ErrorLog.txt", "Failed at sending Message & new2Config: " + ex.Message.ToString());
                    return;
                }
            }
        }
Esempio n. 10
0
        void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo)
        {
            if (entity.lastAttacker != null && entity.lastAttacker is BasePlayer)
            {
                if (entity is BuildingBlock)
                {
                    BasePlayer attacker = ((BasePlayer)entity.lastAttacker);
                    string     weapon   = "Unknown";
                    try
                    {
                        weapon = attacker.GetActiveItem().info.displayName.english;
                    }
                    catch {}
                    try
                    {
                        executeQuery(
                            "INSERT INTO stats_player_destroy_building (player, building, date, tier, weapon) VALUES (@0, @1, @2, @3, @4)",
                            ((BasePlayer)entity.lastAttacker).userID,
                            ((BuildingBlock)entity).blockDefinition.info.name.english, getDateTime(),
                            ((BuildingBlock)entity).currentGrade.gradeBase.name.ToUpper() + " (" +
                            ((BuildingBlock)entity).MaxHealth() + ")", weapon);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Line 194. " + ex.Message);
                    }
                }
                else if (entity is BaseNPC)
                {
                    try
                    {
                        string weapon = "Unknown";
                        try
                        {
                            weapon = ((BasePlayer)entity.lastAttacker).GetActiveItem().info.displayName.english;
                        }
                        catch { }
                        string distance = "-1";
                        if (hitInfo != null)
                        {
                            distance = GetDistance(entity, hitInfo.Initiator) ?? "0";
                        }
                        else
                        {
                            weapon  += "(BLEED TO DEATH)";
                            distance = GetDistance(entity, (BasePlayer)entity.lastAttacker) ?? "0";
                        }

                        executeQuery(
                            "INSERT INTO stats_player_animal_kill (player, animal, date, weapon, distance) VALUES (@0, @1, @2, @3, @4)",
                            ((BasePlayer)entity.lastAttacker).userID,
                            GetFormattedAnimal(entity.LookupShortPrefabName()), getDateTime(), weapon, distance);
                    }
                    catch (Exception ex)
                    {
                        Puts("!!!!WRONG!!!! 210!!!");
                        throw new Exception("Line 210. " + ex.Message);
                    }
                }
                else if (entity is BasePlayer && entity != entity.lastAttacker)
                {
                    try
                    {
                        string weapon = "Unknown";
                        try
                        {
                            weapon = ((BasePlayer)entity.lastAttacker).GetActiveItem().info.displayName.english;
                        }
                        catch { }
                        string distance = "-1";
                        if (hitInfo != null)
                        {
                            distance = GetDistance(entity, hitInfo.Initiator) ?? "0";
                        }
                        else
                        {
                            weapon  += "(BLEED TO DEATH)";
                            distance = GetDistance(entity, (BasePlayer)entity.lastAttacker) ?? "0";
                        }

                        executeQuery(
                            "INSERT INTO stats_player_kill (killer, victim, weapon, date, bodypart, distance) VALUES (@0, @1, @2, @3, @4, @5)",
                            ((BasePlayer)entity.lastAttacker).userID, ((BasePlayer)entity).userID,
                            weapon, getDateTime(),
                            formatBodyPartName(hitInfo), distance);
                    }
                    catch (Exception ex)
                    {
                        Puts("!!!!WRONG!!!! 227!!!");
                        if (entity && entity.lastAttacker == null)
                        {
                            Puts("Entity was attacked by NULL!");
                        }
                        if (hitInfo == null)
                        {
                            Puts("hitInfo is NULL!");
                        }
                        throw new Exception("Line 227. " + ex.StackTrace);
                    }
                }
            }

            try
            {
                if (entity is BasePlayer)
                {
                    string cause = entity.lastDamage.ToString().ToUpper();
                    executeQuery("INSERT INTO stats_player_death (player, cause, date) VALUES (@0, @1, @2)" +
                                 "ON DUPLICATE KEY UPDATE count = count + 1", ((BasePlayer)entity).userID, cause,
                                 getDate());
                }
            }
            catch (Exception ex)
            {
                Puts("!!!!WRONG!!!!245!!!");
                throw new Exception("Line 245" + ex.Message);
            }
        }
Esempio n. 11
0
        void OnEntityDeath(BaseCombatEntity vic, HitInfo hitInfo)
        {
            if(hitInfo == null) return;
            string victimstring = "None";
            string killerstring = "None";
            string weapon = "";

            string msg = null;

            string dmg = FirstUpper(vic.lastDamage.ToString());
            if(dmg == null || dmg == "") dmg = "None";

            string bodypart = GetFormattedBodypart(StringPool.Get(hitInfo.HitBone), true);
            if(bodypart == null || bodypart == "") bodypart = "None";

            string victim = "";
            string attacker = null;
            bool sleeping = false;

            try
            {
                if(hitInfo.Initiator != null)
                {
                    if(hitInfo.Initiator.ToPlayer() != null)
                    {
                        attacker = hitInfo.Initiator.ToPlayer().displayName;
                    }
                    else
                    {
                        attacker = FirstUpper(hitInfo.Initiator.LookupShortPrefabName());
                    }
                }
                else
                {
                    attacker = "None";
                }
            }
            catch (Exception ex)
            {
                ConVar.Server.Log("Oxide/Logs/DeathNotes_ErrorLog.txt", "Failed at getting attacker: " + ex.Message.ToString());
                return;
            }

            try
            {
                if(!vic.ToString().Contains("corpse"))
                {
                    if(vic != null)
                    {
                        if(vic.ToPlayer() != null)
                        {
                            victim = vic.ToPlayer().displayName;

                            sleeping = (bool)vic.ToPlayer().IsSleeping();

                            //	Is it Suicide or Metabolism?
                            if(dmg == "Suicide" && (bool)Config["Settings", "ShowSuicides"]) msg = dmg;
                            if(metabolism.Contains(dmg) && (bool)Config["Settings", "ShowMetabolismDeaths"]) msg = dmg;

                            //	Is Attacker a Player?
                            if(hitInfo.Initiator != null && hitInfo.Initiator.ToPlayer() != null && playerDamageTypes.Contains(dmg) && hitInfo.WeaponPrefab.ToString().Contains("grenade") == false)
                            {
                                if(hitInfo.WeaponPrefab.ToString().Contains("hunting") || hitInfo.WeaponPrefab.ToString().Contains("bow"))
                                {
                                    if(sleeping) msg = "ArrowSleep";
                                    else msg = "Arrow";
                                }
                                else
                                {
                                    if(sleeping) msg = dmg + "Sleep";
                                    else msg = dmg;
                                }
                            }
                            //	Is Attacker an explosive?
                            else if(dmg == "Explosion" || dmg == "Stab" && (bool)Config["Settings", "ShowExplosionDeaths"])
                            {
                                msg = "Explosion";
                            }
                            //	Is Attacker a trap?
                            else if(traps.Contains(attacker) && (bool)Config["Settings", "ShowTrapDeaths"])
                            {
                                msg = "Trap";
                            }
                            //	Is Attacker a Barricade?
                            else if(barricadeDamageTypes.Contains(dmg) && (bool)Config["Settings", "ShowBarricadeDeaths"])
                            {
                                msg = "Barricade";
                            }
                            //	Is Attacker an Animal?
                            else if(dmg == "Bite" && (bool)Config["Settings", "ShowAnimalKills"])
                            {
                                if(sleeping) msg = "BiteSleep";
                                else msg = "Bite";
                            }
                        }
                        //	Victim is an Animal
                        else if(vic.ToString().Contains("animals") && (bool)Config["Settings", "ShowAnimalDeaths"])
                        {
                            victim = FirstUpper(vic.LookupShortPrefabName());
                            msg = "AnimalDeath";
                            if(dmg == "Explosion") msg = "Explosion";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ConVar.Server.Log("Oxide/Logs/DeathNotes_ErrorLog.txt", "Failed at getting victim: " + ex.Message.ToString());
                return;
            }

            if(msg != null)
            {
                if(hitInfo.Weapon != null) weapon = hitInfo.Weapon.GetItem().info.displayName.english.ToString();
                if(weapon.Contains("Semi-Automatic Pistol")) weapon = "Semi-Automatic Pistol";

                string formattedDistance = "";

                if(hitInfo.Initiator != null)
                formattedDistance = GetFormattedDistance(GetDistance(vic, hitInfo.Initiator));

                string formattedVictim = GetFormattedVictim(victim, false);
                string formattedAttacker = GetFormattedAttacker(attacker, false);
                string formattedAnimal = GetFormattedAnimal(attacker);
                string formattedBodypart = GetFormattedBodypart(bodypart, false);
                string formattedWeapon = GetFormattedWeapon(weapon);

                string rawVictim = GetFormattedVictim(victim, true);
                string rawAttacker = GetFormattedAttacker(attacker, true);
                string rawAnimal = attacker;
                string rawBodypart = GetFormattedBodypart(bodypart, true);
                string rawWeapon = weapon;

                string deathmsg = Config["Messages", msg].ToString();
                string rawmsg = Config["Messages", msg].ToString();

                deathmsg = deathmsg.Replace("{victim}", formattedVictim);
                rawmsg = rawmsg.Replace("{victim}", rawVictim);

                if(hitInfo.Initiator != null)
                {
                    if(hitInfo.Initiator.ToPlayer() == null) deathmsg = deathmsg.Replace("{attacker}", formattedAnimal);
                    else deathmsg = deathmsg.Replace("{attacker}", formattedAttacker);

                    if(hitInfo.Initiator.ToPlayer() == null) rawmsg = rawmsg.Replace("{attacker}", rawAnimal);
                    else rawmsg = rawmsg.Replace("{attacker}", rawAttacker);
                }

                try
                {
                    if (vic.ToString().Contains("animals") && hitInfo.Initiator == null)
                    {
                        return;
                    }

                    if (vic.ToString().Contains("animals") && hitInfo.Initiator.ToString().Contains("animals"))
                    {
                        return;
                    }

                    if(vic.ToPlayer() == null && hitInfo.Initiator == null)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ConVar.Server.Log("Oxide/Logs/DeathNotes_ErrorLog.txt", "Failed at checking for victim & attacker: " + ex.Message.ToString());
                    return;
                }

                if(formattedBodypart != null) deathmsg = deathmsg.Replace("{bodypart}", formattedBodypart);
                if(hitInfo.Initiator != null) deathmsg = deathmsg.Replace("{distance}", formattedDistance);
                if(hitInfo.Weapon != null) deathmsg = deathmsg.Replace("{weapon}", formattedWeapon);

                if(formattedBodypart != null) rawmsg = rawmsg.Replace("{bodypart}", rawBodypart);
                if(hitInfo.Initiator != null) rawmsg = rawmsg.Replace("{distance}", GetDistance(vic, hitInfo.Initiator));
                if(hitInfo.Weapon != null) rawmsg = rawmsg.Replace("{weapon}", rawWeapon);

                try
                {
                    AddNewToConfig(rawBodypart, weapon);

                    BroadcastDeath(prefix + " " + GetFormattedMessage(deathmsg), rawmsg, vic);
                }
                catch (Exception ex)
                {
                    ConVar.Server.Log("Oxide/Logs/DeathNotes_ErrorLog.txt", "Failed at sending Message & new2Config: " + ex.Message.ToString());
                    return;
                }
            }
        }