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