-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckpointstream.inc
258 lines (212 loc) · 6.18 KB
/
checkpointstream.inc
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
About: checkpoint stream system
Author: ziggi
*/
#if defined _checkpoint_stream_included
#endinput
#endif
#define _checkpoint_stream_included
#pragma library checkpoint_stream
#define INVALID_CHECKPOINT_ID -1
#define MAX_CHECKPOINTS 255
#define CHECKPOINT_STREAM_DISTANCE 200.0
#define CHECKPOINT_STREAM_MAX_DISTANCE 65000.0
enum info_Checkpoint {
Float:cp_x,
Float:cp_y,
Float:cp_z,
Float:cp_size,
cp_world,
cp_interior,
cp_playerid,
Float:cp_dist,
bool:cp_isvalid,
}
enum info_Player_Checkpoint {
cp_isactive[MAX_CHECKPOINTS],
cp_currentid,
}
static
checkpoints[MAX_CHECKPOINTS][info_Checkpoint],
player_checkpoints[MAX_PLAYERS][info_Player_Checkpoint];
Checkpoint_OnPlayerConnect(playerid)
{
Checkpoint_ResetPlayerData(playerid);
Checkpoint_ToggleAllForPlayer(playerid, 1);
return 1;
}
stock Checkpoint_Create(Float:x, Float:y, Float:z, Float:size, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = CHECKPOINT_STREAM_DISTANCE)
{
new cpid = Checkpoint_GetFreeId();
if (cpid == INVALID_CHECKPOINT_ID) {
printf("Checkpoint: Error: checkpoint limit is full (%d).", MAX_CHECKPOINTS);
return INVALID_CHECKPOINT_ID;
}
checkpoints[cpid][cp_x] = x;
checkpoints[cpid][cp_y] = y;
checkpoints[cpid][cp_z] = z;
checkpoints[cpid][cp_size] = size;
checkpoints[cpid][cp_world] = worldid;
checkpoints[cpid][cp_interior] = interiorid;
checkpoints[cpid][cp_playerid] = playerid;
checkpoints[cpid][cp_dist] = streamdistance;
checkpoints[cpid][cp_isvalid] = true;
return cpid;
}
stock Checkpoint_Delete(cpid)
{
if (!Checkpoint_IsValid(cpid)) {
return 0;
}
checkpoints[cpid][cp_x] = 0.0;
checkpoints[cpid][cp_y] = 0.0;
checkpoints[cpid][cp_z] = 0.0;
checkpoints[cpid][cp_size] = 0.0;
checkpoints[cpid][cp_world] = -1;
checkpoints[cpid][cp_interior] = -1;
checkpoints[cpid][cp_playerid] = -1;
checkpoints[cpid][cp_dist] = CHECKPOINT_STREAM_DISTANCE;
checkpoints[cpid][cp_isvalid] = false;
return 1;
}
Checkpoint_Stream(playerid)
{
new cpid = Checkpoint_GetPlayerClosest(playerid);
if (cpid != INVALID_CHECKPOINT_ID && cpid != player_checkpoints[playerid][cp_currentid]) {
player_checkpoints[playerid][cp_currentid] = cpid;
SetPlayerCheckpoint(playerid, checkpoints[cpid][cp_x], checkpoints[cpid][cp_y], checkpoints[cpid][cp_z], checkpoints[cpid][cp_size]);
} else if (cpid == INVALID_CHECKPOINT_ID) {
player_checkpoints[playerid][cp_currentid] = INVALID_CHECKPOINT_ID;
DisablePlayerCheckpoint(playerid);
}
}
stock Checkpoint_GetPlayerClosest(playerid)
{
new Float:min_dist = CHECKPOINT_STREAM_MAX_DISTANCE,
Float:dist,
result_id = INVALID_CHECKPOINT_ID,
is_active, is_in_world, is_in_interior, is_for_playerid;
for (new cpid = 0; cpid < MAX_CHECKPOINTS; cpid++) {
if (!Checkpoint_IsValid(cpid)) {
continue;
}
is_active = Checkpoint_IsActiveForPlayer(playerid, cpid);
if (!is_active) {
continue;
}
is_in_world = Checkpoint_IsPlayerInWorld(playerid, cpid);
if (!is_in_world) {
continue;
}
is_in_interior = Checkpoint_IsPlayerInInterior(playerid, cpid);
if (!is_in_interior) {
continue;
}
is_for_playerid = Checkpoint_IsForPlayer(playerid, cpid);
if (!is_for_playerid) {
continue;
}
dist = GetPlayerDistanceFromPoint(playerid, checkpoints[cpid][cp_x], checkpoints[cpid][cp_y], checkpoints[cpid][cp_z]);
if (dist <= checkpoints[cpid][cp_dist] && dist < min_dist) {
min_dist = dist;
result_id = cpid;
}
}
return result_id;
}
stock Checkpoint_GetPos(cpid, &Float:x, &Float:y, &Float:z)
{
if (!Checkpoint_IsValid(cpid)) {
return 0;
}
x = checkpoints[cpid][cp_x];
y = checkpoints[cpid][cp_y];
z = checkpoints[cpid][cp_z];
return 1;
}
stock Checkpoint_FindByCoord(Float:x, Float:y, Float:z)
{
for (new cpid = 0; cpid < MAX_CHECKPOINTS; cpid++) {
if (!Checkpoint_IsValid(cpid)) {
continue;
}
if (x == checkpoints[cpid][cp_x] && y == checkpoints[cpid][cp_y] && z == checkpoints[cpid][cp_z]) {
return cpid;
}
}
return INVALID_CHECKPOINT_ID;
}
stock Checkpoint_GetFreeId()
{
for (new cpid = 0; cpid < MAX_CHECKPOINTS; cpid++) {
if (checkpoints[cpid][cp_isvalid] == false) {
return cpid;
}
}
return INVALID_CHECKPOINT_ID;
}
stock Checkpoint_ResetPlayerData(playerid)
{
player_checkpoints[playerid][cp_currentid] = INVALID_CHECKPOINT_ID;
for (new cpid = 0; cpid < MAX_CHECKPOINTS; cpid++) {
player_checkpoints[playerid][cp_isactive][cpid] = 0;
}
return 1;
}
stock Checkpoint_IsValid(cpid)
{
if (cpid < 0 || cpid > MAX_CHECKPOINTS || checkpoints[cpid][cp_isvalid] == false) {
return 0;
}
return 1;
}
stock Checkpoint_ToggleForPlayer(playerid, cpid, toggle)
{
if (!Checkpoint_IsValid(cpid)) {
return 0;
}
player_checkpoints[playerid][cp_isactive][cpid] = toggle;
Checkpoint_Stream(playerid);
return 1;
}
stock Checkpoint_ToggleAllForPlayer(playerid, toggle)
{
for (new cpid = 0; cpid < MAX_CHECKPOINTS; cpid++) {
if (!Checkpoint_IsValid(cpid)) {
return 0;
}
player_checkpoints[playerid][cp_isactive][cpid] = toggle;
}
Checkpoint_Stream(playerid);
return 1;
}
stock Checkpoint_IsActiveForPlayer(playerid, cpid)
{
if (!Checkpoint_IsValid(cpid)) {
return 0;
}
return player_checkpoints[playerid][cp_isactive][cpid] == 1 ? 1 : 0;
}
stock Checkpoint_IsPlayerIn(playerid, cpid)
{
if (!Checkpoint_IsValid(cpid)) {
return 0;
}
return IsPlayerInRangeOfPoint(playerid, checkpoints[cpid][cp_dist], checkpoints[cpid][cp_x], checkpoints[cpid][cp_y], checkpoints[cpid][cp_z]);
}
stock Checkpoint_GetPlayerVisible(playerid)
{
return player_checkpoints[playerid][cp_currentid];
}
stock Checkpoint_IsPlayerInWorld(playerid, cpid)
{
return checkpoints[cpid][cp_world] == -1 || checkpoints[cpid][cp_world] == GetPlayerVirtualWorld(playerid);
}
stock Checkpoint_IsPlayerInInterior(playerid, cpid)
{
return checkpoints[cpid][cp_interior] == -1 || checkpoints[cpid][cp_interior] == GetPlayerInterior(playerid);
}
stock Checkpoint_IsForPlayer(playerid, cpid)
{
return checkpoints[cpid][cp_playerid] == -1 || checkpoints[cpid][cp_playerid] == playerid;
}