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