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