forked from VANCOLD/fm_drive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FM_ENTMOD_BASE.sma
291 lines (231 loc) · 6.25 KB
/
FM_ENTMOD_BASE.sma
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#include "feckinmad/fm_global"
#include "feckinmad/entmod/fm_entmod_base"
#include <fakemeta>
#define MAX_ENTS 1365 // Note: This can actually be altered via the command line switch -num_edicts at runtime!
new Array:g_EntInfo[MAX_ENTS]
new Array:g_BrushModels, Array:g_BrushOrigins
new g_iBrushModelCount, g_iBrushOriginCount
new g_pCvarEnabled, bool:g_bEnabled
public plugin_precache()
{
g_pCvarEnabled = register_cvar("fm_entmod_enabled", "1")
if (get_pcvar_num(g_pCvarEnabled))
{
g_BrushModels = ArrayCreate(1)
g_BrushOrigins = ArrayCreate(1)
register_forward(FM_KeyValue, "Forward_KeyValue")
register_forward(FM_RemoveEntity, "Forward_RemoveEntity")
g_bEnabled = true
}
}
public plugin_init()
{
fm_RegisterPlugin()
register_clcmd("fm_ent_count", "Player_PrintEntCount")
}
public Player_PrintEntCount(id)
{
client_print(id, print_chat, "Entity Count: %d/%d", engfunc(EngFunc_NumberOfEntities), global_get(glb_maxEntities))
}
public plugin_end()
{
for (new i = 0; i < MAX_ENTS; i++)
{
if (g_EntInfo[i] != Invalid_Array)
{
ArrayDestroy(g_EntInfo[i])
}
}
}
public Forward_KeyValue(iEnt, Kvd)
{
static Buffer[eKeyValue_t]
get_kvd(Kvd, KV_KeyName, Buffer[m_sKey], MAX_KEY_LEN - 1)
get_kvd(Kvd, KV_Value, Buffer[m_sValue], MAX_VALUE_LEN - 1)
PushEntKeyValue(iEnt, Buffer)
if (equal(Buffer[m_sKey], "model") && Buffer[m_sValue][0] == '*')
{
ArrayPushCell(g_BrushModels, str_to_num(Buffer[m_sValue][1]))
g_iBrushModelCount++
}
if (equal(Buffer[m_sKey], "origin"))
{
ArrayPushCell(g_BrushOrigins, iEnt)
g_iBrushOriginCount++
}
}
PushEntKeyValue(iEnt, KeyValue[eKeyValue_t])
{
if (g_EntInfo[iEnt] == Invalid_Array)
{
g_EntInfo[iEnt] = ArrayCreate(eKeyValue_t, 1)
}
ArrayPushArray(g_EntInfo[iEnt], KeyValue)
}
public Forward_RemoveEntity(iEnt)
{
if (g_EntInfo[iEnt] != Invalid_Array)
{
ArrayDestroy(g_EntInfo[iEnt])
}
}
GetEntKeyValue(iEnt, const sKey[], sValue[] = "", iLen = 0)
{
if (g_EntInfo[iEnt] != Invalid_Array)
{
static Buffer[eKeyValue_t]
for (new i = 0, iSize = ArraySize(g_EntInfo[iEnt]); i < iSize; i++)
{
ArrayGetArray(g_EntInfo[iEnt], i, Buffer)
if (equal(Buffer[m_sKey], sKey))
{
if (iLen > 0) copy(sValue, iLen, Buffer[m_sValue])
return i
}
}
}
return -1
}
public plugin_natives()
{
register_native("fm_IsEntModEnabled", "Native_IsEntModEnabled")
register_native("fm_GetCachedEntKey", "Native_GetEntKey")
register_native("fm_GetCachedEntKeyIndex", "Native_GetEntKeyIndex")
register_native("fm_PushCachedEntKey", "Native_PushEntKey")
register_native("fm_SetCachedEntKey", "Native_SetEntKey")
register_native("fm_RemoveCachedEntKey", "Native_RemoveEntKey")
register_native("fm_RemoveCachedEntKeyIndex", "Native_RemoveEntKeyIndex")
register_native("fm_DestroyCachedEntKeys", "Native_DestroyEntKeys")
register_native("fm_CachedEntKeyCount", "Native_SizeEntKeys")
// The rest of these functions are in the fm_entmod_base.inc
// The float one has to be here to be able to set the parameter byref
register_native("fm_GetCachedEntKeyFloat", "Native_GetEntKeyFloat")
register_native("fm_IsValidBrushModel", "Native_IsValidBrushModel")
register_native("fm_EntityHasOriginBrush", "Native_EntityHasOriginBrush")
register_library("fm_entmod_base")
}
public Native_IsValidBrushModel()
{
new iModel = get_param(1)
for (new i = 0; i < g_iBrushModelCount; i++)
{
if (ArrayGetCell(g_BrushModels, i) == iModel)
{
return 1
}
}
return 0
}
public Native_EntityHasOriginBrush()
{
new iEnt = get_param(1)
for (new i = 0; i < g_iBrushOriginCount; i++)
{
if (ArrayGetCell(g_BrushOrigins, i) == iEnt)
{
return 1
}
}
return 0
}
public Native_IsEntModEnabled()
{
return g_bEnabled
}
// native fm_GetEntKey(iEnt, sKey[], sValue[] = "", iLen = 0)
public Native_GetEntKey(iPlugin, iParams)
{
static sKey[MAX_KEY_LEN], sValue[MAX_VALUE_LEN]
new iEnt = get_param(1)
get_string(2, sKey, charsmax(sKey))
new iIndex, iLen = get_param(4)
if (iLen > 0)
{
iIndex = GetEntKeyValue(iEnt, sKey, sValue, iLen)
set_string(3, sValue, iLen)
}
else
iIndex = GetEntKeyValue(iEnt, sKey)
return iIndex
}
// native fm_GetEntKey(iEnt, sKey[], fValue)
public Native_GetEntKeyFloat(iPlugin, iParams)
{
static sKey[MAX_KEY_LEN], sValue[MAX_VALUE_LEN]
new iEnt = get_param(1)
get_string(2, sKey, charsmax(sKey))
new iIndex = GetEntKeyValue(iEnt, sKey, sValue, charsmax(sValue))
set_float_byref(3, str_to_float(sValue))
return iIndex
}
// native fm_GetEntKeyIndex(iEnt, iIndex, sKey[], iKeyLen, sValue[], iValueLen)
public Native_GetEntKeyIndex(iPlugin, iParams)
{
new iEnt = get_param(1)
if (g_EntInfo[iEnt] == Invalid_Array)
return 0
new iIndex = get_param(2)
static Buffer[eKeyValue_t]; ArrayGetArray(g_EntInfo[iEnt], iIndex, Buffer)
set_string(3, Buffer[m_sKey], get_param(4))
set_string(5, Buffer[m_sValue], get_param(6))
return 1
}
// native fm_PushEntKey(iEnt, sKey[], sValue[])
public Native_PushEntKey(iPlugin, iParams)
{
new iEnt = get_param(1)
static Buffer[eKeyValue_t]
get_string(2, Buffer[m_sKey], MAX_KEY_LEN - 1)
get_string(3, Buffer[m_sValue], MAX_VALUE_LEN - 1)
PushEntKeyValue(iEnt, Buffer)
return 1
}
// native fm_SetEntKey(iEnt, sKey[], sValue[])
public Native_SetEntKey(iPlugin, iParams)
{
new iEnt = get_param(1)
static Buffer[eKeyValue_t]
get_string(2, Buffer[m_sKey], MAX_KEY_LEN - 1)
get_string(3, Buffer[m_sValue], MAX_VALUE_LEN - 1)
new iIndex = GetEntKeyValue(iEnt, Buffer[m_sKey])
if (iIndex != -1)
ArraySetArray(g_EntInfo[iEnt], iIndex, Buffer)
else
PushEntKeyValue(iEnt, Buffer)
return 1
}
public Native_RemoveEntKey(iPlugin, iParams)
{
new iEnt = get_param(1)
static sKey[MAX_KEY_LEN]; get_string(2, sKey, charsmax(sKey))
new iIndex = GetEntKeyValue(iEnt, sKey)
if (iIndex != -1)
{
ArrayDeleteItem(g_EntInfo[iEnt], iIndex)
return 1
}
return 0
}
public Native_RemoveEntKeyIndex(iPlugin, iParams)
{
new iEnt = get_param(1)
if (g_EntInfo[iEnt] == Invalid_Array)
return 0
ArrayDeleteItem(g_EntInfo[iEnt], get_param(2))
return 1
}
public Native_DestroyEntKeys(iPlugin, iParams)
{
new iEnt = get_param(1)
if (g_EntInfo[iEnt] == Invalid_Array)
return 0
ArrayDestroy(g_EntInfo[iEnt])
return 1
}
public Native_SizeEntKeys(iPlugin, iParams)
{
new iEnt = get_param(1)
if (g_EntInfo[iEnt] == Invalid_Array)
return 0
return ArraySize(g_EntInfo[iEnt])
}