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 server packages and to clients.

Properties

This class does not have any properties.

Functions

jcmp.events.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!');
});

jcmp.events.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]

jcmp.events.Remove(EventInstance p1)

Parameter

Name Type Description
p1 EventInstance

jcmp.events.RemoveAll(string p1)

Parameter

Name Type Description
p1 string

jcmp.events.AddRemoteCallable(string name, function handler)

Adds an event that can be called from client scripts.

The first argument in the handler is the Player from where the event is being called.

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', player => {
  console.log(`${player.name} called MyEvent!`);
});

jcmp.events.CallRemote(string name, Player or null target, any ...args)

Calls an Event on the client side to one or all Players. Other than the normal Call function, this function does not return anything.

Parameter

Name Type Description
name string event name
target Player or null target to call the event on. If using `null`, the event will be broadcasted to all clients.
...args any optional event arguments

Example

// see the clientside documentation of EventSystem#AddRemoteCallable
jcmp.events.Add('PlayerReady', player => {
  jcmp.events.CallRemote('MyEvent', player);
});

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.