Running command when player is attacked with item?
I am currently developing a Rust server and have got all my necessary plugins ready! I am just missing one thing, after constantly trying to edit plugins and create my own I have not been able to figure out how to enter a console command when a player is attacked by a salvaged hammer.

For context, I am trying to make it so that the target player is jailed for 300 seconds using the jail plugin via console after being attacked. Appreciate anyone who could help, I am very new to Rust plugins.
I've been struggling to find a way to do this.
object OnMeleeAttack(BasePlayer player, HitInfo info)
{
    if (CHECK INFO FOR ITEM HERE) // Unsure the exact method, VS IntelliSense can help here
    {
        server.Command("run command"); // If CovalencePlugin, else:
        covalence.Server.Command("run command"); // If RustPlugin
    }
}
I edited the code you sent me Wulf!

namespace Oxide.Plugins
{
[Info("JailStick", "TomQ", "1.0")]
[Description("Sends victim to jail.")]
public class JailStick : RustPlugin

object OnMeleeAttack(BasePlayer player, HitInfo info)
{
if (tool.GetItem()?.info.shortname.Contains("hammer.salvaged") == true) // Unsure the exact method, VS IntelliSense can help here
{
BasePlayer target = info.HitEntity.GetComponent<BasePlayer>();
covalence.Server.Command("jail send " + target.userID + " 300"); // If RustPlugin
}
}

However this is not working as my console outputs "Error while compiling: JailStick.cs(16,5): error CS1514: Unexpected symbol `}', expecting `.' or `{'".

I may have gone wrong in my code editing as I am very new to this.
namespace Oxide.Plugins
{
    [Info("Jail Stick", "TomQ", "1.0")]
    [Description("Sends player to jail when hit with hammer")]
    class JailStick : CovalencePlugin
    {
        object OnMeleeAttack(BasePlayer player, HitInfo info)
        {
            if (info.shortname.Contains("hammer.salvaged"))
            {
                BasePlayer target = info.HitEntity.GetComponent<BasePlayer>();
                if (target != null)
                {
                    server.Command($"jail send {target.userID} 300");
                }
            }
        }
    }
}
Thanks a ton!

For some reason this will not execute a command when I attack a player with a salvaged hammer. However if I remove the line it will execute the command with every melee weapon. I only want it to work for the salvaged hammer.

        void OnMeleeAttack(BasePlayer player, HitInfo info)
        {
            if (info.Weapon.ShortPrefabName.Contains("hammer.salvaged"))
You should print info.Weapon.ShortPrefabName to see if the hammer is registering here and if you have the name correct.
I think it's "hammer_salvaged.entity", but Puts(...) proves it.
Wow, thanks a ton. Yeah, it was just hammer_salvaged.entity instead of hammer.salvaged!
Cool. :)
Good way to think - If your condition isn't being met when you think it should, print out the value that's being assessed. ;)

No work, error

Error while compiling: JailStick.cs(14,22): error CS1061: Type `HitInfo' does not contain a definition for `shortname' and no extension method `shortname' of type `HitInfo' could be found. Are you missing an assembly reference?

GG you revived a thread that was over a year old! Might want to go find the dev of that addon or post in the addons help section.

You have rediscovered the same problem that was solved in this thread, try reading the rest of it. 😄

upps my body asked me to sleep and I couldn't read that, sorry for my blindness.