-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetLocation.sp
More file actions
64 lines (51 loc) · 1.43 KB
/
SetLocation.sp
File metadata and controls
64 lines (51 loc) · 1.43 KB
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
#if defined _SET_LOCATION_H
#endinput
#endif
#define _SET_LOCATION_H
#include <sourcemod>
#include <str_util.sp>
#define MAX_LOCATION_NAME_SIZE 16
#define MAX_LOCATIONS 20
SetLocation setLocations[MAX_LOCATIONS];
void AddSetLocation(int client, const char[] name, float location[3] = NULL_VECTOR) {
if (IsNullVector(location)) {
GetClientAbsOrigin(client, location);
}
static int id = 1;
SetLocation setLocation;
setLocation.id = id++;
setLocation.client = client;
setLocation.location = location;
strcopy(setLocation.name, sizeof(setLocation.name), name);
//find an index in the array which is either occupied with the same client and name, or the first one with the lowest id
int index = 0;
for (int i = 0; i < sizeof(setLocations); i++) {
SetLocation slot;
slot = setLocations[i];
if (slot.client == client && streq(slot.name, name)) {
index = i;
break;
}
if (slot.id < setLocations[index].id) {
index = i;
}
}
setLocations[index] = setLocation;
}
bool GetSetLocation(SetLocation setLocation, int client, const char[] name) {
for (int i = 0; i < sizeof(setLocations); i++) {
SetLocation slot;
slot = setLocations[i];
if (slot.client == client && streq(slot.name, name)) {
setLocation = slot;
return true;
}
}
return false;
}
enum struct SetLocation {
float location[3];
char name[MAX_LOCATION_NAME_SIZE];
int client;
int id;
}