Bug regarding events in the Javascript API

Server sided Javascript cannot trigger client sided javascript events using the “documented” calls.
emit() triggers a server event, contrary to the documentation at https://docs.fivem.net/scripting/javascript/.
emitNet() fails with a console warning of a non-existent native (matching that used in the lua TriggerServerEventInternal.)

Additionally, client sided onNet does not fire when the server event is fired, though this may be the intended behavior.

Comparing the scripting/lua and /v8 files, it appears emit() was hardcoded to the same native as TriggerEventInternal, while emitNet() was hardcoded to the (client only) TriggerServerEventInternal, and TriggerClientEventInternal (server only) was missed.

I’ve already been referred to this erroneous documentation multiple times for similar issues. Please implement the TriggerXEvent calls in Javascript and fix the documentation.

1 Like

This documentation (and the emit/emitNet wrappers themselves) predates having JS support on the server, it should be read from the perspective of only existing on the client - that is, emit() triggers a local event, and emitNet triggers a remote event.

I don’t know why you would want Trigger*Event to exist specifically; emitNet should however be implemented as a wrapper around TRIGGER_CLIENT_EVENT_INTERNAL (but isn’t at this time; there’s still other pending changes in the queue).

There are also a few other missing features in the JS high-level runtime code, such as wrapping around exports, and similarly the documentation doesn’t mention Yarn/Webpack builders nor the use of the Node.js API.

While it may be known to you that the documentation is out-of-date, it is not indicated there.

Trigger(target)Event is common to both Lua and C#, so the JS should offer the same for clarity.
And in my opinion, those are much more descriptive than the emit language.

It wasn’t known, no, we were already puzzled why people were assuming emit would trigger client event calls.

Perhaps so. Offering aliases is something that has already been done in the past (see Lua Citizen.Wait/Wait), so this could be considered.

I see the July 1st update has changes to the FXServer\citizen\scripting\v8\main.js relevant to the above. Are those supposed to be applied to \FiveM.app\citizen\scripting\v8\main.js as well? Or did I just screw up updating my client files?

These client changes are only in the canary channel so far.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.