How to change the components of an object?Solved

In the OnExplosiveThrown hook, I'm trying to intercept the moment when the player throws a Survey Charge to replace the Explode method with his own. But I can't do it.
I tried to remove the SurveyCharge component from this object, but the charge just hangs in the air and explodes anyway.
I also tried at this moment to create a new charge and set my component to it via AddComponent, but this also does not work.
I understand that when using "СreateEntity", the server creates an object with all its inherent components, but I don't understand how to change or delete them.

my advise stop living in the 90s and come to the future.. survey charges and quarry's.. don't live in the past, think of the future or at least embrace the game changes.

I don't think there is a hook for that method at the moment so for now you could use harmony to override the method and use your own code.

Harmony patching docs

wXLxOgFUEnSjh1r.png 0x89A

I don't think there is a hook for that method at the moment so for now you could use harmony to override the method and use your own code.

Harmony patching docs

My hosting does not allow third party extensions.
By the error "UnauthorizedAccessException: System access is restricted, you are not allowed to use Harmony.HarmonyInstance" I realized that using Harmony in a regular plugin is impossible.

You would need to disable the oxide sandbox and make sure you put //Reference: 0Harmony at the top.

Guide

I don't have access to these directories on the hosting.

Hmmm. Then I expect it also won't be possible to use your own version of oxide so I assume you'll just have to request a new hook be added to oxide.

 

You could always change the explode time higher do what you want to do then manualy explode or kill the ent.

I have disabled the oxide sandbox and I found an example of a plugin with Harmony and made a test one for myself.

// Reference: 0Harmony
using System;
using Harmony;

namespace Oxide.Plugins
{
    [Info("TTest", "Timon1221", "1.0.0")]
    public class TTest : RustPlugin
    {
        HarmonyInstance _harmony;
        void Init()
        {
            _harmony = HarmonyInstance.Create(Name + "PATCH");
            Type patchType = AccessTools.Inner(typeof(TTest), "MySurvey");
            new PatchProcessor(_harmony, patchType, HarmonyMethod.Merge(patchType.GetHarmonyMethods())).Patch();
            
            Puts($"Applied Patch: {patchType.Name}");
        }

        void Unload() => _harmony.UnpatchAll(Name + "PATCH");

        [HarmonyPatch(typeof(SurveyCharge), nameof(SurveyCharge.Explode), MethodType.Normal)]
        public static class MySurvey
        {
            [HarmonyPrefix]
            public static void Prefix()
            {
                Console.WriteLine("Test");
            }
        }
    }
}​

But that plugin works fine and I have this error:



As I understand it, the error is related to the SurveyCharge class or its Explode method, but I don't understand how yet.

Sorry for the late reply, basically in your HarmonyPatch attribute you will need to specify an empty type array.

[HarmonyPatch(typeof(SurveyCharge), nameof(SurveyCharge.Explode), new Type[] { })]
wXLxOgFUEnSjh1r.png 0x89A

Sorry for the late reply, basically in your HarmonyPatch attribute you will need to specify an empty type array.

[HarmonyPatch(typeof(SurveyCharge), nameof(SurveyCharge.Explode), new Type[] { })]

What Razor said is easier for me to implement, but still thank you so much for the answer.

Locked automatically