Can't find base playerSolved

Hi I need to define a player in OnEntityKill
But first I find BaseEntity and everything stops working

        private void OnEntityKill(BaseNetworkable entity)
        {

            var baseEnt = entity as BaseEntity;        //Here I define BaseEntity
            if (baseEnt == null) return;
            BasePlayer player = baseEnt as BasePlayer;  // Here I want to define BasePlayer to use ShowUI()
            if (oreCashe.Contains(baseEnt))
            {
                oreCashe.Remove(baseEnt);
                ShowUI(player, "Ваша руда была разбита");

            }
        }

There are hooks specifically for BasePlayer deaths such as OnPlayerDeath.

MCWaVwjyqnm0N5b.png Wulf

There are hooks specifically for BasePlayer deaths such as OnPlayerDeath.

I need an Entity hook because the player mines the ore that he himself will supply
It is stored in oreCashe from there when mining ore, I delete it, because. the player puts the ore and it is added there

bAwDocn4t9LJEWP.jfif ParkSM

I need an Entity hook because the player mines the ore that he himself will supply
It is stored in oreCashe from there when mining ore, I delete it, because. the player puts the ore and it is added there

If you are tracking when a player dies (you are based on your above code), you can use the other hook. I'm not sure what tracking ore has to do with players being killed though, but I doubt they hook is what you want if you are trying to track ore  removals.
x8OGr5dnYIRNgM0.png Wulf
If you are tracking when a player dies (you are based on your above code), you can use the other hook. I'm not sure what tracking ore has to do with players being killed though, but I doubt they hook is what you want if you are trying to track ore  removals.

I don't track player kills.
I keep track of when a player broke his own ore (which he himself placed)

   if (oreCashe.Contains(baseEnt))
    {
        oreCashe.Remove(baseEnt);
        ShowUI(player, "Ваша руда была разбита");

    }


Here the player breaks the ore that he himself placed
This ore was cached on the server

 

I need to get Entity and BasePlayer

You can try to see if the entity you destroyed has an owner, otherwise that hook likely would not work for that. The entity in that hook is the entity being killed,  not what killed it.

wj2AJfSAMmeGDlr.png Wulf

You can try to see if the entity you destroyed has an owner, otherwise that hook likely would not work for that. The entity in that hook is the entity being killed,  not what killed it.

oreCashe - Ore Storage
baseEnt - a variable that passes the ore

I need to check what kind of ore the player kills, if it is in the server cache then the condition is triggered, if not, then by.

you should use hooks like OnEntityDeath which provide a hitinfo from where you can retrieve the initiator, whereas OnEntityKill provides no such info

Thanks!!

Locked automatically