1. Hi,

    i search a solution to get a playername when i use

    Code:
    void OnEntityKill(BaseNetworkable entity)
    found this at forum, but it dont work

    Code:
    var player = entity.net.connection.player as BasePlayer;
    thanks for helping :)
     
  2. Code:
    void OnEntityKill(BaseNetworkable entity) {
        if (!(entity is BasePlayer))
            return;
        BasePlayer player = entity as BasePlayer;
        string name = player.DisplayName;
        ulong ID = player.UserID;
        // e.t.c.
    }
     
  3. thanks, but it dont work :(

    my complete code:

    Code:
    void OnEntityKill(BaseNetworkable entity)
    {
        BaseEntity sEntity = entity.GetComponent<BaseEntity>(); // get objectname
        Vector3 sPosition = entity.transform.position;  // get object position
       
        if (sEntity.ShortPrefabName == "cupboard.tool.deployed")
        {
            if (!(entity is BasePlayer))
                return;
            BasePlayer player = entity as BasePlayer;
            string name = player.DisplayName;
            Puts(name.DisplayName + " destroyed a cupboard at " + sPosition.ToString());
        }
    }
    
    error:
    Code:
    error CS1061: Type `string' does not contain a definition for `DisplayName' and no extension method `DisplayName' of type `string' could be found. Are you missing an assembly reference?
     
  4. Here's your problem.

    string name = player.DisplayName;
    Puts(name.DisplayName + " destroyed a cupboard at " + sPosition.ToString());

    You're assigning name = player.DisplayName and then in your Puts you're calling name.DisplayName, which is like trying to call player.DisplayName.DisplayName
     
  5. thanks, that failed hard. im blind :D

    fixed it and get this error message:

    Code:
    error CS1061: Type `BasePlayer' does not contain a definition for `DisplayName' and no extension method `DisplayName' of type `BasePlayer' could be found. Are you missing an assembly reference?
     
  6. Maybe displayName, i dont remember about cases in this situation. Do you use IDE? Or just notepad? If not - download Rider or Visual Studio
     
  7. yes. it is player.displayName
     
  8. player.displayName is correct, but it dont work in combination with "BaseNetworkable entity"

    now i have found an other solution for my problem and thanks for ur help :)

    @HOUGAN_Y: i use only notepad :)
     
  9. Wulf

    Wulf Community Admin

    BaseNetworkable is what a BasePlayer is based on in the end, so it would work, you'd just need to cast to BasePlayer and check if that is null or not.