Jump to content
RAGE Multiplayer Community

NAPI.LocalEvent.TriggerEvent seems throwing System.NullReferenceException


taywon
 Share

Recommended Posts

Hey !

I'm trying to communicate between serverside c# and serverside js, with this kind of code:

//serverside C#
Debug.Assert(NAPI.LocalEvent != null, "Never happens, LocalEvent is not null")
NAPI.LocalEvent.TriggerEvent("testEvent"); //throw System.NullReferenceException (Exception has been thrown by the target of an invocation), no matter what arguments are provided

//serverside JS
mp.events.add(	"testEvent", () =>{
		console.log("Never called");
	});

 

Did someone already used this function ?

Thanks :)

Link to comment
Share on other sites

do smth like

 

// c# trigger clientside event
player.TriggerEvent("client.redirect", "myJSEventServerEvent");

// js cs event
mp.events.add("client.redirect", function(eventName: string) { mp.events.callRemote(eventName); }
         
//js serverside event
mp.events.add("myJSEventServerEvent", () => { console.log("js reached through rpc"); });  
            

 

fyi: this is just mind written, cuz i stopped my ragemp project, but should works otherwise lead you to a solution

Link to comment
Share on other sites

vor 5 Stunden schrieb taywon:

Hey !

Thank you for the answer. This trick will do the job, even if it's a bit nasty.

I'll write a bug report later !

Nah, it is nasty to use 2 different languages for server-side. I do not think that they will implement a js <> c# pipeline.
Better rewrite ur js to c# to get it clean

Link to comment
Share on other sites

19 hours ago, Division said:

Nah, it is nasty to use 2 different languages for server-side. I do not think that they will implement a js <> c# pipeline.
Better rewrite ur js to c# to get it clean

Maybe. Not sure.

It's faster to develop in JS, but the module that you script cannot be as fast (neither efficient) as it was developped in c#.
Two differents modules (e g gamemode vs population syncer) may be legitimately developped in two different language, even if it's imply low performance when the two modules communicates.

But you were probably right when you said that NAPI.LocalEvent.TriggerEvent may not be maintened.

TY again 😄

Link to comment
Share on other sites

  • 3 weeks later...

who says .NET is faster than JS? js has the speed / 2 of C++ while .NET compares worse

 

I think you're looking for

NAPI.ClientEvents.TriggerEvent

nvm you're looking for server events

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...