Closed CoolSlimbo closed 9 months ago
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:
https://github.com/steven4547466/LC-API/assets/23726534/964d4839-0b3e-47de-a659-32686cd72f60
Marking as stale. Reopen if this is still an issue.
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)Further testing will be done within 24 hours, to see if this is command specific, or not.