· 8 years ago · Jun 10, 2018, 08:32 PM
1/* Copyright © 2012, lucas_7_94
2
3 'MiniDuels!' is free software;
4 you can redistribute it and/or modify it under the terms of the
5 GNU General Public License as published by the Free Software Foundation.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with 'MiniDuels!'; if not, write to the
14 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
15 Boston, MA 02111-1307, USA.
16
17 ///////////////////////////////////////////////////////////////////////////////////
18
19 I want to send a greeting to a friend of this forum
20 that according to information, he died in an accident, L//, may he rest in peace.
21*/
22
23
24#include < amxmisc >
25#include < fakemeta_util >
26#include < cstrike >
27#include < sqlx >
28#include < hamsandwich >
29
30#pragma semicolon 1
31
32new bool:bPlayerDueling[ 33 ] , gPlayerTeam[ 33 ] ,CountOfKills[ 2 ], gDuelPlayers[ 33 ];
33new gDuelPlayerNames[ 2 ][ 33 ] , gMenuCallBack , gLastMapToSave[ 20 ] , szSteamID[ 2 ][ 33 ];
34
35new bool:gPlayerInTheDatabase[33] , gWinCount[ 33 ] , gLosesCount[ 33 ] , gLastPlayerPlayed[ 32 ][ 33 ];
36new gLastDayPlayed[ 32 ][ 33 ] , gLastMap[ 32 ][ 20 ] , gWinTheLastDuel[ 32 ][ 33 ], Handle:gSqlTuple;
37
38new szBuffer[ 512 ] , bool:WhoWins[ 2 ], gGlowPlayers[ 2 ], ParseColors[ 2 ][ 3 ];
39
40new gMotd[ 2048 ], len , k;
41
42new gTable[] = "duels";
43
44enum
45{
46 DUEL_SENDER,
47 DUEL_RECEIVER
48}
49
50public plugin_init( ) {
51
52 register_event("CurWeapon", "Event_CurWeapon_NotAKnife", "be", "1=1", "2!29")
53
54 static const szAuthor[ ] = "Luqqas";
55 static const szPluginName[ ] = "MiniDuels!";
56 static const szVersion[ ] = "1.0";
57
58 register_plugin( szPluginName, szVersion, szAuthor );
59
60 register_clcmd( "say /duel", "clcmd_duel" );
61
62 register_clcmd("amx_kick", "cmd_amx_cvar");
63
64 get_mapname( gLastMapToSave, charsmax( gLastMapToSave ) );
65
66 gMenuCallBack = menu_makecallback( "DuelPlayerEnabled" );
67
68 register_menu("Duel Stats", MENU_KEY_1, "Duel_Stats");
69
70 register_clcmd( "say /duelstats", "clcmd_duelstats" );
71
72 register_forward( FM_AddToFullPack , "func_AddToFullPack", 1 );
73
74 register_event( "DeathMsg" , "OnDeathMsg" , "a" );
75
76 register_event("TeamInfo", "join_spect", "a", "2=SPECTATOR" );
77
78 register_event( "30" , "event_intermission" , "a" );
79
80 RegisterHam(Ham_Spawn, "player", "PlayerSpawn", 1);
81
82 gGlowPlayers[ 0 ] = register_cvar( "dl_tt_glow", "255000000" );
83 gGlowPlayers[ 1 ] = register_cvar( "dl_ct_glow", "000000255" );
84
85 /* SQL Data */
86
87 static szHost[] = "";
88 static szUser[] = "";
89 static szPass[] = "";
90 static szDB[] = "";
91
92 gSqlTuple = SQL_MakeDbTuple( szHost, szUser, szPass, szDB );
93
94 /* END SQL Data */
95
96 register_cvar("dl_version", szVersion, FCVAR_SERVER|FCVAR_SPONLY);
97
98 // Check if the table exists!
99 set_task(2.0, "CheckTableIfExists");
100
101 // Multilang
102 register_dictionary( "MiniDuelsML.txt" );
103
104
105}
106
107public cmd_amx_cvar( id )
108{
109 if( access( id, ADMIN_ADMIN ) )
110 {
111 new get_kicked[ 32 ], playerindex, szName[ 32 ];
112 read_argv( 1, get_kicked, 31 );
113
114 new player = cmd_target( id, get_kicked ,9 );
115 if( !player )
116 return PLUGIN_HANDLED;
117
118 get_user_name( player, szName, 31 );
119 playerindex = get_user_index( szName );
120
121 if( bPlayerDueling[ playerindex ] ) // One of the dueler's kicked ... :(
122 {
123 client_print( 0 , print_chat, "%L", LANG_PLAYER, "MD_PLAYERKICKED", gDuelPlayerNames[ 0 ], gDuelPlayerNames[ 1 ]);
124 bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = false;
125 CountOfKills[ 0 ] = CountOfKills[ 1 ] = 0;
126 }
127
128 }
129 return PLUGIN_CONTINUE;
130}
131public client_putinserver( id )
132{
133 for( k = 0 ; k < 2 ; k++ )
134 gDuelPlayerNames[ k ][ id ] = EOS;
135
136 if( !is_user_bot( id ) )
137 CheckIfPlayerIsInDb( id );
138
139 gLastPlayerPlayed[ id ][ 0 ] = gLastDayPlayed[ id ][ 0 ] = gLastMap[ id ][ 0 ] = gWinTheLastDuel[ id ][ 0 ] = EOS;
140
141}
142
143public PlayerSpawn(id)
144{
145 if ( !is_user_alive( id ) )
146 return HAM_IGNORED;
147
148 if( bPlayerDueling[ id ] && ( cs_get_user_team( gDuelPlayers[ DUEL_SENDER ] ) == cs_get_user_team( gDuelPlayers[ DUEL_RECEIVER ] ) ) ) // possible bug ? ok , duel closed.
149 {
150 client_print( 0, print_chat, "%L", LANG_PLAYER, "MD_CANCELLED", gDuelPlayerNames[ 0 ] , gDuelPlayerNames[ 1 ]);
151
152 bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = false;
153 CountOfKills[ 0 ] = CountOfKills[ 1 ] = 0;
154 }
155 new color[10];
156
157 for( k = 0 ; k < 2 ; k++ )
158 {
159 get_pcvar_string( gGlowPlayers[ k ], color, 9);
160 new strtonum = str_to_num(color);
161 ParseColors[ k ][ 0 ] = str_to_num(color) / 1000000;
162 strtonum %= 1000000;
163 ParseColors[ k ][ 1 ] = strtonum / 1000;
164 ParseColors[ k ][ 2 ] = strtonum % 1000;
165 #pragma unused strtonum
166 }
167
168 return HAM_IGNORED;
169}
170
171public join_spect( )
172{
173 new id = read_data( 1 );
174
175 if( bPlayerDueling[ id ] )
176 {
177 client_print( 0, print_chat, "%L", LANG_PLAYER, "MD_CHANGETOSPECT", (gDuelPlayers[ DUEL_SENDER ] == id) ? gDuelPlayerNames[ 1 ] : gDuelPlayerNames[ 0 ] , (gDuelPlayers[ DUEL_RECEIVER ] == id) ? gDuelPlayerNames[ 1 ] : gDuelPlayerNames[ 0 ] );
178
179 WhoWins[ 0 ] = ( gDuelPlayers[ DUEL_SENDER ] == id ) ? false : true;
180 WhoWins[ 1 ] = ( gDuelPlayers[ DUEL_SENDER ] == id ) ? true : false;
181 Save_Db( WhoWins );
182
183 bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = false;
184 }
185
186}
187
188public event_intermission( )
189{
190 if( !bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] && !bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] ) return;
191
192 if( CountOfKills[ 0 ] == CountOfKills[ 1 ] )
193 client_print(0, print_chat, "%L", LANG_PLAYER, "MD_TIE", gDuelPlayerNames[ 0 ], gDuelPlayerNames[ 1 ]);
194 else
195 {
196 static result;
197 result = CountOfKills[ 0 ] > CountOfKills[ 1 ];
198 client_print(0, print_chat, "%L", LANG_PLAYER, "MD_WIN",
199 ( result ) ? gDuelPlayerNames[ 0 ] : gDuelPlayerNames[ 1 ],
200 ( result ) ? gDuelPlayerNames[ 1 ] : gDuelPlayerNames[ 0 ],
201 ( result ) ? CountOfKills[ 0 ] : CountOfKills[ 1 ],
202 ( result ) ? CountOfKills[ 1 ] : CountOfKills[ 0 ]);
203
204 WhoWins[ 0 ] = ( result ) ? true : false;
205 WhoWins[ 1 ] = ( result ) ? false : true;
206 Save_Db( WhoWins );
207 }
208}
209
210public OnDeathMsg()
211{
212 new killer = read_data( 1 );
213 new victim = read_data( 2 );
214
215 if ( !killer || killer == victim )
216 return;
217
218 if( bPlayerDueling[ killer ] && bPlayerDueling[ victim ] ) // DUEL HERE SIRS!
219 {
220 ( gDuelPlayers[ DUEL_SENDER ] == killer ) ? CountOfKills[ 0 ]++ : CountOfKills[ 1 ]++;
221 client_print( 0, print_chat, "%L", LANG_PLAYER, "MD_STATUSDUEL", gDuelPlayerNames[ 0 ], CountOfKills[ 0 ] , gDuelPlayerNames[ 1 ], CountOfKills[ 1 ] );
222 }
223
224}
225
226public client_disconnect( id )
227{
228 if( !bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] && !bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] )
229 return;
230
231 client_print( 0 , print_chat, "%L", LANG_PLAYER, "MD_PLAYERLEAVESERVER",
232 ( gDuelPlayers[ DUEL_SENDER ] == id) ? gDuelPlayerNames[1] : gDuelPlayerNames[0],
233 ( gDuelPlayers[ DUEL_SENDER ] == id) ? gDuelPlayerNames[0] : gDuelPlayerNames[1] );
234
235 WhoWins[ 0 ] = ( gDuelPlayers[ DUEL_SENDER ] == id ) ? false : true;
236 WhoWins[ 1 ] = ( gDuelPlayers[ DUEL_SENDER ] == id ) ? true : false;
237
238 Save_Db( WhoWins );
239
240 bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = false;
241
242 return;
243
244}
245
246public clcmd_duel( id )
247{
248 if( bPlayerDueling[ id ] )
249 {
250 client_print( id , print_chat, "%L" , id, "MD_INDUEL");
251 return PLUGIN_HANDLED;
252 }
253
254 if( cs_get_user_team( id ) == CS_TEAM_SPECTATOR || cs_get_user_team( id ) == CS_TEAM_UNASSIGNED )
255 return PLUGIN_HANDLED;
256
257 static title[250];
258 formatex( title , charsmax(title) , "%L", id, "MD_MENUTITLE" );
259
260 new menu = menu_create( title , "Duel_Handled" );
261
262 new players[ 32 ], pnum, tempid;
263
264 new szName[ 32 ], szTempid[ 10 ];
265 get_players( players, pnum );
266
267 for( new i ; i < pnum ; i++ )
268 {
269 tempid = players[ i ];
270
271 if( get_user_team( tempid ) == get_user_team( id ) || cs_get_user_team( tempid ) == CS_TEAM_SPECTATOR )
272 continue;
273
274
275 get_user_name( tempid, szName, charsmax( szName ) );
276 num_to_str( tempid, szTempid, charsmax( szTempid ) );
277 menu_additem( menu, szName, szTempid, 0 , gMenuCallBack );
278 }
279
280 menu_display( id, menu, 0 );
281 return PLUGIN_HANDLED;
282}
283
284public DuelPlayerEnabled(id, menu, item)
285{
286 new data[ 6 ], szName[ 64 ];
287 new access, callback;
288
289 menu_item_getinfo( menu, item, access, data,charsmax(data), szName,charsmax(szName), callback );
290
291 new tempid = str_to_num( data );
292
293 if( bPlayerDueling[ tempid ] )
294 return ITEM_DISABLED;
295
296 return ITEM_ENABLED;
297}
298
299public Duel_Handled(id, menu, item)
300{
301 if( item == MENU_EXIT )
302 {
303 menu_destroy(menu);
304 return PLUGIN_HANDLED;
305 }
306
307 new data[ 6 ], szName[ 64 ];
308 new access, callback;
309 menu_item_getinfo( menu, item, access, data,charsmax( data ), szName,charsmax( szName ), callback );
310
311 new tempid = str_to_num( data );
312
313 if( bPlayerDueling[ tempid ] )
314 {
315 client_print(id, print_chat, "%L", id , "MD_CANTINVITE");
316 clcmd_duel( id );
317 return PLUGIN_HANDLED;
318 }
319
320 gDuelPlayers[ DUEL_SENDER ] = id;
321 gDuelPlayers[ DUEL_RECEIVER ] = tempid;
322
323 get_user_name( gDuelPlayers[ DUEL_RECEIVER ], gDuelPlayerNames[ 1 ], charsmax( gDuelPlayerNames[ ] ) );
324 get_user_name( gDuelPlayers[ DUEL_SENDER ] , gDuelPlayerNames[ 0 ], charsmax( gDuelPlayerNames[ ] ) );
325
326 client_print( 0, print_chat, "%L", LANG_PLAYER, "MD_SENDINVITATION", gDuelPlayerNames[ 0 ] , gDuelPlayerNames[ 1 ]);
327
328 receive_menu_duel( gDuelPlayers[ DUEL_RECEIVER ] );
329
330 return PLUGIN_HANDLED;
331
332}
333
334receive_menu_duel( const Receiver )
335{
336 static buffer[ 65 ], szOptions[ 2 ][ 100 ];
337 formatex( buffer, sizeof( buffer ) - 1 , "%L", Receiver, "MD_RECEIVEINVITATION", gDuelPlayerNames[ 0 ] ) ;
338
339 new menu = menu_create( buffer , "Receive_Handled");
340
341 formatex( szOptions[ 0 ] , charsmax( szOptions[ ] ), "%L", Receiver, "MD_ACCEPTDUEL" );
342 formatex( szOptions[ 1 ] , charsmax( szOptions[ ] ), "%L", Receiver, "MD_CANCELDUEL" );
343
344 menu_additem( menu, szOptions[ 0 ], "1", 0 );
345 menu_additem( menu, szOptions[ 1 ], "2", 0 );
346
347 menu_setprop( menu, MPROP_EXIT, MEXIT_NEVER );
348
349 menu_display( Receiver , menu, 0 );
350
351 return;
352
353}
354public Receive_Handled(id, menu, item)
355{
356 new data[ 6 ], szName[ 64 ];
357 new access, callback;
358
359 menu_item_getinfo( menu, item, access, data,charsmax(data), szName,charsmax(szName), callback );
360
361 new key = str_to_num( data );
362
363 if( bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] )
364 {
365 client_print(id, print_chat, "%L", id , "MD_CANTINVITE" );
366 return PLUGIN_HANDLED;
367 }
368
369 switch(key)
370 {
371 case 1:
372 {
373 client_print( 0 , print_chat, "%L", LANG_PLAYER, "MD_DUELACCEPTED", gDuelPlayerNames[ 0 ], gDuelPlayerNames[ 1 ] );
374 bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = true;
375 gPlayerTeam[ gDuelPlayers[ DUEL_SENDER ] ] = _:cs_get_user_team( gDuelPlayers[ DUEL_SENDER ] );
376 gPlayerTeam[ gDuelPlayers[ DUEL_RECEIVER ] ] = _:cs_get_user_team( gDuelPlayers[ DUEL_RECEIVER ] );
377 get_user_authid( gDuelPlayers[ DUEL_SENDER ], szSteamID[ 0 ] , 32 );
378 get_user_authid( gDuelPlayers[ DUEL_RECEIVER ], szSteamID[ 1 ] , 32 );
379
380 }
381 case 2:
382 {
383 client_print( 0 , print_chat, "%L", LANG_PLAYER, "MD_DUELCANCELLED", gDuelPlayerNames[ 1 ], gDuelPlayerNames[ 0 ] );
384 gDuelPlayers[DUEL_SENDER] = gDuelPlayers[id] = EOS;
385 }
386 }
387
388 menu_destroy(menu);
389 return PLUGIN_HANDLED;
390}
391
392
393public func_AddToFullPack(es, e, ent, host, hostflags, player, pSet)
394{
395 if( !player || !pev_valid( ent ) || !get_orig_retval( ) || host == ent )
396 return FMRES_IGNORED;
397
398 if( bPlayerDueling[ host ] && bPlayerDueling[ ent ] )
399 {
400 set_es( es , ES_RenderFx, kRenderFxGlowShell );
401 switch( gPlayerTeam[ host ] )
402 {
403 case CS_TEAM_T:set_es( es , ES_RenderColor, ParseColors[ 0 ][ 0 ], ParseColors[ 0 ][ 1 ] , ParseColors[ 0 ][ 0 ] );
404 case CS_TEAM_CT:set_es( es , ES_RenderColor, ParseColors[ 1 ][ 0 ], ParseColors[ 1 ][ 1 ] , ParseColors[ 1 ][ 0 ] );
405
406
407 }
408 switch( gPlayerTeam[ ent ] )
409 {
410 case CS_TEAM_T:set_es( es , ES_RenderColor, ParseColors[ 0 ][ 0 ], ParseColors[ 0 ][ 1 ] , ParseColors[ 0 ][ 0 ] );
411 case CS_TEAM_CT:set_es( es , ES_RenderColor, ParseColors[ 1 ][ 0 ], ParseColors[ 1 ][ 1 ] , ParseColors[ 1 ][ 0 ] );
412 }
413 set_es( es , ES_RenderAmt, 25 );
414 }
415 return FMRES_IGNORED;
416}
417
418CheckIfPlayerIsInDb( id )
419{
420 static iData[ 1 ];
421
422 static szSteamid[33];
423 get_user_authid( id , szSteamid , 32 );
424
425 szBuffer[ 0 ] = EOS ;
426
427 formatex( szBuffer , 511 , "SELECT * FROM %s WHERE steam = '%s'", gTable, szSteamid );
428
429 iData[ 0 ] = id ;
430
431 SQL_ThreadQuery( gSqlTuple, "CheckPlayer", szBuffer , iData, 1 );
432}
433
434public CheckPlayer( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
435{
436 if( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )
437 {
438 log_amx( "%s", Error );
439 return;
440 }
441 else
442 {
443 new id = Data[ 0 ];
444
445 if( SQL_NumResults( Query ) < 1 )
446 {
447 gPlayerInTheDatabase[ id ] = false;
448 }
449 else
450 {
451 gPlayerInTheDatabase[ id ] = true;
452 SQL_ReadResult( Query, 2 , gLastPlayerPlayed[ id ] , charsmax( gLastPlayerPlayed[ ] ));
453 SQL_ReadResult( Query, 3 , gWinTheLastDuel[ id ] , charsmax( gWinTheLastDuel[ ] ) );
454 SQL_ReadResult( Query, 4 , gLastMap[ id ] , charsmax( gLastMap[ ] ));
455 SQL_ReadResult( Query, 5 , gLastDayPlayed[ id ] , charsmax( gLastDayPlayed[ ] ));
456 gWinCount[ id ] = SQL_ReadResult( Query, 6 );
457 gLosesCount[ id ] = SQL_ReadResult( Query, 7 );
458 }
459
460 }
461}
462
463public clcmd_duelstats( id )
464{
465 static szTitle[ 90 ];
466 formatex( szTitle, charsmax( szTitle ) , "%L", id, "MD_STATSTITLE2" );
467 new menu = menu_create( szTitle, "DuelStats_Handled" );
468
469 new players[ 32 ], pnum, tempid;
470
471 new szName[ 32 ], szTempid[ 10 ];
472 get_players( players, pnum );
473
474 for( new i ; i < pnum ; i++ )
475 {
476 tempid = players[ i ];
477
478 get_user_name( tempid, szName, charsmax( szName ) );
479 num_to_str( tempid, szTempid, charsmax( szTempid ) );
480 menu_additem( menu, szName, szTempid );
481 }
482
483 menu_display( id, menu, 0 );
484}
485
486public DuelStats_Handled(id, menu, item)
487{
488 if( item == MENU_EXIT )
489 {
490 menu_destroy(menu);
491 return PLUGIN_HANDLED;
492 }
493
494 new data[ 6 ], szName[ 64 ];
495 new access, callback;
496 menu_item_getinfo( menu, item, access, data,charsmax( data ), szName,charsmax( szName ), callback );
497
498 new tempid = str_to_num( data );
499
500 get_user_name( tempid, szName, charsmax( szName ) );
501
502 look_menu_stats( id , tempid , szName , "Duel Stats" );
503
504 return PLUGIN_HANDLED;
505
506}
507 // my id , idplayer , nameplayer , menutittle
508look_menu_stats( id , playertolook, const szPlayerName[] = "" , const MenuTitle[] = "" )
509{
510 static menu[ 512 ], len;
511 len = 0;
512
513 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n^n", id, "MD_STATSTITLE", szPlayerName );
514
515 if( !gPlayerInTheDatabase[ playertolook ] )
516 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n^n", id, "MD_NOSTATSFOUNDED" );
517 else
518 {
519 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_LASTPLAYERPLAYED", gLastPlayerPlayed[ playertolook ] );
520 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_WINLASTDUEL", id, gWinTheLastDuel[ playertolook ][ 0 ] == 'Y' ? "MD_YES" : "MD_NO");
521 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_LASTMAPPLAYED", gLastMap[ playertolook ] );
522 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_LASTDAYPLAYED", gLastDayPlayed[ playertolook ] );
523 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_WINCOUNT", gWinCount[ playertolook ] );
524 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n^n", id, "MD_LOSESCOUNT", gLosesCount[ playertolook ] );
525 }
526 len += formatex( menu[ len ], charsmax( menu ) - len, "\r1.%L^n", id, "MD_EXIT");
527 show_menu( id, MENU_KEY_1, menu, -1, MenuTitle );
528}
529
530public Duel_Stats( id, key )
531{
532 return PLUGIN_HANDLED;
533}
534
535public CheckTableIfExists()
536{
537 szBuffer[ 0 ] = EOS;
538
539 formatex( szBuffer, charsmax( szBuffer ) , "CREATE TABLE IF NOT EXISTS duels (`steam` VARCHAR(32) NOT NULL, `name` VARCHAR(32) NOT NULL, `LastPlayerPlayed` VARCHAR(32) NOT NULL, `WinLastGame` VARCHAR(32) NOT NULL, `LastMapPlayedInDuel` VARCHAR(32) NOT NULL, `LastDayPlayedDuel` VARCHAR(32) NOT NULL, `WinCount` INT(10) NOT NULL, `LosesCount` INT(10) NOT NULL, PRIMARY KEY (`steam`))");
540
541 SQL_ThreadQuery( gSqlTuple, "CreateTableHandle", szBuffer );
542}
543
544public CreateTableHandle( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
545{
546 if( FailState )
547 {
548 log_amx( "SQL Error: %s (%d)", Error, Errcode );
549 return PLUGIN_HANDLED;
550 }
551
552 szBuffer[ 0 ] = EOS;
553
554 formatex( szBuffer, charsmax( szBuffer ), "SELECT * FROM `%s` ORDER BY WinCount DESC, LosesCount DESC LIMIT 15;", gTable );
555
556 SQL_ThreadQuery( gSqlTuple, "duel_top", szBuffer );
557 return PLUGIN_CONTINUE;
558}
559
560public duel_top( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
561{
562 if( FailState )
563 {
564 log_amx( "SQL Error: %s (%d)", Error, Errcode );
565 return PLUGIN_HANDLED;
566 }
567
568 if( SQL_NumResults( Query ) > 1 )
569 {
570 register_clcmd( "say /topduels" , "clcmd_topduels" );
571
572 new Name[ 64 ], steam[ 64 ];
573
574 k = 0;
575
576 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<meta charset=UTF-8><style>body{color:#FFFFFF;background-color:black;margin-top:5;font-family:arial}table{border-collapse:separate;border-spacing:1px;text-align:left;}" );
577 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "td{font-size:15px;}</style>" );
578 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<table border=1 width=700>" );
579 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "%s","<br><tr bgcolor=##ffffff><td> #<td> Name<td> Steam<td>Win Count<td>Loses Count</tr>");
580
581 new isteam = SQL_FieldNameToNum( Query, "steam" );
582 new iname = SQL_FieldNameToNum( Query, "name" );
583 new iwincount = SQL_FieldNameToNum( Query, "WinCount" );
584 new ilosescount = SQL_FieldNameToNum( Query, "LosesCount" );
585
586
587 while ( SQL_MoreResults( Query ) )
588 {
589 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "%s%d", (++k != 1) ? "<tr><td>" : "<tr bgcolor=#00ff00><td>", k);
590
591 SQL_ReadResult(Query, iname, Name, charsmax(Name));
592 SQL_ReadResult(Query, isteam, steam, charsmax(steam));
593
594 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<td>%-22.22s", Name );
595 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<td>%-22.22s", steam );
596 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<td>%d", SQL_ReadResult( Query, iwincount ) );
597 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<td>%d", SQL_ReadResult( Query, ilosescount ) );
598
599 SQL_NextRow( Query );
600 }
601
602 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "</table></font>" );
603
604 }
605
606 return PLUGIN_HANDLED;
607
608}
609
610public clcmd_topduels( id ) show_motd( id, gMotd , "Duel Stats!" );
611
612Save_Db( const Winner[] )
613{
614 static Player1, Player2;
615 Player1 = gDuelPlayers[ DUEL_SENDER ];
616 Player2 = gDuelPlayers[ DUEL_RECEIVER ]; // index of players
617
618 static Query[ 2 ][ 1024 ], gTime[18];
619 get_time( "%c", gTime , 17 );
620
621 static k;
622 for( k = 0 ; k < 2 ; k++ )
623 {
624 replace_all( gDuelPlayerNames[ k ], charsmax( gDuelPlayerNames[ ] ), "`", "" );
625 replace_all( gDuelPlayerNames[ k ], charsmax( gDuelPlayerNames[ ] ), "'", "''" );
626
627 formatex( Query[ ( !k ) ? 0 : 1 ] , sizeof( Query[ ] ) , "%s %s SET `steam` = '%s' , `name` = '%s' , `LastPlayerPlayed` = '%s', `LastDayPlayedDuel` = '%s', `WinLastGame` = '%s', `LastmapPlayedInDuel` = '%s', `WinCount` = %s, `LosesCount` = %s",
628 (gPlayerInTheDatabase[ ( !k ) ? Player1 : Player2 ]) ? "UPDATE" : "INSERT INTO" ,gTable, szSteamID[ ( !k ) ? 0 : 1 ], gDuelPlayerNames[ ( !k ) ? 0 : 1 ], gDuelPlayerNames[ ( !k ) ? 1 : 0 ], gTime, (Winner[ ( !k ) ? 0 : 1 ] ) ? "Yes" : "No" , gLastMapToSave, (Winner[ ( !k ) ? 0 : 1 ] ) ? "`WinCount` + 1" : "`WinCount`" , (Winner[ ( !k ) ? 0 : 1 ] ) ? "`LosesCount`" : "`LosesCount` + 1");
629
630 if( gPlayerInTheDatabase[ ( !k ) ? Player1 : Player2 ] )
631 {
632 static AddBuffer[ 512 ];
633 formatex( AddBuffer , charsmax( AddBuffer ), " WHERE steam = '%s'", szSteamID[ (!k ) ? 0 : 1 ] );
634 add( Query[ ( !k ) ? 0 : 1 ] , charsmax( Query[ ] ), AddBuffer );
635 }
636
637 gPlayerInTheDatabase[ (!k) ? Player1 : Player2 ] = true;
638 CountOfKills[ k ] = 0;
639 SQL_ThreadQuery( gSqlTuple, "SaveHandled", Query[ k ] );
640 }
641}
642
643public SaveHandled( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
644{
645 if( FailState )
646 {
647 log_amx( "SQL Error: %s (%d)", Error, Errcode );
648 return PLUGIN_HANDLED;
649 }
650
651 return PLUGIN_CONTINUE;
652}
653
654public plugin_end()
655 SQL_FreeHandle( gSqlTuple );
656 public Event_CurWeapon_NotAKnife( id )
657{
658 if( read_data(CurWeapon_WeaponID) != CSW_C4 && bPlayerDueling[ id ] )
659 {
660 engclient_cmd(id, "weapon_knife")
661 }
662}