-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtrailerSync.js
83 lines (78 loc) · 2.99 KB
/
trailerSync.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
YouTube: https://youtu.be/TEgLZFVHPEQ
#Кастомная синхронизация трейлеров для платформы RAGE:MP JJiGolem#7069
http://discord.gg/RqKSczZsNW - Сообщество Голема
#Приватная репозитория на github
https://github.com/JJiGolem/rage-custom-trailers-sync
Метод костыльный, но лучше, чем вообще ничего
Идея использовать клиент для синхры ))
*/
let trailers = {};
async function attachTrailerByVehicle(truck, trailer) {
let reAttachInterval = setInterval(() => {
if(mp.vehicles.exists(truck)) {
if(truck.getVariable("TRAILER") != null){
mp.events.call("Create::Trailer", truck, truck.position);
if(mp.vehicles.exists(trailer)) {
trailer.setCanBeVisiblyDamaged(false); //no damages
trailer.setCanBreak(false); //can break
trailer.setDeformationFixed(); //fixed deformation
trailer.setDirtLevel(0); //clear
trailer.setDisablePetrolTankDamage(true); //disable fueltank damage
trailer.setDisablePetrolTankFires(true); //disable fire fuel
trailer.setInvincible(true); //godmode
}
else {
if(reAttachInterval) clearInterval(reAttachInterval);
}
}
}
else {
if(reAttachInterval) clearInterval(reAttachInterval);
}
}, 1000);
};
mp.events.add('Create::Trailer', (truck, position) => {
if(trailers[truck.remoteId] != null) {
setTimeout(() => {
truck.attachToTrailer(trailers[truck.remoteId].handle, 1000);
}, 50);
return;
}
let trailer = mp.vehicles.new(mp.game.joaat(truck.getVariable("TRAILER")), position,
{
heading: truck.getHeading(),
numberPlate: "TRAILER"
});
trailers[truck.remoteId] = trailer;
if(trailer != null){
setTimeout(() => {
truck.attachToTrailer(trailer.handle, 1000);
attachTrailerByVehicle(truck, trailer);
}, 200);
}
else {
mp.gui.chat.push("к сожалению, голем, твой трейлер не заспавнился...ты идиот");
}
});
mp.events.add('entityStreamIn', (entity) => {
if(entity && mp.vehicles.exists(entity)){
if(entity.type == "vehicle"){
if(entity.getVariable("TRAILER") != null){
mp.events.call("Create::Trailer", entity, entity.position);
}
}
}
});
mp.events.add('entityStreamOut', (entity) => {
if(entity && mp.vehicles.exists(entity)){
if(entity.type == "vehicle"){
if(entity.getVariable("TRAILER") != null){
if(trailers[entity.remoteId] != null) {
trailers[entity.remoteId].destroy();
trailers[entity.remoteId] = null;
}
}
}
}
});