Disabling a hook

I have a code, I need the OnEntityKill hook not to fire by default, but only on call

        private void OnEntityKill(BaseNetworkable entity, BasePlayer player)
        {

            var baseEnt = entity as BaseEntity;
            if (baseEnt == null) return;
            if (oreCashe.Contains(baseEnt))
            {
                oreCashe.Remove(baseEnt);
                 IQChat.CallHook("ReplySystem", player, "Твоя руда была разбита");
                Puts("Руда");
                
            }
        }

 

I need OnMeleeAttack to be passed to the BasePlayer hook and triggered by the condition -

 

    object OnMeleeAttack (BasePlayer player, HitInfo info)
    {
        BaseEntity ent = info?.HitEntity;
        
         if(ent.IsDestroyed)
         {
            OnEntityKill(ent,player);
         
         }

Calling a hook manually isn't going to do anything other than what you have specified in that hook, so it wouldn't really be a hook anymore, but rather just a normal method.

3rzybvWsdIreykA.png Wulf

Calling a hook manually isn't going to do anything other than what you have specified in that hook, so it wouldn't really be a hook anymore, but rather just a normal method.

I no longer know how to get out to find a way to define BasePlayer in the OnEntityKill hook, I try all the methods

IQdO1DTIxIypCOu.png Wulf

Calling a hook manually isn't going to do anything other than what you have specified in that hook, so it wouldn't really be a hook anymore, but rather just a normal method.

       private void OnEntityKill(BaseNetworkable entity)
        {

            BaseEntity baseEnt = entity.GetComponent<BaseEntity>();
             
            if (oreCashe.Contains(baseEnt))
            {
                oreCashe.Remove(baseEnt);
                BasePlayer player = entity as BasePlayer;
                if (player == null)
                return;
                 IQChat.CallHook("ReplySystem", player, "Твоя руда была разбита");
                Puts("Руда");
                
            }
        }

Why doesn't it work?

What exactly doesn't work about it? For one, that hook isn't for players. OnPlayerDeath exists for players.

rxRwAnVOEtejI2f.png Wulf

What exactly doesn't work about it? For one, that hook isn't for players. OnPlayerDeath exists for players.

I need to find the player that is killing the Entity

         BasePlayer player = entity as BasePlayer;
         if (player == null)
         return;

Code returns null

GHY2Vrex4uoZTmz.png Wulf

This hook cannot track the Entity that the player breaks, the condition does not work

      void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
               BaseEntity ent = info?.HitEntity;
               BasePlayer player = (BasePlayer)entity.ToPlayer();
               Puts("Работает до условия");
               if(oreCashe.Contains(ent))
               {
                oreCashe.Remove(ent);
                IQChat.CallHook("ReplySystem", player, "Твоя руда была разбита");
                Puts("условие");
               }
        }

The HitInfo.InitiatorPlayer would be the player, the entity would be what is being killed.

               BasePlayer player = info.InitiatorPlayer;
               BaseEntity ent = player.,,,; ????​

How to define kill?

 

HjExypLBKEVgToY.png Wulf

The HitInfo.InitiatorPlayer would be the player, the entity would be what is being killed.

The first argument is the entity that was killed.

J6fOqpiFKBqFJp7.png Wulf

The first argument is the entity that was killed.

And the ore definitely works in this hook?
maybe this hook works on animals and players?

      void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
              
               BasePlayer player = info.InitiatorPlayer;
               BaseEntity ent =  entity.lastAttacker ?? info.InitiatorPlayer;
               Puts("Работает до условия");
               if(oreCashe.Contains(ent))
               {
                oreCashe.Remove(ent);
                IQChat.CallHook("ReplySystem", player, "Твоя руда была разбита");
                Puts("условие");
               }
        }

I don't think ore is a traditional entity, so you'd likely need to look at the resource hooks for that.