Solved RPC Error: playerattack

Discussion in 'Rust Development' started by PsychoTea, Dec 11, 2016.

  1. Hey

    I'm getting this weird error when I use Entity.Kill();
    Here's a short version of what I'm doing:
    Code:
    void OnHammerHit(BasePlayer player, HitInfo info)
    {
        if (info.HitEntity.GetComponent<BuildingBlock> != null)
            if(!info.HitEntity.isDestroyed)
                info.HitEntity.Kill(BaseNetworkable.DestroyMode.None);
    }
    

    For some reason, when I then hit a structure (eg twig wall) with a hammer, I get disconnected from the server with the error "RPC Error: playerattack", and a NullReferenceException in the console.

    Any ideas?

    Edit: I should also mention, despite this not working with my plugin, RemoverTool works fine which afaik is using pretty much the same code.
     
  2. Wulf

    Wulf Community Admin

    I wouldn't assume that HitEntity is always valid, so I'd add a null check for that.
     
  3. I added a null check
    Code:
    if (info.HitEntity != null) info.HitEntity.Kill(...);
    however I'm still having the same error.
    [DOUBLEPOST=1481495153][/DOUBLEPOST]I wonder, is Entity.Kill() the 'proper' way of destroying a structure/buildingblock or is there a better way of doing it?
     
  4. The default destroy mode is none so I removed that, but it doesn't make a difference. Killing the entity next frame seems to work fine.

    Code:
            void OnHammerHit(BasePlayer player, HitInfo info)
            {
                if (info.HitEntity != null)
                    if (!info.HitEntity.isDestroyed)
                    {
                        NextFrame(() =>
                        {
                            info.HitEntity.Kill();
                        });
                    }
            }
     
  5. You sir are a genius! Thanks so much! This worked and fixed my issue.

    Please mark as solved.
     
  6. No problem also you should be able to mark it as solved yourself there is a ctrl + f and search for thread tools and edit the title.