-
Notifications
You must be signed in to change notification settings - Fork 9
/
client.js
69 lines (58 loc) · 1.91 KB
/
client.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Imgur CLIENT ID
const CLIENT_ID = 'yourImgurClientID';
let callbacks = {};
function getMugshotUrl( ped, cb ) {
let id = Object.keys( callbacks ).length++;
let url;
// Store the callback
callbacks[id] = cb;
// Register the ped headshot
let mugshot = RegisterPedheadshot(ped);
// Timeout needed to let the game register the mugshot..
setTimeout(() => {
// Assing the texture to a variable, unnecessary to call it twice in the DrawSprite function
let txdString = GetPedheadshotTxdString(mugshot);
let res = GetActiveScreenResolution();
const loop = setTick(() => {
DrawSprite(txdString, txdString, 0.045, 0.085, 0.10, 0.18, 0.0, 255, 255, 255, 1000);
});
// Another timeout needed since the setTick function takes a few milliseconds to.. start(?)
setTimeout(async() => {
// Screenshot the screen using screenshot-basic
let promise = new Promise(( resolve ) => {
exports['screenshot-basic'].requestScreenshotUpload(`https://api.imgur.com/3/image`, 'imgur', {
headers: {
'authorization': `Client-ID ${ CLIENT_ID }`,
'content-type': 'multipart/form-data'
},
crop: {
offsetX: 0,
offsetY: 0,
width : res[0] / 11,
height : res[1] / 6
}
}, ( data ) => {
clearTick(loop);
resolve(JSON.parse(data).data.link);
});
});
// Await the url
url = await promise;
// Use the callback function to send it back
callbacks[id](url);
// Delete the callback since it's no longer needed
delete callbacks[id];
// Unregister the ped headshot
UnregisterPedheadshot(mugshot)
}, 100);
}, 300);
}
// Mugshot command
RegisterCommand('mugshot', ( source, args ) => {
exports['mugshot'].getMugshotUrl(PlayerPedId(), ( url ) => {
emit('chat:addMessage', {
template: '<img src="{0}" style="width: 160px; height: 170px;" />',
args: [url]
});
});
});