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