forked from Kxnrl/Store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store_stock.inc
411 lines (354 loc) · 12.7 KB
/
store_stock.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
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#if defined __STORE_STOCK__
#endinput
#endif
#define __STORE_STOCK__
#if !defined abstract_struct
#define abstract_struct enum struct
#endif
#include <sdktools>
#define STRING(%1) %1, sizeof(%1)
abstract_struct Item_Plan
{
char szName[ITEM_NAME_LENGTH];
int iPrice;
int iTime;
}
abstract_struct Type_Handler
{
char szType[64];
char szPlFile[64];
bool bEquipable;
bool bRaw;
bool bDisposable;
Handle hPlugin;
Function fnMapStart;
Function fnReset;
Function fnConfig;
Function fnUse;
Function fnRemove;
}
abstract_struct Client_Item
{
int iId;
int iUniqueId;
bool bSynced;
bool bDeleted;
int iDateOfPurchase;
int iDateOfExpiration;
int iPriceOfPurchase;
}
abstract_struct Client_Data
{
int iId;
int iUserId;
char szAuthId[32];
int iCredits;
int iOriginalCredits;
int iDateOfJoin;
int iDateOfLastJoin;
int iItems;
int aEquipment[STORE_MAX_HANDLERS * STORE_MAX_SLOTS];
int aEquipmentSynced[STORE_MAX_HANDLERS * STORE_MAX_SLOTS];
bool bBan;
bool bLoaded;
bool bRefresh;
Handle hTimer;
}
abstract_struct Menu_Handler
{
char szIdentifier[64];
char szPlFile[64];
Handle hPlugin;
Function fnMenu;
Function fnHandler;
}
abstract_struct Compose_Data
{
int item1;
int item2;
int types;
}
stock bool InsertMenuItemEx(Menu menu, int position, int style, char[] info, char[] display, any...)
{
char m_display[256];
VFormat(STRING(m_display), display, 6);
return (menu.ItemCount == position) ? menu.AddItem(info, m_display, style) : menu.InsertItem(position, info, m_display, style);
}
stock void LogStoreError(const char[] buffer, any...)
{
static char path[128];
if (!path[0])
BuildPath(Path_SM, STRING(path), "logs/store.error.log");
char error[1024];
VFormat(STRING(error), buffer, 2);
LogToFileEx(path, error);
}
static void SQLCallback_Void_PrintQuery(Database db, DBResultSet results, const char[] error, DataPack pack)
{
float time = GetEngineTime() - pack.ReadFloat();
char query[1024];
pack.ReadString(STRING(query));
delete pack;
if (results == null || error[0])
LogStoreError("SQL error happened.\nError: %s\nQuery: %s", error, query);
else if (time >= 15.0)
LogMessage("Store SQL slow query.\nTime : %fs\nQuery: %s", time, query);
}
stock void SQL_TVoid(Database db, char[] query, DBPriority dbp = DBPrio_Normal)
{
DataPack data = new DataPack();
data.WriteFloat(GetEngineTime());
data.WriteString(query);
data.Reset();
db.Query(SQLCallback_Void_PrintQuery, query, data, dbp);
}
stock bool AllowItemForAuth(int client, const char[] authid)
{
if (authid[0] == 0)
return true;
char m_szAuthId[32];
if (!GetClientAuthId(client, AuthId_Steam2, STRING(m_szAuthId)))
return false;
if (StrContains(authid, m_szAuthId) == -1)
return false;
return true;
}
stock bool AllowItemForVIP(int client, bool vip)
{
if (!vip)
return true;
int flags = GetUserFlagBits(client);
if (flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION)
return true;
return false;
}
stock bool IsValidClient(int client)
{
if (client > MaxClients || client < 1)
return false;
if (!IsClientInGame(client))
return false;
return true;
}
stock void ClearTimer(Handle &timer)
{
if (timer != INVALID_HANDLE)
{
KillTimer(timer);
timer = INVALID_HANDLE;
}
}
stock bool AddMenuItemEx(Menu menu, int style, char[] info, char[] display, any...)
{
char m_display[256];
VFormat(STRING(m_display), display, 5);
return menu.AddItem(info, m_display, style);
}
stock void tPrintToChat(int client, const char[] szMessage, any...)
{
char szBuffer[256];
VFormat(STRING(szBuffer), szMessage, 3);
Format(STRING(szBuffer), "[{green}Store{white}] %s", szBuffer);
ReplaceColorsCode(STRING(szBuffer));
SayText2(client, szBuffer);
}
stock void tPrintToChatAll(const char[] szMessage, any...)
{
char szBuffer[256];
for (int client = 1; client <= MaxClients; client++)
{
if (IsClientInGame(client) && !IsFakeClient(client))
{
SetGlobalTransTarget(client);
VFormat(STRING(szBuffer), szMessage, 2);
Format(STRING(szBuffer), "[{green}Store{white}] %s", szBuffer);
ReplaceColorsCode(STRING(szBuffer));
SayText2(client, szBuffer);
}
}
}
stock void SayText2(int client, const char[] text, int sender = 0, bool sound = true)
{
static EngineVersion engine = Engine_Unknown;
if (engine == Engine_Unknown)
engine = GetEngineVersion();
Handle um = StartMessageOne(engine == Engine_CSGO ? "SayText2" : "SayText", client, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
if (um == null)
{
LogError("StartMessageOne -> SayText2 is null");
return;
}
if (engine == Engine_CSGO)
{
Protobuf msg = view_as<Protobuf>(um);
msg.SetInt("ent_idx", sender);
msg.SetBool("chat", sound);
msg.SetString("msg_name", text);
msg.AddString("params", "");
msg.AddString("params", "");
msg.AddString("params", "");
msg.AddString("params", "");
EndMessage();
}
else // for L4D2/Insurgency
{
BfWrite msg = view_as<BfWrite>(um);
msg.WriteByte(sender);
msg.WriteByte(sound);
msg.WriteString(text);
EndMessage();
}
}
stock void ReplaceColorsCode(char[] message, int maxLen, int team = 0)
{
static EngineVersion engine = Engine_Unknown;
if (engine == Engine_Unknown)
engine = GetEngineVersion();
if (engine == Engine_CSGO)
{
ReplaceString(message, maxLen, "{normal}", "\x01", false);
ReplaceString(message, maxLen, "{default}", "\x01", false);
ReplaceString(message, maxLen, "{white}", "\x01", false);
ReplaceString(message, maxLen, "{team}", "\x03", false);
ReplaceString(message, maxLen, "{darkred}", "\x02", false);
ReplaceString(message, maxLen, "{pink}", "\x03", false);
ReplaceString(message, maxLen, "{green}", "\x04", false);
ReplaceString(message, maxLen, "{lightgreen}", "\x05", false);
ReplaceString(message, maxLen, "{lime}", "\x06", false);
ReplaceString(message, maxLen, "{red}", "\x07", false);
ReplaceString(message, maxLen, "{grey}", "\x08", false);
ReplaceString(message, maxLen, "{yellow}", "\x09", false);
ReplaceString(message, maxLen, "{gold}", "\x10", false);
ReplaceString(message, maxLen, "{silver}", "\x0A", false);
ReplaceString(message, maxLen, "{blue}", "\x0B", false);
ReplaceString(message, maxLen, "{darkblue}", "\x0C", false);
ReplaceString(message, maxLen, "{purple}", "\x0E", false);
ReplaceString(message, maxLen, "{lightred}", "\x0F", false);
switch (team)
{
case 3: ReplaceString(message, maxLen, "{teamcolor}", "\x0B", false);
case 2: ReplaceString(message, maxLen, "{teamcolor}", "\x05", false);
default: ReplaceString(message, maxLen, "{teamcolor}", "\x01", false);
}
}
else
{
ReplaceString(message, maxLen, "{normal}", "\x07FFFFFF", false);
ReplaceString(message, maxLen, "{default}", "\x07FFFFFF", false);
ReplaceString(message, maxLen, "{white}", "\x07FFFFFF", false);
ReplaceString(message, maxLen, "{darkred}", "\x07FF0000", false);
ReplaceString(message, maxLen, "{pink}", "\x07D32CE6", false);
ReplaceString(message, maxLen, "{green}", "\x077FFF00", false);
ReplaceString(message, maxLen, "{lime}", "\x07BFFF00", false);
ReplaceString(message, maxLen, "{yellow}", "\x07FFD700", false);
ReplaceString(message, maxLen, "{lightgreen}", "\x0798FB98", false);
ReplaceString(message, maxLen, "{lightred}", "\x07EB4B4B", false);
ReplaceString(message, maxLen, "{red}", "\x07DC143C", false);
ReplaceString(message, maxLen, "{gray}", "\x07DCDCDC", false);
ReplaceString(message, maxLen, "{grey}", "\x07DCDCDC", false);
ReplaceString(message, maxLen, "{olive}", "\x07808000", false);
ReplaceString(message, maxLen, "{gold}", "\x07E4AE39", false);
ReplaceString(message, maxLen, "{silver}", "\x07B0C3D9", false);
ReplaceString(message, maxLen, "{lightblue}", "\x075E98D9", false);
ReplaceString(message, maxLen, "{blue}", "\x074B69FF", false);
ReplaceString(message, maxLen, "{purple}", "\x078847FF", false);
ReplaceString(message, maxLen, "{darkorange}", "\x07CF6A32", false);
}
}
stock void RemoveAllColors(char[] message, int maxLen)
{
ReplaceColorsCode(message, maxLen);
ReplaceString(message, maxLen, "\x01", "", false);
ReplaceString(message, maxLen, "\x02", "", false);
ReplaceString(message, maxLen, "\x03", "", false);
ReplaceString(message, maxLen, "\x04", "", false);
ReplaceString(message, maxLen, "\x05", "", false);
ReplaceString(message, maxLen, "\x06", "", false);
ReplaceString(message, maxLen, "\x07", "", false);
ReplaceString(message, maxLen, "\x08", "", false);
ReplaceString(message, maxLen, "\x09", "", false);
ReplaceString(message, maxLen, "\x10", "", false);
ReplaceString(message, maxLen, "\x0A", "", false);
ReplaceString(message, maxLen, "\x0B", "", false);
ReplaceString(message, maxLen, "\x0C", "", false);
ReplaceString(message, maxLen, "\x0D", "", false);
ReplaceString(message, maxLen, "\x0E", "", false);
ReplaceString(message, maxLen, "\x0F", "", false);
ReplaceString(message, maxLen, "\x07FFFFFF", "", false);
ReplaceString(message, maxLen, "\x07FFFFFF", "", false);
ReplaceString(message, maxLen, "\x07FFFFFF", "", false);
ReplaceString(message, maxLen, "\x07FF0000", "", false);
ReplaceString(message, maxLen, "\x07D32CE6", "", false);
ReplaceString(message, maxLen, "\x077FFF00", "", false);
ReplaceString(message, maxLen, "\x07BFFF00", "", false);
ReplaceString(message, maxLen, "\x07FFD700", "", false);
ReplaceString(message, maxLen, "\x0798FB98", "", false);
ReplaceString(message, maxLen, "\x07EB4B4B", "", false);
ReplaceString(message, maxLen, "\x07DC143C", "", false);
ReplaceString(message, maxLen, "\x07DCDCDC", "", false);
ReplaceString(message, maxLen, "\x07DCDCDC", "", false);
ReplaceString(message, maxLen, "\x07808000", "", false);
ReplaceString(message, maxLen, "\x07E4AE39", "", false);
ReplaceString(message, maxLen, "\x07B0C3D9", "", false);
ReplaceString(message, maxLen, "\x075E98D9", "", false);
ReplaceString(message, maxLen, "\x074B69FF", "", false);
ReplaceString(message, maxLen, "\x078847FF", "", false);
ReplaceString(message, maxLen, "\x07CF6A32", "", false);
}
stock int SpawnSpeakerEntity(float fPos[3], float fAgl[3], float removeDelay = 0.1)
{
int speaker = CreateEntityByName("info_target");
if (speaker == INVALID_ENT_REFERENCE)
return INVALID_ENT_REFERENCE;
DispatchKeyValue(speaker, "spawnflags", "2");
TeleportEntity(speaker, fPos, fAgl, NULL_VECTOR);
DispatchSpawn(speaker);
ActivateEntity(speaker);
if (removeDelay > 0.0)
{
/*
char input[128];
FormatEx(STRING(input), "OnUser4 !self:Kill::%.2f:1", removeDelay);
SetVariantString(input);
AcceptEntityInput(speaker, "AddOutput");
AcceptEntityInput(speaker, "FireUser4");
*/
// this for g_EventQueue.Clear() called in CCSGameRules::CleanupMap().
CreateTimer(removeDelay, Timer_RemoveSpeaker, EntIndexToEntRef(speaker), TIMER_FLAG_NO_MAPCHANGE);
}
return speaker;
}
static Action Timer_RemoveSpeaker(Handle timer, int ref)
{
int speaker = EntRefToEntIndex(ref);
if (speaker != INVALID_ENT_REFERENCE)
RemoveEntity(speaker);
return Plugin_Stop;
}
// https://forums.alliedmods.net/showpost.php?p=2471747&postcount=4
stock void PrecacheParticleEffect(const char[] effect)
{
static int table = INVALID_STRING_TABLE;
if (table == INVALID_STRING_TABLE)
table = FindStringTable("ParticleEffectNames");
bool save = LockStringTables(false);
AddToStringTable(table, effect);
LockStringTables(save);
}
stock void PrecacheEffect(const char[] name)
{
static int table = INVALID_STRING_TABLE;
if (table == INVALID_STRING_TABLE)
table = FindStringTable("EffectDispatch");
bool save = LockStringTables(false);
AddToStringTable(table, name);
LockStringTables(save);
}
#define SIZE_OF_INT 2147483647
stock int UTIL_GetRandomInt(int min, int max)
{
int random = GetURandomInt();
if (random == 0)
random++;
return RoundToCeil(float(random) / (float(SIZE_OF_INT) / float(max - min + 1))) + min - 1;
}