Repository navigation
Expand file tree
/
Copy pathcouples.sp
More file actions
377 lines (305 loc) · 11.4 KB
/
Copy pathcouples.sp
File metadata and controls
377 lines (305 loc) · 11.4 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
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
#include <clientprefs>
#include <sdktools>
#include <sourcemod>
#include <shavit/core>
#include <shavit/rankings>
#include <shavit/wr>
#pragma semicolon 1
#pragma newdecls required
#define PLUGIN_VERSION "1337"
bool gB_Queried[MAXPLAYERS + 1];
int gI_Proposer[MAXPLAYERS + 1];
bool gB_Married[MAXPLAYERS + 1];
int gI_Spouse[MAXPLAYERS + 1];
char gS_Spouse[MAXPLAYERS + 1][32 + 1];
int gI_ResultIndex;
// Database gH_Database = null;
Database shavitdb = null;
char gS_ShavitPrefix[32];
chatstrings_t gS_ChatStrings;
public Plugin myinfo =
{
name = "couples",
author = "may and rtldg", // puff did all the hard stuff @_@
description = "i love kaworu (fuck u puff)",
version = PLUGIN_VERSION,
url = "Your website URL/AlliedModders profile URL"
};
public void Shavit_OnChatConfigLoaded()
{
Shavit_GetChatStringsStruct(gS_ChatStrings);
}
public void OnPluginStart()
{
RegConsoleCmd("sm_marry", Command_Marry, "");
RegConsoleCmd("sm_divorce", Command_Divorce, "");
RegConsoleCmd("sm_couples", Command_Couples, "");
RegConsoleCmd("sm_accept", Command_Accept, "");
RegConsoleCmd("sm_reject", Command_Reject, "");
RegConsoleCmd("sm_couplesdebug", Command_Debug, "");
LoadTranslations("common.phrases");
SetUpDB();
}
void SetUpDB()
{
GetTimerSQLPrefix(gS_ShavitPrefix, 32);
shavitdb = GetTimerDatabaseHandle();
SQL_Query(shavitdb, "CREATE TABLE IF NOT EXISTS couples (steamid INT, spouseid INT, points FLOAT, timestamp INT)");
}
public void OnClientConnected(int client)
{
gB_Queried[client] = false;
gB_Married[client] = false;
gI_Proposer[client] = 0;
gS_Spouse[client][0] = '\0';
gI_Spouse[client] = 0;
}
public void OnClientDisconnect(int client)
{
for (int i = 0; i < MaxClients; i++)
{
if (gI_Proposer[i] == client)
gI_Proposer[i] = 0;
}
}
public void OnClientAuthorized(int client)
{
if (!IsFakeClient(client))
{
int steamid = GetSteamAccountID(client);
char query[512];
FormatEx(query, sizeof(query),
"SELECT * FROM couples WHERE steamid = %d OR spouseid = %d",
steamid, steamid);
shavitdb.Query(SQL_GetSpouse, query, GetClientSerial(client));
}
}
public Action Command_Marry(int client, int args)
{
if (!gB_Queried[client]) return Plugin_Handled;
// if (args < 1) return Plugin_Handled;
char name[32 + 1];
GetCmdArgString(name, sizeof(name));
int target = FindTarget(client, name, true, false);
if (target == -1)
{
// PrintToChat(client, "no matching client found");
return Plugin_Handled;
}
if (!IsClientAuthorized(target) || !gB_Queried[target])
{
PrintToChat(client, "%N isn't authorized...", target);
return Plugin_Handled;
}
if (gB_Married[target])
{
PrintToChat(client, "%sthe person you love is already married to %s%s", gS_ChatStrings.sText, gS_ChatStrings.sStyle, gS_Spouse[target]);
return Plugin_Handled;
}
if (gB_Married[client])
{
PrintToChat(client, "%syou are already married to %s%s", gS_ChatStrings.sText, gS_ChatStrings.sStyle, gS_Spouse[client]);
return Plugin_Handled;
}
if (target == client)
{
PrintToChat(client, "%syou can't marry yourself!", gS_ChatStrings.sText, gS_ChatStrings.sStyle, gS_Spouse[client]);
return Plugin_Handled;
}
gI_Proposer[target] = client;
PrintToChat(client, "%syou've sent a request to %s%N", gS_ChatStrings.sText, gS_ChatStrings.sStyle, target);
PrintToChat(target, "%syou've received a marriage proposal from %s%N%s, accept it with %s!accept%s or decline with %s!reject", gS_ChatStrings.sText, gS_ChatStrings.sStyle, client, gS_ChatStrings.sText, gS_ChatStrings.sWarning, gS_ChatStrings.sText, gS_ChatStrings.sWarning);
return Plugin_Handled;
}
public Action Command_Divorce(int client, int args)
{
if (gB_Queried[client] && gB_Married[client])
{
PrintToChatAll("%s%N%s just divorced %s%s%s ;w; %s</3", gS_ChatStrings.sVariable, client, gS_ChatStrings.sText, gS_ChatStrings.sVariable, gS_Spouse[client], gS_ChatStrings.sText, gS_ChatStrings.sStyle);
char query[512];
FormatEx(query, sizeof(query),
"DELETE FROM couples WHERE steamid = %i OR spouseid = %i",
GetSteamAccountID(client), GetSteamAccountID(client));
shavitdb.Query(SQL_Divorce, query, GetClientSerial(client));
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && IsValidClient(i) && GetSteamAccountID(i) == gI_Spouse[client])
{
gB_Married[i] = false;
gI_Spouse[i] = 0;
}
}
gB_Married[client] = false;
gI_Spouse[client] = 0;
}
else
{
PrintToChat(client, "%syou are not married ;w;", gS_ChatStrings.sText);
}
}
public Action Command_Couples(int client, int args)
{
char query[512];
FormatEx(query, sizeof(query), "SELECT u1.name, u2.name, steamid, spouseid, FORMAT(c.points, 2), timestamp FROM couples c JOIN users u1 ON u1.auth = steamid JOIN users u2 ON u2.auth = spouseid ORDER BY c.points DESC LIMIT 100;");
shavitdb.Query(SQL_Couples, query, GetClientSerial(client));
}
public Action Command_Accept(int client, int args)
{
int proposer = gI_Proposer[client];
if (!proposer)
{
PrintToChat(client, "%syou have no current proposals", gS_ChatStrings.sText);
return Plugin_Handled;
}
PrintToChat(client, "%syou're now married to %s%N%s <3", gS_ChatStrings.sText, gS_ChatStrings.sVariable, proposer, gS_ChatStrings.sStyle);
PrintToChat(proposer, "%syou're now married to %s%N%s <3", gS_ChatStrings.sText, gS_ChatStrings.sVariable, client, gS_ChatStrings.sStyle);
PrintToChatAll("%s%N%s and %s%N%s are now married!! ^w^", gS_ChatStrings.sVariable, proposer, gS_ChatStrings.sText, gS_ChatStrings.sVariable, client, gS_ChatStrings.sText);
char query[512];
FormatEx(query, sizeof(query),
"INSERT INTO couples (steamid, spouseid, points, timestamp) VALUES (%i, %i, %f, %i)",
GetSteamAccountID(proposer), GetSteamAccountID(client), 0.0, GetTime());
gB_Married[client] = true;
gB_Married[proposer] = true;
gI_Proposer[client] = 0; // clear our proposals too
gI_Proposer[proposer] = 0; // clear out any proposals they have because they're married too...
gI_Spouse[client] = GetSteamAccountID(proposer);
gI_Spouse[proposer] = GetSteamAccountID(client);
GetClientName(client, gS_Spouse[proposer], 32);
GetClientName(proposer, gS_Spouse[client], 32);
shavitdb.Query(SQL_InsertMarriage, query, GetClientSerial(client));
return Plugin_Handled;
}
public Action Command_Reject(int client, int args)
{
PrintToChat(gI_Proposer[client], "%syou've been rejected ;w;", gS_ChatStrings.sText);
PrintToChat(client, "%syou've rejected %s%N%s </3", gS_ChatStrings.sText, gS_ChatStrings.sVariable, gI_Proposer[client], gS_ChatStrings.sStyle);
gI_Proposer[client] = 0;
return Plugin_Handled;
}
public Action Command_Debug(int client, int args)
{
char stylestrings[64];
Shavit_GetStyleStrings(Shavit_GetBhopStyle(client), sSpecialString, stylestrings, sizeof(stylestrings));
PrintToChat(client, "ghjk: %i %i %i %i", gB_Queried[client], gB_Married[client], !Shavit_IsPracticeMode(client), StrContains(stylestrings, "segments", false) == -1);
return Plugin_Handled;
}
public void Shavit_OnFinish(int client, int style, float time, int jumps, int strafes, float sync, int track, float oldtime, float perfs, float avgvel, float maxvel, int timestamp)
{
char stylestrings[64];
Shavit_GetStyleStrings(style, sSpecialString, stylestrings, sizeof(stylestrings));
// PrintToChat(client, "%d %d %d %d %d", gB_Queried[client], gB_Married[client], !Shavit_IsPracticeMode(client), (StrContains(stylestrings, "segments", false) == -1), (oldtime == 0) ? true : (oldtime > time));
if (gB_Queried[client] && gB_Married[client] && !Shavit_IsPracticeMode(client) && StrContains(stylestrings, "segments", false) == -1 && (oldtime == 0) ? true : (oldtime > time))
{
char query[512], map[32];
float wr = (Shavit_GetWorldRecord(style, track) == 0.0) ? time : Shavit_GetWorldRecord(style, track);
GetCurrentMap(map, sizeof(map));
//PrintToChat(client, "%N %f", client, Shavit_GuessPointsForTime(track, style, Shavit_GetMapTier(map), time, wr));
FormatEx(query, sizeof(query),
"UPDATE couples SET points = points + %f where steamid = %i OR spouseid = %i",
Shavit_GuessPointsForTime(track, style, Shavit_GetMapTier(map), time, wr), GetSteamAccountID(client), GetSteamAccountID(client));
shavitdb.Query(SQL_UpdatePoints, query, GetClientSerial(client));
}
}
void SQL_GetSpouse(Database db, DBResultSet results, const char[] error, int serial)
{
if (results == null)
{
LogError("SQL_GetSpouse error: '%s'", error);
return;
}
int client = GetClientFromSerial(serial);
if (client < 1) return;
gB_Queried[client] = true;
if (results.FetchRow())
{
int a = results.FetchInt(0);
int b = results.FetchInt(1);
int spouseid = (a == GetSteamAccountID(client)) ? b : a;
gI_Spouse[client] = spouseid;
gB_Married[client] = true;
char namequery[512];
FormatEx(namequery, sizeof(namequery),
"SELECT auth, name FROM %susers WHERE auth = %d;",
gS_ShavitPrefix, spouseid);
shavitdb.Query(SQL_SpouseNameQuery, namequery, serial);
}
}
void SQL_SpouseNameQuery(Database db, DBResultSet results, const char[] error, int serial)
{
if (results == null)
{
LogError("SQL_SpouseNameQuery error: '%s'", error);
return;
}
int client = GetClientFromSerial(serial);
if (client < 1) return;
if (results.FetchRow())
{
int auth = results.FetchInt(0);
if (auth == gI_Spouse[client])
{
results.FetchString(1, gS_Spouse[client], 32);
}
}
}
void SQL_InsertMarriage(Database db, DBResultSet results, const char[] error, int serial)
{
if (results == null)
{
LogError("SQL_InsertMarriage error: '%s'", error);
return;
}
// fuck it, don't care to do anything other than log errors here
}
void SQL_UpdatePoints(Database db, DBResultSet results, const char[] error, int serial)
{
if (results == null)
{
LogError("SQL_UpdatePoints error: '%s'", error);
return;
}
PrintToChatAll("%s", error);
// fuck it, don't care to do anything other than log errors here
}
void SQL_Divorce(Database db, DBResultSet results, const char[] error, int serial)
{
if (results == null)
{
LogError("SQL_Divorce error: '%s'", error);
return;
}
// fuck it, don't care to do anything other than log errors here
}
void SQL_Couples(Database db, DBResultSet results, const char[] error, int serial)
{
if (results == null)
{
LogError("SQL_Couples error: '%s'", error);
return;
}
int client = GetClientFromSerial(serial);
if (client < 1) return;
Menu menu = new Menu(MenuHandler1, MENU_ACTIONS_ALL);
menu.SetTitle("Top couples ^w^");
while (results.FetchRow())
{
gI_ResultIndex++;
char result[128], name[32], name1[32], points[32], time[64];
results.FetchString(0, name, sizeof(name));
results.FetchString(1, name1, sizeof(name1));
results.FetchString(4, points, sizeof(points));
FormatTime(time, sizeof(time), "%x", results.FetchInt(5));
Format(result, sizeof(result), "#%i | %s & %s: %s points (%s)", gI_ResultIndex, name, name1, points, time);
menu.AddItem("", result, ITEMDRAW_RAWLINE);
}
menu.ExitButton = true;
menu.Display(client, 9999999999999999);
gI_ResultIndex = 0;
}
public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_End)
{
delete menu;
}
}