Documentation

Want to improve the docs? Take a look at scripting-api-data!
Found a bug? jc3mp/bugs is a good place to let us know.

EventSystem

Constructible This class can not be instantiated from your script. Do not try to use the `new` keyword on this class. Auto Destroy Instances of this class will be deleted automatically. Custom Properties You cannot add your own properties to instances of this class. They will not be saved and can cause undefined behavior.

The EventSystem is used to communicate between client packages and to the server.

Properties

This class does not have any properties.

Functions

EventSystem.Add(string name, function handler)

Adds an event handler

returns: EventInstance

Parameter

Name Type Description
name string the event name
handler function the function to execute when the event is called

Example

jcmp.events.Add('MyEvent', () => {
  console.log('hello world!');
});

EventSystem.Call(string name, any ...args)

Calls an Event.

This function always returns an array with all return values from all event handlers for that name.

returns: Array

Parameter

Name Type Description
name string event name
...args any optional event arguments

Example

jcmp.events.Add('MyEvent', (x = 1) => {
  console.log(`the value of x is ${x}`);
  return x;
});
jcmp.events.Call('MyEvent'); // the value of x is 1
jcmp.events.Call('MyEvent', 5); // the value of x is 5

var ret = jcmp.events.Call('MyEvent');
// ret = [1]

EventSystem.Remove(EventInstance p1)

Parameter

Name Type Description
p1 EventInstance

EventSystem.RemoveAll(string p1)

Parameter

Name Type Description
p1 string

EventSystem.AddRemoteCallable(string name, function handler)

Adds an event that can be called from the server.

Parameter

Name Type Description
name string the event name
handler function the function to execute when the event is called

Example

jcmp.events.AddRemoteCallable('MyEvent', () => {
  print(`the server called MyEvent!`);
});

EventSystem.CallRemote(string name, any ...args)

Calls an Event on the server scripts. Other than the normal Call function, this function does not return anything.

Parameter

Name Type Description
name string event name
...args any optional event arguments

Example

// see the serverside documentation of EventSystem#AddRemoteCallable
jcmp.events.CallRemote('MyEvent');

Stay informed

By becoming the newest member of our growing forums, we and hundreds of other players will always keep you up to date on everything JC3:MP related.