· 8 years ago · Jun 11, 2018, 08:46 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 static const m_pActiveItem = 373;
234 static iActiveItem;
235
236 iActiveItem = get_pdata_cbase( iPlayer , m_pActiveItem , 5 );
237
238 if( iActiveItem > 0 )
239 {
240 client_cmd( iPlayer , "slot1;wait;wait;wait;+attack;wait;-attack" )
241 }
242
243 }
244
245 bPlayerDueling[ victim ] = false
246 bPlayerDueling[ killer ] = false
247}
248
249public client_disconnect( id )
250{
251 if( !bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] && !bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] )
252 return;
253
254 if( id == gDuelPlayers[ DUEL_SENDER ] || id == gDuelPlayers[ DUEL_RECEIVER ] )
255 {
256 bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = false
257 bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = false
258 }
259
260 client_print( 0 , print_chat, "%L", LANG_PLAYER, "MD_PLAYERLEAVESERVER",
261 ( gDuelPlayers[ DUEL_SENDER ] == id) ? gDuelPlayerNames[1] : gDuelPlayerNames[0],
262 ( gDuelPlayers[ DUEL_SENDER ] == id) ? gDuelPlayerNames[0] : gDuelPlayerNames[1] );
263
264 WhoWins[ 0 ] = ( gDuelPlayers[ DUEL_SENDER ] == id ) ? false : true;
265 WhoWins[ 1 ] = ( gDuelPlayers[ DUEL_SENDER ] == id ) ? true : false;
266
267 Save_Db( WhoWins );
268
269 return;
270}
271
272public clcmd_duel( id )
273{
274 if( !is_user_alive( id ) )
275 return PLUGIN_HANDLED
276
277 if( bPlayerDueling[ id ] )
278 {
279 client_print( id , print_chat, "%L" , id, "MD_INDUEL");
280 return PLUGIN_HANDLED;
281 }
282
283 if( cs_get_user_team( id ) == CS_TEAM_SPECTATOR || cs_get_user_team( id ) == CS_TEAM_UNASSIGNED )
284 return PLUGIN_HANDLED;
285
286 static title[250];
287 formatex( title , charsmax(title) , "%L", id, "MD_MENUTITLE" );
288
289 new menu = menu_create( title , "Duel_Handled" );
290
291 new players[ 32 ], pnum, tempid;
292
293 new szName[ 32 ], szTempid[ 10 ];
294 get_players( players, pnum );
295
296 for( new i ; i < pnum ; i++ )
297 {
298 tempid = players[ i ];
299
300 if( get_user_team( tempid ) == get_user_team( id ) || cs_get_user_team( tempid ) == CS_TEAM_SPECTATOR )
301 continue;
302
303
304 get_user_name( tempid, szName, charsmax( szName ) );
305 num_to_str( tempid, szTempid, charsmax( szTempid ) );
306 menu_additem( menu, szName, szTempid, 0 , gMenuCallBack );
307 }
308
309 menu_display( id, menu, 0 );
310
311 return PLUGIN_HANDLED
312}
313
314public DuelPlayerEnabled(id, menu, item)
315{
316 new data[ 6 ], szName[ 64 ];
317 new access, callback;
318
319 menu_item_getinfo( menu, item, access, data,charsmax(data), szName,charsmax(szName), callback );
320
321 new tempid = str_to_num( data );
322
323 if( bPlayerDueling[ tempid ] )
324 return ITEM_DISABLED;
325
326 return ITEM_ENABLED;
327}
328
329public Duel_Handled(id, menu, item)
330{
331 if( item == MENU_EXIT )
332 {
333 menu_destroy(menu);
334 return PLUGIN_HANDLED;
335 }
336
337 new data[ 6 ], szName[ 64 ];
338 new access, callback;
339 menu_item_getinfo( menu, item, access, data,charsmax( data ), szName,charsmax( szName ), callback );
340
341 new tempid = str_to_num( data );
342
343 if( bPlayerDueling[ tempid ] )
344 {
345 client_print(id, print_chat, "%L", id , "MD_CANTINVITE");
346 clcmd_duel( id );
347 return PLUGIN_HANDLED;
348 }
349
350 gDuelPlayers[ DUEL_SENDER ] = id;
351 gDuelPlayers[ DUEL_RECEIVER ] = tempid;
352
353 get_user_name( gDuelPlayers[ DUEL_RECEIVER ], gDuelPlayerNames[ 1 ], charsmax( gDuelPlayerNames[ ] ) );
354 get_user_name( gDuelPlayers[ DUEL_SENDER ] , gDuelPlayerNames[ 0 ], charsmax( gDuelPlayerNames[ ] ) );
355
356 client_print( 0, print_chat, "%L", LANG_PLAYER, "MD_SENDINVITATION", gDuelPlayerNames[ 0 ] , gDuelPlayerNames[ 1 ]);
357
358 receive_menu_duel( gDuelPlayers[ DUEL_RECEIVER ] );
359
360 return PLUGIN_HANDLED;
361
362}
363
364receive_menu_duel( const Receiver )
365{
366 static buffer[ 65 ], szOptions[ 2 ][ 100 ];
367 formatex( buffer, sizeof( buffer ) - 1 , "%L", Receiver, "MD_RECEIVEINVITATION", gDuelPlayerNames[ 0 ] ) ;
368
369 new menu = menu_create( buffer , "Receive_Handled");
370
371 formatex( szOptions[ 0 ] , charsmax( szOptions[ ] ), "%L", Receiver, "MD_ACCEPTDUEL" );
372 formatex( szOptions[ 1 ] , charsmax( szOptions[ ] ), "%L", Receiver, "MD_CANCELDUEL" );
373
374 menu_additem( menu, szOptions[ 0 ], "1", 0 );
375 menu_additem( menu, szOptions[ 1 ], "2", 0 );
376
377 menu_setprop( menu, MPROP_EXIT, MEXIT_NEVER );
378
379 menu_display( Receiver , menu, 0 );
380
381 return;
382
383}
384public Receive_Handled(id, menu, item)
385{
386 new data[ 6 ], szName[ 64 ];
387 new access, callback;
388
389 menu_item_getinfo( menu, item, access, data,charsmax(data), szName,charsmax(szName), callback );
390
391 new key = str_to_num( data );
392
393 if( bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] )
394 {
395 client_print(id, print_chat, "%L", id , "MD_CANTINVITE" );
396 return PLUGIN_HANDLED;
397 }
398
399 switch(key)
400 {
401 case 1:
402 {
403 client_print( 0 , print_chat, "%L", LANG_PLAYER, "MD_DUELACCEPTED", gDuelPlayerNames[ 0 ], gDuelPlayerNames[ 1 ] );
404 bPlayerDueling[ gDuelPlayers[ DUEL_SENDER ] ] = bPlayerDueling[ gDuelPlayers[ DUEL_RECEIVER ] ] = true;
405 gPlayerTeam[ gDuelPlayers[ DUEL_SENDER ] ] = _:cs_get_user_team( gDuelPlayers[ DUEL_SENDER ] );
406 gPlayerTeam[ gDuelPlayers[ DUEL_RECEIVER ] ] = _:cs_get_user_team( gDuelPlayers[ DUEL_RECEIVER ] );
407 get_user_authid( gDuelPlayers[ DUEL_SENDER ], szSteamID[ 0 ] , 32 );
408 get_user_authid( gDuelPlayers[ DUEL_RECEIVER ], szSteamID[ 1 ] , 32 );
409
410 tkdmg[ gDuelPlayers[ DUEL_SENDER ] ] = gDuelPlayers[ DUEL_RECEIVER ]
411 tkdmg[ gDuelPlayers[ DUEL_RECEIVER ] ] = gDuelPlayers[ DUEL_SENDER ]
412
413 engclient_cmd( gDuelPlayers[ DUEL_SENDER ] , "weapon_knife" )
414 engclient_cmd( gDuelPlayers[ DUEL_RECEIVER ] , "weapon_knife" )
415 }
416 case 2:
417 {
418 client_print( 0 , print_chat, "%L", LANG_PLAYER, "MD_DUELCANCELLED", gDuelPlayerNames[ 1 ], gDuelPlayerNames[ 0 ] );
419 gDuelPlayers[DUEL_SENDER] = gDuelPlayers[id] = EOS;
420 }
421 }
422
423 menu_destroy(menu);
424 return PLUGIN_HANDLED;
425}
426
427
428public func_AddToFullPack(es, e, ent, host, hostflags, player, pSet)
429{
430 if( !player || !pev_valid( ent ) || !get_orig_retval( ) || host == ent )
431 return FMRES_IGNORED;
432
433 if( bPlayerDueling[ host ] && bPlayerDueling[ ent ] )
434 {
435 set_es( es , ES_RenderFx, kRenderFxGlowShell );
436 switch( gPlayerTeam[ host ] )
437 {
438 case CS_TEAM_T:set_es( es , ES_RenderColor, ParseColors[ 0 ][ 0 ], ParseColors[ 0 ][ 1 ] , ParseColors[ 0 ][ 0 ] );
439 case CS_TEAM_CT:set_es( es , ES_RenderColor, ParseColors[ 1 ][ 0 ], ParseColors[ 1 ][ 1 ] , ParseColors[ 1 ][ 0 ] );
440
441
442 }
443 switch( gPlayerTeam[ ent ] )
444 {
445 case CS_TEAM_T:set_es( es , ES_RenderColor, ParseColors[ 0 ][ 0 ], ParseColors[ 0 ][ 1 ] , ParseColors[ 0 ][ 0 ] );
446 case CS_TEAM_CT:set_es( es , ES_RenderColor, ParseColors[ 1 ][ 0 ], ParseColors[ 1 ][ 1 ] , ParseColors[ 1 ][ 0 ] );
447 }
448 set_es( es , ES_RenderAmt, get_pcvar_num( opacite ) );
449 }
450 return FMRES_IGNORED;
451}
452
453CheckIfPlayerIsInDb( id )
454{
455 static iData[ 1 ];
456
457 static szSteamid[33];
458 get_user_authid( id , szSteamid , 32 );
459
460 szBuffer[ 0 ] = EOS ;
461
462 formatex( szBuffer , 511 , "SELECT * FROM %s WHERE steam = '%s'", gTable, szSteamid );
463
464 iData[ 0 ] = id ;
465
466 SQL_ThreadQuery( gSqlTuple, "CheckPlayer", szBuffer , iData, 1 );
467}
468
469public CheckPlayer( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
470{
471 if( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )
472 {
473 log_amx( "%s", Error );
474 return;
475 }
476 else
477 {
478 new id = Data[ 0 ];
479
480 if( SQL_NumResults( Query ) < 1 )
481 {
482 gPlayerInTheDatabase[ id ] = false;
483 }
484 else
485 {
486 gPlayerInTheDatabase[ id ] = true;
487 SQL_ReadResult( Query, 2 , gLastPlayerPlayed[ id ] , charsmax( gLastPlayerPlayed[ ] ));
488 SQL_ReadResult( Query, 3 , gWinTheLastDuel[ id ] , charsmax( gWinTheLastDuel[ ] ) );
489 SQL_ReadResult( Query, 4 , gLastMap[ id ] , charsmax( gLastMap[ ] ));
490 SQL_ReadResult( Query, 5 , gLastDayPlayed[ id ] , charsmax( gLastDayPlayed[ ] ));
491 gWinCount[ id ] = SQL_ReadResult( Query, 6 );
492 gLosesCount[ id ] = SQL_ReadResult( Query, 7 );
493 }
494
495 }
496}
497
498public clcmd_duelstats( id )
499{
500 static szTitle[ 90 ];
501 formatex( szTitle, charsmax( szTitle ) , "%L", id, "MD_STATSTITLE2" );
502 new menu = menu_create( szTitle, "DuelStats_Handled" );
503
504 new players[ 32 ], pnum, tempid;
505
506 new szName[ 32 ], szTempid[ 10 ];
507 get_players( players, pnum );
508
509 for( new i ; i < pnum ; i++ )
510 {
511 tempid = players[ i ];
512
513 get_user_name( tempid, szName, charsmax( szName ) );
514 num_to_str( tempid, szTempid, charsmax( szTempid ) );
515 menu_additem( menu, szName, szTempid );
516 }
517
518 menu_display( id, menu, 0 );
519}
520
521public DuelStats_Handled(id, menu, item)
522{
523 if( item == MENU_EXIT )
524 {
525 menu_destroy(menu);
526 return PLUGIN_HANDLED;
527 }
528
529 new data[ 6 ], szName[ 64 ];
530 new access, callback;
531 menu_item_getinfo( menu, item, access, data,charsmax( data ), szName,charsmax( szName ), callback );
532
533 new tempid = str_to_num( data );
534
535 get_user_name( tempid, szName, charsmax( szName ) );
536
537 look_menu_stats( id , tempid , szName , "Duel Stats" );
538
539 return PLUGIN_HANDLED;
540
541}
542 // my id , idplayer , nameplayer , menutittle
543look_menu_stats( id , playertolook, const szPlayerName[] = "" , const MenuTitle[] = "" )
544{
545 static menu[ 512 ], len;
546 len = 0;
547
548 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n^n", id, "MD_STATSTITLE", szPlayerName );
549
550 if( !gPlayerInTheDatabase[ playertolook ] )
551 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n^n", id, "MD_NOSTATSFOUNDED" );
552 else
553 {
554 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_LASTPLAYERPLAYED", gLastPlayerPlayed[ playertolook ] );
555 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_WINLASTDUEL", id, gWinTheLastDuel[ playertolook ][ 0 ] == 'Y' ? "MD_YES" : "MD_NO");
556 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_LASTMAPPLAYED", gLastMap[ playertolook ] );
557 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_LASTDAYPLAYED", gLastDayPlayed[ playertolook ] );
558 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n", id, "MD_WINCOUNT", gWinCount[ playertolook ] );
559 len += formatex( menu[ len ], charsmax( menu ) - len, "%L^n^n", id, "MD_LOSESCOUNT", gLosesCount[ playertolook ] );
560 }
561 len += formatex( menu[ len ], charsmax( menu ) - len, "\r1.%L^n", id, "MD_EXIT");
562 show_menu( id, MENU_KEY_1, menu, -1, MenuTitle );
563}
564
565public Duel_Stats( id, key )
566{
567 return PLUGIN_HANDLED;
568}
569
570public CheckTableIfExists()
571{
572 szBuffer[ 0 ] = EOS;
573
574 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`))");
575
576 SQL_ThreadQuery( gSqlTuple, "CreateTableHandle", szBuffer );
577}
578
579public CreateTableHandle( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
580{
581 if( FailState )
582 {
583 log_amx( "SQL Error: %s (%d)", Error, Errcode );
584 return PLUGIN_HANDLED;
585 }
586
587 szBuffer[ 0 ] = EOS;
588
589 formatex( szBuffer, charsmax( szBuffer ), "SELECT * FROM `%s` ORDER BY WinCount DESC, LosesCount DESC LIMIT 15;", gTable );
590
591 SQL_ThreadQuery( gSqlTuple, "duel_top", szBuffer );
592 return PLUGIN_CONTINUE;
593}
594
595public duel_top( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
596{
597 if( FailState )
598 {
599 log_amx( "SQL Error: %s (%d)", Error, Errcode );
600 return PLUGIN_HANDLED;
601 }
602
603 if( SQL_NumResults( Query ) > 1 )
604 {
605 register_clcmd( "say /topduels" , "clcmd_topduels" );
606
607 new Name[ 64 ], steam[ 64 ];
608
609 k = 0;
610
611 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;}" );
612 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "td{font-size:15px;}</style>" );
613 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<table border=1 width=700>" );
614 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "%s","<br><tr bgcolor=##ffffff><td> #<td> Name<td> Steam<td>Win Count<td>Loses Count</tr>");
615
616 new isteam = SQL_FieldNameToNum( Query, "steam" );
617 new iname = SQL_FieldNameToNum( Query, "name" );
618 new iwincount = SQL_FieldNameToNum( Query, "WinCount" );
619 new ilosescount = SQL_FieldNameToNum( Query, "LosesCount" );
620
621
622 while ( SQL_MoreResults( Query ) )
623 {
624 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "%s%d", (++k != 1) ? "<tr><td>" : "<tr bgcolor=#00ff00><td>", k);
625
626 SQL_ReadResult(Query, iname, Name, charsmax(Name));
627 SQL_ReadResult(Query, isteam, steam, charsmax(steam));
628
629 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<td>%-22.22s", Name );
630 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<td>%-22.22s", steam );
631 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<td>%d", SQL_ReadResult( Query, iwincount ) );
632 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "<td>%d", SQL_ReadResult( Query, ilosescount ) );
633
634 SQL_NextRow( Query );
635 }
636
637 len += formatex( gMotd[ len ], charsmax( gMotd ) - len, "</table></font>" );
638
639 }
640
641 return PLUGIN_HANDLED;
642
643}
644
645public clcmd_topduels( id ) show_motd( id, gMotd , "Duel Stats!" );
646
647Save_Db( const Winner[] )
648{
649 static Player1, Player2;
650 Player1 = gDuelPlayers[ DUEL_SENDER ];
651 Player2 = gDuelPlayers[ DUEL_RECEIVER ]; // index of players
652
653 static Query[ 2 ][ 1024 ], gTime[18];
654 get_time( "%c", gTime , 17 );
655
656 static k;
657 for( k = 0 ; k < 2 ; k++ )
658 {
659 replace_all( gDuelPlayerNames[ k ], charsmax( gDuelPlayerNames[ ] ), "`", "" );
660 replace_all( gDuelPlayerNames[ k ], charsmax( gDuelPlayerNames[ ] ), "'", "''" );
661
662 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",
663 (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");
664
665 if( gPlayerInTheDatabase[ ( !k ) ? Player1 : Player2 ] )
666 {
667 static AddBuffer[ 512 ];
668 formatex( AddBuffer , charsmax( AddBuffer ), " WHERE steam = '%s'", szSteamID[ (!k ) ? 0 : 1 ] );
669 add( Query[ ( !k ) ? 0 : 1 ] , charsmax( Query[ ] ), AddBuffer );
670 }
671
672 gPlayerInTheDatabase[ (!k) ? Player1 : Player2 ] = true;
673 CountOfKills[ k ] = 0;
674 SQL_ThreadQuery( gSqlTuple, "SaveHandled", Query[ k ] );
675 }
676}
677
678public SaveHandled( FailState, Handle:Query, Error[ ], Errcode, Data[ ], DataSize )
679{
680 if( FailState )
681 {
682 log_amx( "SQL Error: %s (%d)", Error, Errcode );
683 return PLUGIN_HANDLED;
684 }
685
686 return PLUGIN_CONTINUE;
687}
688
689public plugin_end()
690 SQL_FreeHandle( gSqlTuple );
691
692public Event_CurWeapon( id )
693{
694 if( bPlayerDueling[ id ] )
695 {
696 engclient_cmd(id, "weapon_knife")
697 }
698}