예제 #1
0
        void OnLootEntityEnd(BasePlayer player, BaseCombatEntity entity)
        {
            string theitem = entity.GetType().ToString();

            if (theitem == "LootContainer")
            {
                LootContainer saken;
                saken = (LootContainer)entity;
                if (saken.destroyOnEmpty)
                {
                    bool doearnmoney = true;
                    for (int i = 0; i < saken.inventorySlots; i++)
                    {
                        try{
                            if (saken.inventory.GetSlot(i).ToString() != "")
                            {
                                doearnmoney = false;
                            }
                        }
                        catch (System.Exception e) {
                        }
                    }
                    if (doearnmoney)
                    {
                        Puts("Player earned coins from looting a crate which got ruined!");
                        addcoin(player.userID.ToString(), lootcratemoney);
                    }
                    else
                    {
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// ON STRUCTURE DEATH
        /// ON PLAYER DEATH
        /// ON TURRET DEATH
        /// ON HELICOPTER DEATH
        /// ON CUPBOARD DEATH
        /// ON SLEEPING BAG DEATH
        /// ON NPC DEATH
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="info"></param>
        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            string hook;

            if (TryGetHook(entity.GetType(), killableTypes, out hook))
            {
                Interface.CallHook(hook, entity, info);
            }
        }
예제 #3
0
 void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
 {
     if (entity.GetType() == typeof(BasePlayer))
     {
         if (weaponData.ContainsKey((BasePlayer)entity))
         {
             weaponData[(BasePlayer)entity].Destroy();
         }
     }
 } //Maybe add items to corpse instead? Could lag even worse if lots of bodies
예제 #4
0
        private bool IsOfType(BaseCombatEntity entity, out string matchingType)
        {
            matchingType = null;

            foreach (var pair in config.multipliers)
            {
                if (pair.Key == entity.GetType()?.Name)
                {
                    matchingType = pair.Key;
                    return(true);
                }
            }

            return(false);
        }
예제 #5
0
        /// <summary>
        /// ON ANIMAL ATTACK
        /// ON HELICOPTER ATTACK
        /// ON STRUCTURE DAMAGE
        /// ON PLAYER DAMAGE
        /// ON TURRET DAMAGE
        /// ON HELICOPTER DAMAGE
        /// ON CUPBOARD DAMAGE
        /// ON CORPSE DAMAGE
        /// ON SLEEPING BAG DAMAGE
        /// ON NPC DAMAGE
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="info"></param>
        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
            string hook;

            if (info.Initiator != null)
            {
                if (TryGetHook(info.Initiator.GetType(), attackTypes, out hook))
                {
                    Interface.CallHook(hook, entity, info.Initiator, info);
                }
            }

            if (TryGetHook(entity.GetType(), damagableTypes, out hook))
            {
                Interface.CallHook(hook, entity, info);
            }
        }
예제 #6
0
        private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo)
        {
            if (!enabled)
            {
                return(null);
            }

            if (entity == null || hitinfo == null)
            {
                return(null);
            }

            float  damageAmount = 0f;
            string entity_name  = entity.LookupPrefab().name;
            ulong  owner        = entity.OwnerID;

            switch (hitinfo.damageTypes.GetMajorityDamageType().ToString())
            {
            case "Decay":
                float before = hitinfo.damageTypes.Get(Rust.DamageType.Decay);
                damageAmount = before * configData.Global.DecayMultiplier;

                if (entity is BuildingBlock)
                {
                    if ((bool)JPipes?.Call("IsPipe", entity) && (bool)JPipes?.Call("IsNoDecayEnabled"))
                    {
                        DoLog("Found a JPipe with nodecay enabled");
                        hitinfo.damageTypes.Scale(Rust.DamageType.Decay, 0f);
                        return(null);
                    }

                    damageAmount = before * configData.Global.DecayMultiplier;
                }

                NextTick(() =>
                {
                    DoLog($"Decay ({entity_name}) before: {before} after: {damageAmount}, item health {entity.health.ToString()}");
                    entity.health -= damageAmount;
                    if (entity.health == 0)
                    {
                        DoLog($"Entity {entity_name} completely decayed - destroying!");
                        if (entity == null)
                        {
                            return;
                        }

                        entity.Kill(BaseNetworkable.DestroyMode.Gib);
                    }
                });
                return(true);    // Cancels this hook (for decay only).  Decay handled on NextTick.

            default:
                if (configData.Global.EnablePVE)
                {
                    try
                    {
                        object CanTakeDamage = Interface.CallHook("CanEntityTakeDamage", new object[] { entity, hitinfo });
                        if (CanTakeDamage != null && CanTakeDamage is bool && (bool)CanTakeDamage)
                        {
                            return(null);
                        }
                    }
                    catch { }

                    string source = hitinfo.Initiator?.GetType().Name;
                    string target = entity?.GetType().Name;

                    if (source == "BasePlayer" && target == "BasePlayer")
                    {
                        return(true);    // Block player to player damage
                    }

                    if (source == "BasePlayer" && (target == "BuildingBlock" || target == "Door" || target == "wall.window"))
                    {
                        BasePlayer pl = hitinfo.Initiator as BasePlayer;
                        if (pl != null && owner == pl.userID)
                        {
                            return(null);
                        }
                        // Block damage to non-owned building
                        return(true);
                    }
                }
                break;
            }
            return(null);
        }