steven4547466/LC-API

The `Player` variable (From Features), is null, when used within a command.

Closed this issue · 4 comments

As the title states, the Player variable returns a NullReferenceException when used within a command.
I do not know if this problem persists through accessing it via other means, however, at any point in time, it has shown to be null when executing a chat command. (Currently tested in orbit, and on ground)

[Error  :Lethal Company API] Error handling command: lc
[Error  :Lethal Company API] System.NullReferenceException: Object reference not set to an instance of an object
  at LethallyCheated.Plugin.LethallyCheated (System.String[] args) [0x00006] in <3ba071e22617494dbacf7b69db2df2fb>:0 
  at LC_API.ClientAPI.CommandHandler+SubmitChatPatch.HandleMessage (HUDManager manager) [0x00066] in <2cbba39d1e4241d2961a30e8f27ca788>:0 

Further testing will be done within 24 hours, to see if this is command specific, or not.

Player is a class, it can't be "null." static variables in it might be, can you show me your code?

Sorry. Should’ve clarified.

Code:

static void command(string args[]) {
    Player.LocalPlayer.Hurt(5);
    // Player.HostPlayer.Hurt(5);
}

This is the code with the reference, and than the only thing I else that is relevant is the use of CommandHandler.RegisterCommand to register command.

What I can also mention (that should’ve been done so in the initial comment of the issue), is that the start method of the class is not run through my testing, which is the only time either HostPlayer or LocalPlayer get set from what I can see in the code.

If you believe you might know why this is happening, I am free to edit a fork and send in a PR to fix it to save time on your end.

Interesting, here's my code:

ClientAPI.CommandHandler.RegisterCommand("test", (string[] args) =>
{
    GameInterfaceAPI.Features.Player.LocalPlayer.Hurt(10);
});

And here's a video showing it in action:

8mb.video-bp6-HaeEksoH.mp4

Marking as stale. Reopen if this is still an issue.