-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclient.mjs
More file actions
32 lines (24 loc) · 761 Bytes
/
client.mjs
File metadata and controls
32 lines (24 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import * as alt from "alt";
// import * as utils from "utils"; My utils resource
var counter = 0;
var ClientCallbacks = {};
function getCounter() {
counter++;
return counter;
}
alt.onServer("communication=>response", (event, id, args) => {
ClientCallbacks[event][id](...args);
delete ClientCallbacks[event][id];
})
export function triggerServerCallback(event, callback, ...args) {
if (args == null or args == undefined) {
args = [];
}
// var id = utils.Random.getCounter(); Using my utils resource (Possibly not public <3)
var id = getCounter();
if (!ClientCallbacks[event]) {
ClientCallbacks[event] = [];
}
ClientCallbacks[event][id] = callback;
alt.emitServer(event, id, ...args);
}