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