Hey i am getting an error in this code with calling hook on "OnEntitySpawned"
using Oxide.Ext.Discord;
using Oxide.Ext.Discord.Attributes;
using Oxide.Ext.Discord.DiscordObjects;
using System;
using static Oxide.Ext.Discord.DiscordObjects.Embed;
namespace Oxide.Plugins
{
[Info("Test", "Nealo", 1.0)]
[Description("Nealos test plugin")]
public class Test : RustPlugin
{
[DiscordClient] DiscordClient _client;
private void Loaded() { Discord.CreateClient(this, "token"); }
private void Unload() { Discord.CloseClient(_client); }
private void OnEntitySpawned(BaseNetworkable entity)
{
if (entity is CargoPlane || entity is BaseHelicopter || entity is CargoShip || entity is CH47Helicopter)
{
Channel channel = null;
_client.DiscordServer.channels.FindAll(findChannel =>
{
if (findChannel.id == "not for you ") channel = findChannel;
return true;
});
Author author = new Author
{
name = entity.ShortPrefabName + "Inbound",
icon_url = GetUrl(entity)
};
Embed embed = new Embed
{
author = author,
description = GetText(entity),
color = 3447003,
};
channel.CreateMessage(_client, embed);
}
}
private string GetUrl(object entity)
{
if (entity is CargoPlane) return "https://rustlabs.com/img/items180/supply.signal.png";
if (entity is BaseHelicopter) return "https://rustlabs.com/img/screenshots/helicopter.png";
if (entity is CargoShip) return "https://www.corrosionhour.com/wp-content/uploads/2018/10/Screenshot-518.png";
if (entity is CH47Helicopter) return "https://rustlabs.com/img/screenshots/codelockedhackablecrate.png";
return null;
}
private string GetText(object entity)
{
if (entity is CargoPlane) return "Cargo Plane Spawned";
if (entity is BaseHelicopter) return "Attack Heli Inbound";
if (entity is CargoShip) return "Cargo Ship Spawned";
if (entity is CH47Helicopter) return "Chinhook Inbound";
return null;
}
}
}
| Failed to call hook 'OnEntitySpawned' on plugin 'Test v1.0.0' (NullReferenceException: Object reference not set to an instance of an object)
at Oxide.Plugins.Test.OnEntitySpawned (BaseNetworkable entity) [0x000b7] in <a7a86b0f264e44db9db59b2888c1ecde>:0
at Oxide.Plugins.Test.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x0007e] in <a7a86b0f264e44db9db59b2888c1ecde>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0