-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmarker_controller.js
146 lines (110 loc) · 3.48 KB
/
marker_controller.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var currentSpherePos = null;
var currentSphereScale = null;
var marker = null;
var destinationPos = null;
var destinationScale = null;
var interpolatingPos = false;
var interpolation = 0.0;
var interpolationStart = 0;
var interpolationEnd = 0;
var isInsideSphere = true;
var lastSphereLeave = 0;
var roundEnd = false;
//"Explosion_Countdown", NETWORK::NET_TO_VEH(l_181/*2*/]._f1), "GTAO_FM_Events_Soundset", 0,
API.onServerEventTrigger.connect(function (eventName, args) {
if (eventName == "pennedin_roundend") {
if (marker != null) {
API.deleteEntity(marker);
}
roundEnd = true;
}
if (eventName == "pennedin_roundstart") {
currentSpherePos = args[0];
currentSphereScale = args[1];
roundEnd = false;
destinationPos = null;
destinationScale = null;
interpolation = 0;
interpolationStart = 0;
interpolationEnd = 0;
interpolatingPos = false;
lastSphereLeave = 0;
isInsideSphere = true;
if (marker != null) {
API.deleteEntity(marker);
}
marker = API.createMarker(28, currentSpherePos,
new Vector3(), new Vector3(),
new Vector3(currentSphereScale, currentSphereScale, currentSphereScale),
255, 0, 0, 100);
}
if (eventName == "pennedin_setposdestination") {
if (marker == null) return;
if (destinationScale != null)
{
currentSphereScale = destinationScale;
destinationScale = null;
}
currentSpherePos = args[0];
destinationPos = args[1];
API.setMarkerPosition(marker, currentSpherePos);
interpolatingPos = true;
interpolation = 0;
interpolationStart = API.getGlobalTime();
interpolationEnd = args[2];
}
if (eventName == "pennedin_setscaledestination") {
if (marker == null) return;
if (destinationPos != null)
{
currentSpherePos = destinationPos;
destinationPos = null;
}
currentSphereScale = args[0];
destinationScale = args[1];
API.setMarkerScale(marker, new Vector3(currentSphereScale, currentSphereScale, currentSphereScale));
interpolatingPos = false;
interpolation = 0;
interpolationStart = API.getGlobalTime();
interpolationEnd = args[2];
}
});
API.onUpdate.connect(function(sender, e) {
if (interpolationStart != 0 && marker != null) {
var cTime = API.getGlobalTime() - interpolationStart;
var dur = interpolationEnd;
var newScale = currentSphereScale;
var newPos = currentSpherePos;
if (interpolatingPos) {
newPos = API.lerpVector(currentSpherePos, destinationPos, cTime, dur);
API.setMarkerPosition(marker, newPos);
} else {
newScale = API.lerpFloat(currentSphereScale, destinationScale, cTime, dur);
API.setMarkerScale(marker, new Vector3(newScale, newScale, newScale));
}
var player = API.getLocalPlayer();
var playerPos = API.getEntityPosition(player);
var isInRange = API.isInRangeOf(playerPos, newPos, newScale);
if (!isInRange && isInsideSphere) {
lastSphereLeave = API.getGlobalTime();
} else if (isInRange && !isInsideSphere) {
API.displaySubtitle("");
}
isInsideSphere = isInRange;
if (!isInRange) {
var timeLeft = 10000 - (API.getGlobalTime() - lastSphereLeave);
API.displaySubtitle("~r~Return to the sphere or die in ~w~" + API.formatTime(timeLeft, "ss\\.fff"));
if (API.getGlobalTime() - lastSphereLeave > 10000) {
API.setPlayerHealth(player, -1);
API.deleteEntity(marker);
marker = null;
roundEnd = true;
}
}
}
});
API.onResourceStop.connect(function(sender, e) {
if (marker != null) {
API.deleteEntity(marker);
}
});