Asokanta Posted January 30, 2023 Posted January 30, 2023 Hey, I'm trying to add a custom event but getting "Object reference not set to an instance of an object" error instead. Exception details: Spoiler System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object. at void RageInternal.Events+EventPusher.PushOne(object obj) at void RageInternal.Events+EventPusher.Push(params object[] args) at void RageInternal.Events.CallLocal(string eventName, params object[] args) at void RAGE.Events.CallLocal(string eventName, params object[] args) at void ExampleResource.Main.TriggerHelloWorld(Player sender) in TestScript.cs:line 86 --- End of inner exception stack trace --- at object RuntimeMethodHandle.InvokeMethod(object target, object[] arguments, Signature sig, bool constructor, bool wrapExceptions) at object System.Reflection.RuntimeMethodInfo.Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) at bool GTANetworkInternals.CommandParser.Parse(Player sender, string cmdRaw, string ourcmd, string[] args) [ServerEvent(Event.ResourceStart)] public void OnResourceStart() { Events.Add("sendhelloworld", SendHelloWorld); } private void SendHelloWorld(object[] args) { NAPI.Util.ConsoleOutput("Hello world."); } [Command("hey")] public void TriggerHelloWorld(Player sender) { Events.CallLocal("sendhelloworld", sender); }
Xabi Posted January 31, 2023 Posted January 31, 2023 Why would you call a serverside event like that when you can just call SendHelloWorld(sender)?
Asokanta Posted January 31, 2023 Author Posted January 31, 2023 (edited) public void TriggerHelloWorld(Player sender) 8 hours ago, hash_ said: which is line 86? I simplified that way so people can focus on error rather than code. I'm trying to understand why I'm getting that error. 5 hours ago, Xabi said: Why would you call a serverside event like that when you can just call SendHelloWorld(sender)? Edited January 31, 2023 by Asokanta remove unnecessary lines
Xabi Posted January 31, 2023 Posted January 31, 2023 Also RAGE.Events it's clientside API, can't call it serverside.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now