Possible Melee-only Option?Solved

Hello!

Would it be possible to add an option to only trigger barrels when they are attacked by a melee weapon? Currently if you want to use the option of having barrels go straight to inventory, players can shoot the barrels from any distance, causing them to basically be able to farm the road from their base.

An easy fix would be to make it so that bullets/thrown items do not trigger the auto-pickup, and make it so only melee hits would trigger it.

This would be an amazing addition, and hope it can be added!

To anyone wanting to use it the way that I am, this is what I did to change it. Arainrr could possibly make this a config option if he wants to. Basically, you change the plugin file, and anywhere "OnPlayerAttack" is being called, use "OnMeleeAttack" instead. An example is below.

private void OnPlayerAttack(BasePlayer attacker, HitInfo info)
        {
            if (attacker == null || !attacker.userID.IsSteamId()) return;
            var barrel = info?.HitEntity as LootContainer;
            if (barrel == null || barrel.net == null) return;
            if (!IsBarrel(barrel.ShortPrefabName)) return;
            if (permission.UserHasPermission(attacker.UserIDString, PERMISSION_USE))
            {
                if (TryPickupLootContainer(barrel, attacker, info))
                {
                }
            }
        }

You would change the above to :

private void OnMeleeAttack(BasePlayer attacker, HitInfo info)
        {
            if (attacker == null || !attacker.userID.IsSteamId()) return;
            var barrel = info?.HitEntity as LootContainer;
            if (barrel == null || barrel.net == null) return;
            if (!IsBarrel(barrel.ShortPrefabName)) return;
            if (permission.UserHasPermission(attacker.UserIDString, PERMISSION_USE))
            {
                if (TryPickupLootContainer(barrel, attacker, info))
                {
                }
            }
        }

Just make sure you change all instances of OnPlayerAttack to OnMeleeAttack.

Updated. 

    "LootContainer": {
      "Enabled": true,
      "Check Radius": 5// You can set it to 5
    }​

I need to take care of everyone. Some people are like you. Some people want to use ranged weapons. So I don't use OnMeleeAttack.

DjuJWQX1WEaVdyz.jpg Arainrr

Updated. 

    "LootContainer": {
      "Enabled": true,
      "Check Radius": 5// You can set it to 5
    }​

I need to take care of everyone. Some people are like you. Some people want to use ranged weapons. So I don't use OnMeleeAttack.

Thanks Arainrr! 

Locked automatically