-
Notifications
You must be signed in to change notification settings - Fork 12
/
entity.inc
90 lines (78 loc) · 2.62 KB
/
entity.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
/**
* Entity property helpers.
*/
#if defined __stocksoup_entity_included
#endinput
#endif
#define __stocksoup_entity_included
#define COPYPROP_MAX_STRING_LENGTH 256
/**
* Assigns an integer value to the `dest` entity property from the `src` entity property.
*/
stock void CopyEntProp(int src, int dest, PropType type, const char[] prop, int size = 4,
int element = 0) {
SetEntProp(dest, type, prop, GetEntProp(src, type, prop, size, element), size, element);
}
/**
* Assigns a float value to the `dest` entity property from the `src` entity property.
*/
stock void CopyEntPropFloat(int src, int dest, PropType type, const char[] prop,
int element = 0) {
SetEntPropFloat(dest, type, prop, (GetEntPropFloat(src, type, prop, element)), element);
}
/**
* Assigns an entity index to the `dest` entity property from the `src` entity property.
*/
stock void CopyEntPropEnt(int src, int dest, PropType type, const char[] prop,
int element = 0) {
SetEntPropEnt(dest, type, prop, (GetEntPropEnt(src, type, prop, element)), element);
}
/**
* Assigns a string value to the `dest` entity property from the `src` entity property.
*/
stock void CopyEntPropString(int src, int dest, PropType type, const char[] prop,
int element = 0, int maxlen = COPYPROP_MAX_STRING_LENGTH) {
char[] buffer = new char[maxlen];
GetEntPropString(src, type, prop, buffer, maxlen, element);
SetEntPropString(dest, type, prop, buffer, element);
}
/**
* Assigns a vector of floats to the `dest` entity property from the `src` entity property.
*/
stock void CopyEntPropVector(int src, int dest, PropType type, const char[] prop,
int element = 0) {
float vec[3];
GetEntPropVector(src, type, prop, vec, element);
SetEntPropVector(dest, type, prop, vec, element);
}
/**
* Marks an entity for deletion, deferred until the next frame.
*/
stock void RemoveEntityNextFrame(int entity) {
RequestFrame(OnRemoveEntityFrame, EntIndexToEntRef(entity));
}
/**
* Internal `RequestFrameCallback` function that marks a given entity for deletion.
*/
static stock void OnRemoveEntityFrame(int entref) {
int entity = EntRefToEntIndex(entref);
if (IsValidEntity(entity)) {
RemoveEntity(entity);
}
}
/**
* Marks an entity for deletion after a given delay.
*/
stock void RemoveEntityDelayed(int entity, float delay) {
CreateTimer(delay, OnRemoveEntityTimer, EntIndexToEntRef(entity), TIMER_FLAG_NO_MAPCHANGE);
}
/**
* Internal `Timer` callback function that marks a given entity for deletion.
*/
static stock Action OnRemoveEntityTimer(Handle timer, int entref) {
int entity = EntRefToEntIndex(entref);
if (IsValidEntity(entity)) {
RemoveEntity(entity);
}
return Plugin_Handled;
}