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.
The EventSystem is used to communicate between server packages and to clients.
This class does not have any properties.
Adds an event handler
returns: EventInstance
| Name | Type | Description |
|---|---|---|
| name | string | the event name |
| handler | function | the function to execute when the event is called |
jcmp.events.Add('MyEvent', () => {
console.log('hello world!');
});
Calls an Event.
This function always returns an array with all return values from all event handlers for that name.
returns: Array
| Name | Type | Description |
|---|---|---|
| name | string | event name |
| ...args | any | optional event arguments |
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]
| Name | Type | Description |
|---|---|---|
| p1 | EventInstance |
| Name | Type | Description |
|---|---|---|
| p1 | string |
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.
| Name | Type | Description |
|---|---|---|
| name | string | the event name |
| handler | function | the function to execute when the event is called |
jcmp.events.AddRemoteCallable('MyEvent', player => {
console.log(`${player.name} called MyEvent!`);
});
null target, any ...args)Calls an Event on the client side to one or all Players. Other than the normal
Callfunction, this function does not return anything.
| 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 |
// see the clientside documentation of EventSystem#AddRemoteCallable
jcmp.events.Add('PlayerReady', player => {
jcmp.events.CallRemote('MyEvent', player);
});
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.