Jump to content

When the base is removed after the event ends, conflicts with other plugins occur.

Closed 2.8.4

dosiin
dosiin

Posted

It conflicts with other plugins that use the OnEntityDeath hook, causing a null error. player, info
I tried debugging to see if null occurs in entity.name, but
It was of no use and a null error occurred in a situation where the base was destroyed, causing serious lag on the server.
Is there any solution?
I would like to know if there is a point I am noticing, a debug method, or the cause.
Note: An error occurs in Bearrels created by redBDGR.
Create a debug plugin
I checked, but an error still occurs in OnEntityDeath.

nivex

Posted

what is the error

  • Like 1
dosiin

Posted

Failed to call hook 'OnEntityDeath' on plugin 'dosiin v2.2.3' (NullReferenceException: Object reference not set to an instance of an object)

at Oxide.Plugins.dosiin.OnEntityDeath (BaseCombatEntity entity, HitInfo info) [0x0002c] in <a7bf8e4281df4231b379117211eb9622>:0

at Oxide.Plugins.dosiin.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x0007e] in <a7bf8e4281df4231b379117211eb9622>:0

at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <87ce9ac9776a48658bc55eae6debe38b>:0

at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <18d4f19bbc844191b11ed9e69284d09b>:0

at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <18d4f19bbc844191b11ed9e69284d09b>:0

nivex

Posted

you need to null check your code then

Quote

if (!entity || info == null) return;

 

  • Like 1
dosiin

Posted

if(player != null || entity != null || info != null)
    {
    if(entity.name != null)
    {

I tried it, but the error keeps occurring. Is there anything else I should check?

nivex

Posted

that's close, but you need to use what I suggested

        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            if (!entity || info == null)
                return;
            if (!entity.name.Contains("barrel"))
                return;
            if (UnityEngine.Random.Range(0f, 1f) <= ConfigFile.chanceOfBear)
            {
                SpawnBear(entity.transform.position);
                BasePlayer player = info.InitiatorPlayer;
                if (player != null)
                    PrintToChat(player, msg("Bearrel", player.UserIDString));
            }
        }

 

  • Like 1
dosiin

Posted

Thank you. I think it has now been resolved in that plugin.
The problem is that I have written a plugin for the purpose of linking to the web and generating statistics.
I get the same error.
Please one more time.

void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
    BasePlayer player = info.InitiatorPlayer;
    if (!entity || info == null)
    return;
    if(entity.name.Contains("barrel"))
    {
    BarryWebRequest2?.Call("BWR2","kostat","barrel");
    }
    else if(entity.name.Contains("scarecrow"))
    {
    BarryWebRequest2?.Call("BWR2","kostat","scarecrow");
    }
    else if(entity.name.Contains("scientist"))
    {
    BarryWebRequest2?.Call("BWR2","kostat","scientist");
    }
    else if(entity.name.Contains("stag"))
    {
    BarryWebRequest2?.Call("BWR2","kostat","stag");
    }
    else if(entity.name.Contains("bear"))
    {
    BarryWebRequest2?.Call("BWR2","kostat","bear");
    }
    else if(entity.name.Contains("boar"))
    {
    BarryWebRequest2?.Call("BWR2","kostat","boar");
    }
    else if(entity.name.Contains("wolf"))
    {
    BarryWebRequest2?.Call("BWR2","kostat","wolf");
    }
    else if(entity.name.Contains("chicken"))
    {
    BarryWebRequest2?.Call("BWR2","kostat","chicken");
    }
    else
    {
    return;
    }
    }

Every time an NPC is captured, the plugin is called and counted, but an error occurs for the same reason.

nivex

Posted (edited)

yes no problem.

check before the cast

if (!entity || info == null)
    return;
BasePlayer player = info.InitiatorPlayer;

you should use entity.ShortPrefabName instead of entity.name too

Edited by nivex
  • Like 1
dosiin

Posted

You are truly amazing.
I don't know English and am very interested in programming, but I was at a loss after referring to various plugins and contacting chatGPT.
It has been resolved.
thank you so much.

The second question was simply a matter of order.

nivex

Posted

no problem enjoy

  • Like 1
nivex

Posted

Changed Status from Pending to Closed

1.6m

Downloads

Total number of downloads.

7.7k

Customers

Total customers served.

116.2k

Files Sold

Total number of files sold.

2.4m

Payments Processed

Total payments processed.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.