· 9 years ago · Oct 03, 2016, 06:42 PM
1#include <amxmodx>
2#include <amxmisc>
3#include <colorchat>
4#include <cstrike>
5#include <hamsandwich>
6#include <fakemeta>
7#include <engine>
8#include <sqlx>
9
10#pragma semicolon 1
11
12#define USE_CONFIG_FILE 1
13#define UPDATE_INTERVAL 1.0
14#define NEEDED_ACCESS ADMIN_RCON
15
16enum _:PlData {
17 gLoaded,
18 gAuthed,
19 gLifes,
20 gIncreaseLifes,
21 gVip
22}
23enum PluginCvars {
24 PREFIX,
25 GIVE,
26 LIFE,
27 RESPAWN,
28 MYLIFE,
29 PRUNE,
30 MAX_LIFE,
31 KILL_MESSAGE,
32 VIP_FLAG
33}
34enum LifeAwardCvars {
35 KILL,
36 HEADSHOT,
37 HE_GRENADE,
38 AWP
39}
40
41new UserData[ 33 ][ PlData ], iCvars[ PluginCvars ], lifeCvars[ LifeAwardCvars ];
42
43new bool:g_Sql_Ready = false;
44
45new Handle:g_SqlConnection;
46new Handle:g_SqlTuple;
47
48new g_Error[ 512 ], g_szPrefix[ 32 ], g_iVipFlag[ 7 ];
49
50new g_iMaxPlayers, g_iSync;
51
52new const PLUGIN[] = "Deathrun: Life System";
53new const VERSION[] = "v1.1b";
54new const AUTHOR[] = "AJW1337//";
55new const DataBase[] = "dr_lifes";
56new const g_szClassNameHud[] = "LifesHud";
57
58public plugin_init()
59{
60 register_plugin( PLUGIN, VERSION, AUTHOR );
61
62 iCvars[ PREFIX ] = register_cvar( "dr_lifes_prefix", " Deathrun: Lifes " );
63 iCvars[ VIP_FLAG ] = register_cvar( "dr_lifes_vip_flag", "t" );
64 iCvars[ GIVE ] = register_cvar( "dr_lifes_give_command", "1" );
65 iCvars[ LIFE ] = register_cvar( "dr_lifes_life_command", "1" );
66 iCvars[ RESPAWN ] = register_cvar( "dr_lifes_respawn_command", "1" );
67 iCvars[ MYLIFE ] = register_cvar( "dr_lifes_mylife_command", "1" );
68 iCvars[ PRUNE ] = register_cvar( "dr_lifes_prune_command", "1" );
69 iCvars[ MAX_LIFE ] = register_cvar( "dr_lifes_max_lifes", "500" );
70 iCvars[ KILL_MESSAGE ] = register_cvar( "dr_lifes_killer_message", "1" );
71 lifeCvars[ KILL ] = register_cvar( "dr_lifes_kill_life", "1" );
72 lifeCvars[ HEADSHOT ] = register_cvar( "dr_lifes_headshot_life", "1" );
73 lifeCvars[ HE_GRENADE ] = register_cvar( "dr_lifes_he_grenade_life", "1" );
74 lifeCvars[ AWP ] = register_cvar( "dr_lifes_awp_life", "1" );
75
76 register_event( "DeathMsg", "HookDeathMsg", "a" );
77 register_forward( FM_Sys_Error, "fw_ServerDown" );
78 register_forward( FM_GameShutdown, "fw_ServerDown" );
79 register_forward( FM_ServerDeactivate, "fw_ServerDown" );
80
81 register_clcmd( "say", "hook_say" );
82 register_clcmd( "say_team", "hook_say" );
83
84 register_concmd( "amx_give_lifes", "CmdGiveLifes", NEEDED_ACCESS, "<name> <lifes amount>" );
85 register_concmd( "amx_take_lifes", "CmdTakeLifes", NEEDED_ACCESS, "<name> <lifes amount>" );
86 register_concmd( "amx_give_lifes_all", "CmdGiveLifesToAll", NEEDED_ACCESS, "<lifes amount>" );
87
88 new iEnt = create_entity( "info_target" );
89
90 if( iEnt )
91 {
92 entity_set_string( iEnt, EV_SZ_classname, g_szClassNameHud );
93 entity_set_float( iEnt, EV_FL_nextthink, get_gametime( ) + UPDATE_INTERVAL );
94
95 register_think( g_szClassNameHud, "displayLifesHud" );
96 }
97
98 g_iSync = CreateHudSyncObj( );
99
100 g_iMaxPlayers = get_maxplayers( );
101 set_task( 1.0, "MySql_Init" );
102
103 #if USE_CONFIG_FILE == 1
104 register_concmd( "amx_reload_file", "CmdReloadConfigFile", NEEDED_ACCESS );
105 set_task( 1.0, "taskLoadFile" );
106 #endif
107}
108public fw_ServerDown( )
109{
110 for ( new i = 0; i <= g_iMaxPlayers; i++ )
111 {
112 if ( is_user_connected( i ) )
113 Save_MySql( i );
114 }
115}
116public displayLifesHud( iEnt )
117{
118 if(!is_valid_ent(iEnt)) return;
119
120 new iPlayers[ 32 ], iNum, id;
121 get_players( iPlayers, iNum, "ach" );
122
123 get_pcvar_string( iCvars[ PREFIX ], g_szPrefix, charsmax ( g_szPrefix ) );
124
125 for (new i = 0; i < iNum; i++)
126 {
127 id = iPlayers[ i ];
128 if ( 0 <= UserData[ id ][ gLifes ] <= 100) set_hudmessage( 255, 255, 255, 0.01, 0.92, 0, 1.0, 1.0 );
129 else if ( 101 <= UserData[ id ][ gLifes ] <= 200) set_hudmessage( 255, 0, 255, 0.01, 0.92, 0, 1.0, 1.0 );
130 else if ( 201 <= UserData[ id ][ gLifes ] <= 250) set_hudmessage( 0, 255, 0, 0.01, 0.92, 0, 1.0, 1.0 );
131 else if ( 251 <= UserData[ id ][ gLifes ] <= 350) set_hudmessage( 0, 255, 255, 0.01, 0.92, 0, 1.0, 1.0 );
132 else if ( 351 <= UserData[ id ][ gLifes ] <= 450) set_hudmessage( 255, 0, 0, 0.01, 0.92, 0, 1.0, 1.0 );
133 else if ( 451 <= UserData[ id ][ gLifes ] <= get_pcvar_num( iCvars[ MAX_LIFE ] ) - 1 ) set_hudmessage( 255, 127, 0, 0.01, 0.92, 0, 1.0, 1.0 );
134 else if ( UserData[ id ][ gLifes ] == get_pcvar_num( iCvars[ MAX_LIFE ] ) ) set_hudmessage( 255, 255, 42, 0.01, 0.92, 0, 1.0, 1.0 );
135
136 ShowSyncHudMsg( id, g_iSync, "[ Lifes: %i | VIP Bonus: %s ]", UserData[ id ][ gLifes ], UserData[ id ][ gVip ] ? "Yes" : "No" );
137 }
138 entity_set_float( iEnt, EV_FL_nextthink, get_gametime( ) + UPDATE_INTERVAL );
139}
140public client_putinserver( id )
141{
142 if( !is_user_bot( id ) || !is_user_hltv( id ) )
143 {
144 get_pcvar_string( iCvars[ VIP_FLAG ], g_iVipFlag, charsmax ( g_iVipFlag ) );
145 UserData[ id ][ gVip ] = ( get_user_flags( id ) & read_flags( g_iVipFlag ) ) ? true : false;
146 UserData[ id ][ gAuthed ] = true;
147 Load_MySql( id );
148 }
149}
150public client_disconnect( id )
151{
152 Save_MySql( id );
153}
154public CmdGiveLifes( id, level,cid )
155{
156 if ( !cmd_access ( id, level, cid, 3 ) )
157 return PLUGIN_HANDLED;
158
159 new szArgs[32], szAmount[ 32 ], iTarget;
160
161 read_argv( 1, szArgs, charsmax( szArgs ) );
162 read_argv( 2, szAmount, charsmax ( szAmount ) );
163
164 iTarget = cmd_target( id, szArgs, 8 );
165
166 if( !iTarget ) return PLUGIN_HANDLED;
167
168 new szAdminName[ 32 ], szTargetName[ 32 ];
169 get_user_name( id, szAdminName, charsmax ( szAdminName ) );
170 get_user_name( iTarget, szTargetName, charsmax ( szTargetName ) );
171
172 UserData[ iTarget ][ gIncreaseLifes ] = str_to_num( szAmount );
173
174 UserData[ iTarget ][ gLifes ] += UserData[ iTarget ][ gIncreaseLifes ];
175 ColorChat( 0, GREY, "^4[%s]^3 ADMIN^4 %s^3: give^4 %i^3 lifes to^4 %s^3.", g_szPrefix, szAdminName, UserData[ iTarget ][ gIncreaseLifes ], szTargetName );
176
177 Save_MySql( id );
178 return PLUGIN_CONTINUE;
179}
180
181public CmdTakeLifes(id, level,cid)
182{
183 if ( !cmd_access ( id, level, cid, 3 ) )
184 return PLUGIN_HANDLED;
185
186 new szArgs[32], szAmount[ 32 ], iTarget;
187
188 read_argv( 1, szArgs, charsmax( szArgs ) );
189 read_argv( 2, szAmount, charsmax ( szAmount ) );
190
191 iTarget = cmd_target( id, szArgs, 8 );
192
193 if( !iTarget ) return PLUGIN_HANDLED;
194
195 new szAdminName[ 32 ], szTargetName[ 32 ];
196 get_user_name( id, szAdminName, charsmax ( szAdminName ) );
197 get_user_name( iTarget, szTargetName, charsmax ( szTargetName ) );
198
199 UserData[ iTarget ][ gIncreaseLifes ] = str_to_num( szAmount );
200
201 if( UserData[ iTarget ][ gLifes ] < UserData[ iTarget ][ gIncreaseLifes ] )
202 {
203 console_print(id, "Player %s doesn't even have %d lifes! He has: %d lifes.", szTargetName, UserData[ iTarget ][ gIncreaseLifes ], UserData[ iTarget ][ gLifes ]);
204 return PLUGIN_HANDLED;
205 }
206 UserData[ iTarget ][ gLifes ] -= UserData[ iTarget ][ gIncreaseLifes ];
207 ColorChat( 0, GREY, "^4[%s]^3 ADMIN^4 %s^3: took^4 %i^3 lifes from^4 %s^3.", g_szPrefix, szAdminName, UserData[ iTarget ][ gIncreaseLifes ], szTargetName );
208
209 Save_MySql( id );
210 return PLUGIN_CONTINUE;
211}
212public CmdGiveLifesToAll(id, level, cid)
213{
214 if( !cmd_access( id, level, cid, 2 ) )
215 return PLUGIN_HANDLED;
216
217 new szAmount[32];
218
219 read_argv(1, szAmount, charsmax ( szAmount ) );
220
221 new szAdminName[32];
222 get_user_name( id, szAdminName, charsmax ( szAdminName ) );
223
224 new iPlayers[ 32 ], iNum;
225 get_players( iPlayers, iNum, "ch" );
226
227 for( new i; i < iNum; i++ )
228 {
229 new iTarget = iPlayers[ i ];
230 UserData[ iTarget ][ gIncreaseLifes ] = str_to_num( szAmount );
231
232 UserData[ iTarget ][ gLifes ] += UserData[ iTarget ][ gIncreaseLifes ];
233
234 ColorChat( 0,GREY, "^4[%s]^3 ADMIN ^4%s^3: give^4 %i^3 lifes to ^4all ^3players", g_szPrefix, szAdminName, UserData[ iTarget ][ gIncreaseLifes ] );
235 }
236
237 Save_MySql( id );
238 return PLUGIN_CONTINUE;
239}
240public hook_say(id)
241{
242 new szArgs[ 192 ], szArgCmd[ 32 ], szArgName[ 32 ], szArgLife[ 10 ];
243 read_args( szArgs ,charsmax ( szArgs ) );
244 remove_quotes( szArgs );
245 parse(szArgs, szArgCmd, charsmax ( szArgCmd ), szArgName, charsmax ( szArgName ), szArgLife, charsmax ( szArgLife ) );
246
247 new szName[ 32 ], szTargetName[ 32 ], iTarget;
248 iTarget = cmd_target( id, szArgName, 0 );
249 UserData[ iTarget ][ gIncreaseLifes ] = str_to_num ( szArgLife );
250
251 if ( get_pcvar_num( iCvars[ GIVE ] ) && equali( szArgCmd,"/give" ) )
252 {
253 get_user_name( id, szName, charsmax ( szName ) );
254 get_user_name(iTarget, szTargetName, charsmax ( szTargetName ) );
255
256 if ( equal( szArgName, "" ) )
257 {
258 ColorChat( id, GREY,"^4[%s]^3 You must enter a name.", g_szPrefix );
259 return;
260 }
261
262 if ( !iTarget )
263 {
264 ColorChat( id, GREY,"^4[%s]^3 I can't find player with the name^4 %s^3.", g_szPrefix, szArgName );
265 return;
266 }
267
268 if ( id == iTarget )
269 {
270 ColorChat( id, GREY,"^4[%s]^3 You can't give^4 lifes^3 to yourself.", g_szPrefix );
271 return;
272 }
273
274 if ( UserData[ id ][ gLifes ] < UserData[ iTarget ][ gIncreaseLifes ] )
275 {
276 ColorChat( id, GREY,"^4[%s]^3 You don't have enough^4 lifes^3.", g_szPrefix );
277 return;
278 }
279
280 if ( UserData[ iTarget ][ gIncreaseLifes ] <= 0 )
281 {
282 ColorChat(id, GREY,"^4[%s]^3 You can give only^4 positive life amount^3.", g_szPrefix );
283 return;
284 }
285 if ( UserData[ iTarget ][ gIncreaseLifes ] >= 0 )
286 {
287 UserData[ id ][ gLifes ] -= UserData[ iTarget ][ gIncreaseLifes ];
288 UserData[ iTarget ][ gLifes ] += UserData[ iTarget ][ gIncreaseLifes ];
289 ColorChat( 0, GREEN,"^4[%s]^3 %s^1 give^4 %d^1 lifes to^3 %s^1.", g_szPrefix, szName, UserData[ iTarget ][ gIncreaseLifes ], szTargetName );
290 log_to_file( "LIFES_GIVE.log", "| LOG LIFES | <%s> give <%d> lifes to <%s>", szName, UserData[ iTarget ][ gIncreaseLifes ], szTargetName );
291 }
292 }
293 if( get_pcvar_num( iCvars[ LIFE ] ) && equali( szArgCmd,"/life" ) && get_user_flags( id ) & NEEDED_ACCESS )
294 {
295 get_user_name(iTarget, szTargetName, charsmax ( szTargetName ) );
296
297 if ( equal( szArgName, "") )
298 {
299 ColorChat( id, GREY,"^4[%s]^3 You must enter a name.", g_szPrefix );
300 return;
301 }
302 if ( !iTarget )
303 {
304 ColorChat( id,GREY,"^4[%s]^3 I can't find player with the name^4 %s^3.", g_szPrefix, szArgName );
305 return;
306 }
307 ColorChat( id, GREEN,"^4[%s]^3 %s^1 has^4 %i^1 lifes.", g_szPrefix,szTargetName, UserData[ iTarget ][ gLifes ] );
308 }
309 if ( get_pcvar_num( iCvars[ RESPAWN ] ) && equali( szArgCmd, "/respawn") || get_pcvar_num( iCvars[ RESPAWN ] ) && equali( szArgCmd, "/revive") )
310 {
311 if ( is_user_alive( id ) || get_user_team( id ) == 3 )
312 return;
313
314 if ( UserData[ id ][ gLifes ] >= 1 )
315 {
316 ExecuteHam( Ham_CS_RoundRespawn, id );
317 UserData[ id ][ gLifes ]--;
318 }
319 else
320 {
321 ColorChat( id, GREY, "^4[%s]^3 You don't have any^4 lifes^3 to^4 respawn^3.", g_szPrefix );
322 }
323 }
324 if ( get_pcvar_num( iCvars[ MYLIFE ] ) && equali( szArgCmd, "/mylifes" ) || get_pcvar_num( iCvars[ MYLIFE ] ) && equali( szArgCmd, "/lifes" ) )
325 {
326 ColorChat( id, GREY, "^4[%s]^3 Lifes:^4 %d", g_szPrefix, UserData[ id ][ gLifes ] );
327 }
328 if ( get_pcvar_num( iCvars[ PRUNE ] ) && equali( szArgCmd, "/prune" ) && get_user_flags( id ) & NEEDED_ACCESS )
329 {
330 if( !is_user_connected( id ) )
331 return;
332
333 TruncateTableMenu( id );
334 }
335}
336public HookDeathMsg( )
337{
338 new iKiller = read_data(1);
339 new iVictim = read_data(2);
340 new iHead = read_data(3);
341
342 new kill_message[126], vip_message[126], szVictimName[ 32 ];
343
344 get_user_name( iVictim, szVictimName, charsmax( szVictimName ) );
345
346 if ( iKiller != iVictim && is_user_connected( iKiller ) && UserData[ iKiller ][ gLifes ] <= get_pcvar_num( iCvars[ MAX_LIFE ] ) )
347 {
348 new szWeapon[ 32 ];
349 read_data( 4, szWeapon, charsmax ( szWeapon ) );
350
351 if ( equal( szWeapon, "grenade" ) )
352 {
353 UserData[ iKiller ][ gIncreaseLifes ] = get_pcvar_num( lifeCvars[ HE_GRENADE ] );
354 formatex( kill_message, charsmax ( kill_message ), " ^1with^3 HE Grenade^1");
355 }
356 else if ( equal( szWeapon, "awp" ) )
357 {
358 UserData[ iKiller ][ gIncreaseLifes ] = get_pcvar_num( lifeCvars[ AWP ] );
359 formatex( kill_message, charsmax ( kill_message ), " ^1with^3 %s^1", iHead ? "Awp HeadShot" : "Awp");
360 }
361 else
362 {
363 UserData[ iKiller ][ gIncreaseLifes ] = iHead ? get_pcvar_num( lifeCvars[ HEADSHOT ] ) : get_pcvar_num( lifeCvars[ KILL ] );
364 iHead ? formatex( kill_message, charsmax ( kill_message ), " ^1with^3 HeadShot^1" ) : formatex( kill_message, charsmax ( kill_message ), "" );
365 }
366 UserData[ iKiller ][ gLifes ] += UserData[ iKiller][ gVip ] ? ( UserData[ iKiller ][ gIncreaseLifes ] + 1 ) : UserData[ iKiller ][ gIncreaseLifes ];
367
368 if( get_pcvar_num( iCvars[ KILL_MESSAGE ] ) )
369 {
370 UserData[ iKiller ][ gVip ] ? formatex( vip_message, charsmax ( vip_message ), " (Bonus:^3 %i Lifes^1 for^4 VIP Users^1)", UserData[ iKiller ][ gIncreaseLifes ] ) : formatex( vip_message, charsmax ( vip_message ), " (buy^4 VIP^1 to get more^3 Lifes^1)" );
371 ColorChat( iKiller, NORMAL, "^4[%s]^1 You received^4 %d Lifes^1 for killing^3 %s%s%s", g_szPrefix, UserData[ iKiller ][ gIncreaseLifes ], szVictimName, kill_message, vip_message );
372 }
373 }
374
375 Save_MySql( iKiller );
376 return PLUGIN_CONTINUE;
377}
378public MySql_Init( )
379{
380 new Host[ 32 ], User[ 32 ], Pass[ 32 ], Db[ 32 ];
381 get_cvar_string( "amx_sql_host", Host, charsmax ( Host ) );
382 get_cvar_string( "amx_sql_user", User, charsmax ( User ) );
383 get_cvar_string( "amx_sql_pass", Pass, charsmax ( Pass ) );
384 get_cvar_string( "amx_sql_db", Db, charsmax (Db));
385
386 g_SqlTuple = SQL_MakeDbTuple( Host, User, Pass, Db );
387
388 new ErrorCode;
389 g_SqlConnection = SQL_Connect( g_SqlTuple, ErrorCode, g_Error, charsmax ( g_Error ) );
390
391 if( g_SqlConnection == Empty_Handle )
392 set_fail_state( g_Error );
393
394 new Handle:Queries;
395
396 Queries = SQL_PrepareQuery( g_SqlConnection, "CREATE TABLE IF NOT EXISTS %s (name varchar(64), lifes INT(11))" , DataBase );
397
398 if( !SQL_Execute( Queries ) )
399 {
400 SQL_QueryError( Queries, g_Error, charsmax ( g_Error ) );
401 set_fail_state( g_Error );
402 }
403
404 SQL_FreeHandle( Queries );
405
406 g_Sql_Ready = true;
407
408 for( new i=1; i <= g_iMaxPlayers; i++ )
409 {
410 if( UserData[ i ][ gAuthed ] )
411 {
412 Load_MySql( i );
413 }
414 }
415}
416public Load_MySql( id )
417{
418 if( g_Sql_Ready )
419 {
420 if( g_SqlTuple == Empty_Handle )
421 set_fail_state( g_Error );
422
423 new szPlayerName[ 32 ], szQuotedName[ 64 ], szTemp[ 512 ];
424 get_user_name( id, szPlayerName, charsmax ( szPlayerName ) );
425 SQL_QuoteString( g_SqlConnection, szQuotedName, charsmax ( szQuotedName ), szPlayerName );
426
427 new Data[ 1 ];
428 Data[ 0 ] = id;
429
430 format( szTemp,charsmax ( szTemp),"SELECT * FROM `%s` WHERE `name` = '%s'", DataBase, szQuotedName );
431 SQL_ThreadQuery( g_SqlTuple,"register_client", szTemp, Data, 1 );
432 }
433}
434public register_client( FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
435{
436 if ( FailState == TQUERY_CONNECT_FAILED )
437 log_amx( "Load - Could not connect to SQL database. [%d] %s", Errcode, Error );
438 else if ( FailState == TQUERY_QUERY_FAILED )
439 log_amx( "Load Query failed. [%d] %s", Errcode, Error );
440
441 new id = Data[ 0 ];
442
443 if ( SQL_NumResults( Query ) < 1 )
444 {
445 new szName[32], szQuotedName[ 64 ];
446 get_user_name( id, szName, charsmax ( szName ) );
447 SQL_QuoteString( g_SqlConnection, szQuotedName, charsmax ( szQuotedName ), szName );
448
449 new szTemp[ 512 ];
450 format( szTemp,charsmax ( szTemp ),"INSERT INTO `%s` VALUES ('%s','0');", DataBase, szQuotedName );
451 SQL_ThreadQuery( g_SqlTuple, "IgnoreHandle", szTemp );
452 }
453 else
454 UserData[ id ][ gLifes ] = SQL_ReadResult( Query, 1 );
455
456 UserData[ id ][ gLoaded ] = true;
457
458 return PLUGIN_HANDLED;
459}
460public Save_MySql( id )
461{
462 if( UserData[ id ][ gLoaded ] )
463 {
464 new szTemp[ 512 ], szName[ 32 ], szQuotedName[ 64 ];
465 get_user_name( id, szName, charsmax ( szName ) );
466 SQL_QuoteString( g_SqlConnection, szQuotedName, charsmax ( szQuotedName ), szName );
467
468 if( UserData[ id ][ gLifes ] >= get_pcvar_num( iCvars[ MAX_LIFE ] ) ) UserData[ id ][ gLifes ] = get_pcvar_num( iCvars[ MAX_LIFE ] );
469
470 format( szTemp,charsmax ( szTemp ),"UPDATE `%s` SET `lifes` = '%i' WHERE `name` = '%s';", DataBase, UserData[ id ][ gLifes ], szQuotedName );
471 SQL_ThreadQuery( g_SqlTuple,"IgnoreHandle",szTemp );
472 }
473}
474public IgnoreHandle( FailState, Handle:Query,Error[], Errcode,Data[], DataSize )
475{
476 SQL_FreeHandle( Query );
477
478 return PLUGIN_HANDLED;
479}
480public plugin_end( )
481{
482 if( g_SqlConnection != Empty_Handle )
483 SQL_FreeHandle( g_SqlConnection );
484}
485public plugin_natives( )
486{
487 register_library("deathrun_lifes");
488
489 register_native("get_user_lifes", "_get_user_lifes");
490 register_native("set_user_lifes", "_set_user_lifes");
491}
492public _get_user_lifes( plugin, params )
493{
494 return UserData[ get_param( 1 ) ][ gLifes ];
495}
496public _set_user_lifes( plugin, params )
497{
498 new id = get_param( 1 );
499 UserData[ id ][ gLifes ] = max( 0, get_param( 2 ) );
500 return UserData[ id ][ gLifes ];
501}
502public client_infochanged( id )
503{
504 new szNewName[ 32 ], szOldName[ 32 ];
505 get_user_info( id, "name", szNewName, charsmax ( szNewName ) );
506 get_user_name( id, szOldName, charsmax ( szOldName ) );
507
508 if( !equal( szNewName, szOldName ) )
509 {
510 Save_MySql( id );
511 set_task( 0.1, "Load_MySql", id );
512 return PLUGIN_HANDLED;
513 }
514 return PLUGIN_HANDLED;
515}
516public TruncateTableMenu( id )
517{
518 new szMenuTitle[126];
519 formatex( szMenuTitle, charsmax ( szMenuTitle ), "\r[\y%s\r] \wAre you sure you want to empty database?", g_szPrefix );
520 new iMenu = menu_create( szMenuTitle, "TruncateTableMenuFunc" );
521 menu_additem( iMenu, "Yes", "1", 0 );
522 menu_additem( iMenu, "No", "2", 0 );
523 menu_display( id, iMenu, 0 );
524}
525public TruncateTableMenuFunc( id, iMenu, Item )
526{
527 switch( ++Item )
528 {
529 case 1:
530 {
531 new Handle:iTruncate;
532 iTruncate = SQL_PrepareQuery( g_SqlConnection, "TRUNCATE TABLE `%s`", DataBase );
533 if( SQL_Execute( iTruncate ) )
534 {
535 ColorChat( id, GREY, "^4[%s]^3 The table was cleared successfully!", g_szPrefix );
536 }
537 else
538 {
539 ColorChat( id, GREY, "^4[%s]^3 There was a problem, the table is^4 not cleared^3!" , g_szPrefix );
540 }
541 SQL_FreeHandle(iTruncate);
542 }
543 case 2:
544 {
545 return PLUGIN_CONTINUE;
546 }
547 case MENU_EXIT:
548 {
549 menu_destroy( iMenu );
550 return PLUGIN_HANDLED;
551 }
552 }
553 menu_destroy(iMenu);
554 return PLUGIN_HANDLED;
555}
556#if USE_CONFIG_FILE == 1
557public CmdReloadConfigFile( id, level, cid )
558{
559 if( !cmd_access( id, level, cid, 1 ) )
560 return PLUGIN_HANDLED;
561
562 client_print( id, print_console, "Configuration file executed successfully!" );
563 taskLoadFile( );
564 return PLUGIN_HANDLED;
565}
566
567public taskLoadFile( )
568{
569 new szFile[ 124 ], dir[ 124 ];
570 get_configsdir( dir, charsmax( dir ) );
571 formatex( szFile, charsmax ( szFile ), "%s/DeathRun_Lifes.cfg", dir );
572
573 if( file_exists( szFile ) )
574 {
575 server_cmd( "exec %s", szFile );
576 server_exec( );
577 }
578 else
579 {
580 CreateFile( szFile );
581 log_amx( "DeathRun_Lifes.cfg is not found in configs folder. File is created..." );
582 }
583}
584
585CreateFile( const file[ ] )
586{
587 new i = fopen( file, "wt" );
588
589 fprintf( i, "// %s %s by %s^n" , PLUGIN, VERSION, AUTHOR);
590 fprintf( i, "// Do not modify, If you don't know how!!^n^n" );
591
592 fprintf( i, "// DeathRun Lifes Prefix ( Default: ^"Deathrun: Lifes^" )^n");
593 fprintf( i, "dr_lifes_prefix ^"%s^"^n^n", g_szPrefix );
594 fprintf( i, "// Vip Flag for Extra Lifes: ( Default: ^"t^" )^n");
595 fprintf( i, "dr_lifes_vip_flag ^"%s^"^n^n", g_iVipFlag );
596 fprintf( i, "// Killer Message: ( Default: 1 )^n");
597 fprintf( i, "dr_lifes_killer_message ^"%i^"^n^n", get_pcvar_num( iCvars[ KILL_MESSAGE ] ) );
598 fprintf( i, "// How much Lifes to get on normal kill ( Default: 1 )^n");
599 fprintf( i, "dr_lifes_kill_life ^"%i^"^n^n", get_pcvar_num( lifeCvars[ KILL ] ) );
600 fprintf( i, "// How much Lifes to get on headshot kill ( Default: 1 )^n");
601 fprintf( i, "dr_lifes_kill_life ^"%i^"^n^n", get_pcvar_num( lifeCvars[ HEADSHOT ] ) );
602 fprintf( i, "// How much Lifes to get on he grenade kill ( Default: 1 )^n");
603 fprintf( i, "dr_lifes_he_grenade_life ^"%i^"^n^n", get_pcvar_num( lifeCvars[ HE_GRENADE ] ) );
604 fprintf( i, "// How much Lifes to get on awp kill ( Default: 1 )^n");
605 fprintf( i, "dr_lifes_awp_life ^"%i^"^n^n", get_pcvar_num( lifeCvars[ AWP ] ) );
606 fprintf( i, "// Max lifes you can have ( Default: 500 )^n");
607 fprintf( i, "dr_lifes_max_lifes ^"%i^"^n^n", get_pcvar_num( iCvars[ MAX_LIFE ] ) );
608 fprintf( i, "// Chat Commands:^n// [ /give <nick> <amount> | /lifes, /mylifes | /life <nick> | /respawn | /prune ]^n^n" );
609 fprintf( i, "// Command: /give < nick > < amount > ( Default: 1 )^n");
610 fprintf( i, "dr_lifes_give_command ^"%i^"^n^n", get_pcvar_num( iCvars[ GIVE ] ) );
611 fprintf( i, "// Command: /lifes / /mylifes ( Default: 1 )^n");
612 fprintf( i, "dr_lifes_mylife_command ^"%i^"^n^n", get_pcvar_num( iCvars[ MYLIFE ] ) );
613 fprintf( i, "// Command: /life < nick > [ Check other player lifes | Needed Access: RCON ] ( Default: 1 )^n");
614 fprintf( i, "dr_lifes_life_command ^"%i^"^n^n", get_pcvar_num( iCvars[ LIFE ] ) );
615 fprintf( i, "// Command: /respawn | /revive ( Default: 1 )^n");
616 fprintf( i, "dr_lifes_respawn_command ^"%i^"^n^n", get_pcvar_num( iCvars[ RESPAWN ] ) );
617 fprintf( i, "// Command: /prune [ Prune(clear) Lifes DataBase | Needed Access: RCON ] ( Default: 1 )^n");
618 fprintf( i, "dr_lifes_prune_command ^"%i^"^n^n", get_pcvar_num( iCvars[ PRUNE ] ) );
619
620 fclose( i );
621}
622#endif