Unable to get entity from HitInfo in OnMeleeAttackSolved
object OnMeleeAttack(BasePlayer player, HitInfo info)
{
    if (info.Weapon.ShortPrefabName.Contains("hammer.salvaged"))
    {
        BasePlayer target = info.HitEntity.GetComponent<BasePlayer>();
        if (target != null)
        {
            server.Command("vip");
        }
    }
    return null;
}

Hello,

Your problem is most likely in trying to use OnMeleeAttack Hook,

I believe this hook gets fired on the "cast" of a melee attack and therefore there will never be a hit entity because of the timing,

Player uses melee attack -> OnMeleeAttack Fires (No player has been hit yet) -> Player is hit -> OnEntityTakeDamage Fires

So in suggestion I would use OnEntityTakeDamage

Some helpful lines to get you started :)

void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo)
{
    var attacker = hitInfo?.Initiator as BasePlayer;
    var hitPlayer= entity.ToPlayer();
    if (hitPlayer!= null && attacker != null){
        var weapon = hitInfo.Weapon?.GetItem();
        if (weapon != null)
        {
        }
    }
}
Gj, poison! It's your first post! Welcome!

Where've you been all this time? We need you!
👍😏😏😉✌
Locked automatically