Hello, I am using this plugin I would like to know how I can add a benefit with "ADMIN_LEVEL_H" to the user who wins the map and in the next one they will give him the benefit only on that map then if he wins another one that is granted to everything and so on ..
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fakemeta>
#include <fun>
#include <sqlx>
new const szPlugin[ ][ ] = { "Win By Frags", "1.0", "Mario AR." };
new const szPrefix[ ] = "^3[ Redline ]^1";
new const szNameDb[ ] = "db_wbf";
new const szNameTb[ ] = "tb_wbf";
/* =============================================== */
#define player_name(%0) (g_playername[%0-1])
#define player_connected(%0) (g_connected & (1 << %0-1))
#define RANDOMR random_num( 0, 255 )
#define RANDOMG random_num( 0, 255 )
#define RANDOMB random_num( 0, 255 )
enum ( += 111 ) {
TASK_SHOWFRAGS = 987,
TASK_SHOWLEADER
};
enum {
DATA_LOAD,
DATA_SAVE,
DATA_INSERT,
DATA_TOP
};
new g_firstleader, g_secondleader, g_thirdleader, g_winner;
new g_votemap, g_leaderfrags;
new g_connected, g_maxplayers;
new g_kills[ MAX_PLAYERS+1 ], g_kills_knife[ MAX_PLAYERS+1 ], g_kills_hs[ MAX_PLAYERS+1 ], g_deaths[ MAX_PLAYERS+1 ], g_deaths_knife[ MAX_PLAYERS+1 ], g_deaths_hs[ MAX_PLAYERS+1 ], g_wins[ MAX_PLAYERS+1 ];
new Handle:g_hTuple, Handle:g_hConnect;
new g_TopEmpty, g_rank[ MAX_PLAYERS + 1 ];
new g_playername[ MAX_PLAYERS+1 ][ MAX_NAME_LENGTH ];
new cvar_maxfrags, cvar_enable, cvar_lastfrags, cvar_winnertime, cvar_steal, cvar_suicide;
new g_motd[1500], g_music;
new KEYSMENU = MENU_KEY_0 | MENU_KEY_1;
new const szWinMusic[ ][ ] = {
"media/Half-Life03.mp3",
"media/Half-Life11.mp3",
"media/Half-Life12.mp3",
"media/Half-Life13.mp3",
"media/Half-Life17.mp3"
};
/* =============================================== */
public plugin_precache( ) {
precache_sound( "gungame/gg_brass_bell.wav" );
precache_sound( "wbf/box_ring.wav" );
g_music = random( sizeof szWinMusic );
precache_generic( szWinMusic[ g_music ] );
}
public plugin_init( ) {
register_plugin( szPlugin[ 0 ], szPlugin[ 1 ], szPlugin[ 2 ] );
register_clcmd( "say .info", "fn_ShowStatistics" );
register_event( "DeathMsg", "event_DeathMsg", "a" )
register_menu( "Statitics Menu", KEYSMENU, "fn_HandStatitics" );
cvar_maxfrags = register_cvar( "wbf_max_frags", "50" );
cvar_enable = register_cvar( "wbf_enable", "1" );
cvar_winnertime = register_cvar( "wbf_winner_time", "15" );
cvar_lastfrags = register_cvar( "wbf_frags_left_to_vote", "10" );
cvar_steal = register_cvar( "wbf_knife_steal", "1" );
cvar_suicide = register_cvar( "wbf_penalty", "0" );
set_task( 3.0, "fn_StartTasks" );
g_maxplayers = get_maxplayers( );
SQL_Init( );
}
public plugin_end( ) if( g_hTuple ) SQL_FreeHandle( g_hTuple );
public client_putinserver( id ) {
if( !get_pcvar_num( cvar_enable ) ) return;
get_user_name( id, player_name( id ), 31 );
g_connected |= ( 1 << id-1 );
fn_LoadData( id );
fn_GetRank( id );
if( !is_user_bot( id ) ) {
set_task( 3.0, "fn_ShowFrags", id + TASK_SHOWFRAGS );
set_task( 3.0, "fn_ShowTheLeader", id + TASK_SHOWLEADER );
}
}
public client_disconnected( id ) {
if( !get_pcvar_num( cvar_enable ) ) return;
if( task_exists( id + TASK_SHOWLEADER ) )
remove_task( id + TASK_SHOWLEADER );
if( task_exists( id + TASK_SHOWFRAGS ) )
remove_task( id + TASK_SHOWFRAGS );
g_connected &= ~( 1 << id-1 );
fn_SaveData( id );
}
public client_infochanged( id ) {
if( !player_connected( id ) ) return;
get_user_info( id, "name", player_name( id ), 31 );
}
/* =============================================== */
public event_DeathMsg( ) {
if( !get_pcvar_num( cvar_enable ) || g_winner ) return;
static id, vic, hs;
id = read_data( 1 );
vic = read_data( 2 );
hs = read_data( 3 );
static weapon[ 3 ], steal, frags, maxfrags;
g_kills[ id ]++;
g_deaths[ vic ]++;
if( id == vic ) {
if( ( frags = get_pcvar_num( cvar_suicide ) ) ) {
if( frags > 1 ) set_user_frags( id, get_user_frags( id ) + 1 - frags );
client_print_color( id, print_team_default, "%s Pierdes^4 %d fra%s^1 por suicidarte.", szPrefix, frags > 1 ? "gs" : "g" );
} else set_user_frags( id, get_user_frags( id ) + 1 );
return;
}
if( hs ) {
g_kills_hs[ id ]++;
g_deaths_hs[ vic ]++;
}
read_data( 4, weapon, 2 );
steal = get_pcvar_num( cvar_steal );
frags = get_user_frags( id );
if( steal && weapon[ 0 ] == 'k' ) {
g_kills_knife[ id ]++;
g_deaths_knife[ vic ]++;
set_user_frags( id, frags + steal - 1 );
set_user_frags( vic, get_user_frags( vic ) - steal );
client_print_color( id, print_team_default, "%s Robaste^4 %i frag%s^1 de^4 %s^1 por acuchillarlo.", szPrefix, steal, steal == 1 ? "" : "s", player_name( vic ) );
client_print_color( vic, print_team_default, "%s^4 %s^1 te robo^4 %i frag%s^1 por acuchillarte.", szPrefix, player_name( id ), steal, steal == 1 ? "" : "s" );
}
maxfrags = get_pcvar_num( cvar_maxfrags );
if( !g_winner && frags + 1 >= maxfrags ) {
g_winner = id;
g_firstleader = get_pcvar_num( cvar_winnertime );
g_secondleader = vic;
client_cmd( 0, "spk wbf/box_ring.wav" );
fn_PrepareToChangeMap( );
g_wins[ g_winner ]++;
fn_SaveData( g_winner );
fn_SaveData( vic );
new len = st_PrepareWinnerMotd( g_winner, g_wins[ g_winner ] );
new nextmap[ 150 ], map[ 32 ], newlen;
get_cvar_string( "amx_nextmap", map, 31 );
formatex( nextmap, charsmax( nextmap ), "<br><p>El proximo mapa sera <font color=FF4C4C>%s<font color=FFFFFF>. Cambiando en %.0f segundos...</font></p>", map, get_pcvar_float( cvar_winnertime ) );
for( id = 1; id <= g_maxplayers; id++ )
{
if( !player_connected( id ) ) continue;
set_user_godmode( id, 1 );
strip_user_weapons( id );
frags = get_user_frags( id );
if( id == g_winner )
newlen = len + formatex( g_motd[ len ], charsmax( g_motd ) - len, "<p>Felicitaciones! Has ganado en este mapa.<p>Mucha suerte para el proximo!" );
else {
newlen = len + formatex( g_motd[ len ], charsmax( g_motd ) - len, "<p>%s, conseguiste %d frags, te falt%s %d para ganar.<p>\
Mejor suerte la proxima vez!", player_name( id ), frags, maxfrags - frags <= 1 ? "o solo" : "aron", maxfrags - frags );
}
copy( g_motd[ newlen ], charsmax( g_motd ) - newlen, nextmap );
show_motd( id, g_motd, "Fin del Juego" );
}
}
}
/* =============================================== */
public fn_StartTasks( ) {
if( !get_pcvar_num( cvar_enable ) ) return;
set_cvar_num( "mp_timelimit", 0 );
fn_GetTheLeader( );
}
public fn_ShowFrags( id ) {
id -= TASK_SHOWFRAGS;
if( !player_connected( id ) ) return;
static Frags;
Frags = get_user_frags( id );
if( !g_winner ) {
set_hudmessage( RANDOMR, RANDOMG, RANDOMB, -1.0, 0.84, 1, 0.0, 1.1, 0.0, 0.0, 4 );
show_hudmessage( id, "Tienes %i frags.^nNecesitas %i mas para ganar.", Frags, get_pcvar_num( cvar_maxfrags ) - Frags );
} else {
set_hudmessage( RANDOMR, RANDOMG, RANDOMB, -1.0, -1.0, 1, 0.0, 1.1, 0.0, 0.0, 3 );
show_hudmessage( id, "Cambio de mapa en %d segundos.", g_firstleader );
}
set_task( 1.0, "fn_ShowFrags", id + TASK_SHOWFRAGS );
}
public fn_GetTheLeader( ) {
if( g_winner ) return;
if( !g_votemap && get_pcvar_num( cvar_maxfrags ) - g_leaderfrags <= get_pcvar_num( cvar_lastfrags ) ) {
g_votemap = true;
st_VoteForMap( );
}
static frags[ 33 ], i;
g_leaderfrags = -99;
g_secondleader = g_thirdleader = 0;
for(i = 1; i <= g_maxplayers; i++) {
if( !player_connected( i ) ) continue;
frags[ i ] = get_user_frags( i );
if( frags[ i ] > g_leaderfrags ) {
g_firstleader = i;
g_leaderfrags = frags[ i ];
}
}
for( i = 1; i <= g_maxplayers; i++ ) {
if( !player_connected( i ) || i == g_firstleader ) continue;
if( frags[ i ] == g_leaderfrags ) {
if( !g_secondleader ) g_secondleader = i
else if( !g_thirdleader ) {
g_thirdleader = i;
break;
}
}
}
set_task( 0.2, "fn_GetTheLeader" );
}
public fn_ShowTheLeader( id ) {
id -= TASK_SHOWLEADER
if( !player_connected( id ) ) return;
set_hudmessage( RANDOMR, RANDOMG, RANDOMB, -1.0, 0.12, 1, 0.0, 1.1, 0.0, 0.0, 3 );
static frags; frags = get_user_frags(id);
if( !g_secondleader ) {
if( g_firstleader == id )
show_hudmessage( id, "Eres el unico lider." );
else
show_hudmessage( id, "Lider: %s con %d frags.^nEstas a %i frags de alcanzarlo.", player_name( g_firstleader ), g_leaderfrags, g_leaderfrags - frags );
} else if(!g_thirdleader) {
if( frags == g_leaderfrags )
show_hudmessage( id, "Eres el lider y compartes el titulo con:^n%s", player_name( ( id == g_firstleader ) ? g_secondleader : g_firstleader ) );
else
show_hudmessage( id, "Lideres: %s y %s con %d frags.^nEstas a %d frags de alcanzarlos.", player_name( g_firstleader ), player_name( g_secondleader ), g_leaderfrags, g_leaderfrags - frags );
} else {
if( frags == g_leaderfrags ) {
if( id == g_firstleader )
show_hudmessage( id, "Eres el lider y compartes el titulo con:^n%s y %s", player_name( g_secondleader ), player_name( g_thirdleader ) );
else if( id == g_secondleader )
show_hudmessage( id, "Eres el lider y compartes el titulo con:^n%s y %s", player_name( g_firstleader ), player_name( g_thirdleader ) );
else
show_hudmessage( id, "Eres el lider y compartes el titulo con:^n%s y %s", player_name( g_firstleader ), player_name( g_secondleader ) );
}
else
show_hudmessage( id, "Lideres: %s, %s y %s con %d frags.^nEstas a %d frags de alcanzarlos.", player_name( g_firstleader ), player_name( g_secondleader ), player_name( g_thirdleader ), g_leaderfrags, g_leaderfrags - frags );
}
if( !g_winner ) set_task( 1.0, "fn_ShowTheLeader", id + TASK_SHOWLEADER );
}
/* =============================================== */
public fn_GetRank( id ) {
new Handle:iQuery, iCount, szName[ MAX_NAME_LENGTH ];
iQuery = SQL_PrepareQuery( g_hConnect, "SELECT Name FROM '%s' ORDER BY Wins DESC", szNameTb );
if( SQL_Execute( iQuery ) ) {
while( SQL_MoreResults( iQuery ) ) {
iCount++;
SQL_ReadResult( iQuery, 0, szName, charsmax( szName ) );
if( equal( player_name( id ), szName ) ) {
g_rank[ id ] = iCount;
break;
}
SQL_NextRow( iQuery );
}
}
return PLUGIN_HANDLED;
}
public fn_ShowStatistics( id ) {
new menu[ 500 ], len;
len = 0;
len += formatex( menu[ len ], sizeof menu -1 - len, "\yEstadisticas^n^n\r•\w Nombre:\y %s^n\r•\w Rank en top de victorias:\y #%d \r(%d victorias)^n^n", player_name( id ), g_rank[ id ], g_wins[ id ] );
len += formatex( menu[ len ], sizeof menu -1 - len, "\r•\w Asesinatos:\y %d^n", g_kills[ id ] );
len += formatex( menu[ len ], sizeof menu -1 - len, "\r•\w Asesinatos con Cuchillo:\y %d^n", g_kills_knife[ id ] );
len += formatex( menu[ len ], sizeof menu -1 - len, "\r•\w Asesinatos de HeadShot:\y %d^n^n", g_kills_hs[ id ] );
len += formatex( menu[ len ], sizeof menu -1 - len, "\r•\w Muertes:\y %d^n", g_deaths[ id ] );
len += formatex( menu[ len ], sizeof menu -1 - len, "\r•\w Muertes por Cuchillo:\y %d^n", g_deaths_knife[ id ] );
len += formatex( menu[ len ], sizeof menu -1 - len, "\r•\w Muertes de HeadShot:\y %d^n^n", g_deaths_hs[ id ] );
len += formatex( menu[ len ], sizeof menu -1 - len, "\r0.\w Salir^n" );
len += formatex( menu[ len ], sizeof menu -1 - len, "\r1.\w Top de victorias" );
show_menu( id, KEYSMENU, menu, -1, "Statitics Menu" );
}
public fn_HandStatitics( id, keys, menu ) {
switch( keys ) {
case 9: { }
case 0: {
if( g_TopEmpty ) {
client_print_color( id, print_team_default, "%s El^4 Top^1 esta vacio.", szPrefix );
return PLUGIN_HANDLED;
}
fn_ShowTop( id );
}
}
return PLUGIN_HANDLED;
}
public fn_ShowTop( id ) {
static data[ 2 ], query[ 300 ];
data[ 0 ] = id; data[ 1 ] = DATA_TOP;
formatex( query, charsmax( query ), "SELECT Name, Wins FROM '%s' ORDER BY Wins DESC LIMIT 0, 10", szNameTb );
SQL_ThreadQuery( g_hTuple, "SQL_DataHandle", query, data, 2 );
}
public fn_LoadData( id ) {
static data[ 2 ], query[ 300 ];
data[ 0 ] = id; data[ 1 ] = DATA_LOAD;
formatex( query, charsmax( query ), "SELECT * FROM %s WHERE Name = ^"%s^"", szNameTb, player_name( id ) );
SQL_ThreadQuery( g_hTuple, "SQL_DataHandle", query, data, 2 );
}
public fn_SaveData( id ) {
static data[ 2 ], query[ 300 ];
data[ 0 ] = id; data[ 1 ] = DATA_SAVE;
formatex( query, charsmax( query ), "UPDATE %s SET Kills = '%d', KillsKnife = '%d', KillsHs = '%d', Deaths = '%d', DeathsKnife = '%d', DeathsHs = '%d', Wins = ^"%d^" WHERE Name = ^"%s^"",
szNameTb, g_kills[ id ], g_kills_knife[ id ], g_kills_hs[ id ], g_deaths[ id ], g_deaths_knife[ id ], g_deaths_hs[ id ], g_wins[ id ], player_name( id ) );
SQL_ThreadQuery( g_hTuple, "SQL_DataHandle", query, data, 2 );
}
public SQL_DataHandle( failstate, Handle:Query, Error[ ], szError, Data[ ], szData[ ], Float:time ) {
static id; id = Data[ 0 ];
if( !is_user_connected( id ) ) return;
if( failstate == TQUERY_CONNECT_FAILED || failstate == TQUERY_QUERY_FAILED )
log_to_file( "SQL_ERROR-1.txt", "Error %d: %s", szError, Error );
switch( Data[ 1 ] ) {
case DATA_LOAD: {
if( SQL_NumResults( Query ) ) {
g_kills[ id ] = SQL_ReadResult( Query, 1 );
g_kills_knife[ id ] = SQL_ReadResult( Query, 2 );
g_kills_hs[ id ] = SQL_ReadResult( Query, 3 );
g_deaths[ id ] = SQL_ReadResult( Query, 4 );
g_deaths_knife[ id ] = SQL_ReadResult( Query, 5 );
g_deaths_hs[ id ] = SQL_ReadResult( Query, 6 );
g_wins[ id ] = SQL_ReadResult( Query, 7 );
} else {
static gData[ 2 ], gQuery[ 300 ];
gData[ 0 ] = id; gData[ 1 ] = DATA_INSERT;
formatex( gQuery, charsmax( gQuery ), "INSERT INTO %s (Name) VALUES (^"%s^")", szNameTb, player_name( id ) );
SQL_ThreadQuery( g_hTuple, "SQL_DataHandle", gQuery, gData, 2 );
}
}
case DATA_SAVE: {
if( failstate < TQUERY_SUCCESS ) client_print_color( id, print_team_default, "%s Error al guardar tus datos.", szPrefix );
else client_print_color( id, print_team_default, "%s Datos guardados correctamente.", szPrefix );
}
case DATA_INSERT: {
if( failstate < TQUERY_SUCCESS ) return;
else fn_LoadData( id );
}
case DATA_TOP: {
if( SQL_NumResults( Query ) ) {
g_TopEmpty = false;
new iPosition, szName[ MAX_NAME_LENGTH ], iWins;
static len, szBuffer[ 2368 ];
len = 0;
len = format( szBuffer[ len ], charsmax( szBuffer ) - len, "<STYLE>body{background:#232323;color:#cfcbc2;font-family:sans-serif}table{width:100%%;line-height:160%%;font-size:12px}\
.q{border:1px solid #4a4945}.b{background:#2a2a2a}</STYLE><table cellpadding=2 cellspacing=0 border=0>" );
len += format( szBuffer[ len ], charsmax( szBuffer ) - len, "<tr align=center bgcolor=#52697B><th width=5%%> # <th width=22%% align=left> Nombre <th width=10%%> Victorias" );
while( SQL_MoreResults( Query ) ) {
++iPosition;
SQL_ReadResult( Query, 0, szName, charsmax( szName ) );
iWins = SQL_ReadResult( Query, 1 );
len += format( szBuffer[ len ], charsmax( szBuffer ) - len, "<tr align=center%s><td> %d <td align=left> %s <td> %d",
( ( iPosition%2 )==0 ) ? "" : " bgcolor=#2f3030", iPosition, szName, iWins );
SQL_NextRow( Query );
}
show_motd( id, szBuffer, "TOP DE VICTORIAS" );
} else
g_TopEmpty = true;
}
}
}
public SQL_Init( ) {
new get_type[ 12 ], table[ 1000 ], len, szError[ 256 ], iError;
SQL_SetAffinity( "sqlite" );
SQL_GetAffinity( get_type, sizeof( get_type ) );
if( !equal( get_type, "sqlite" ) ) {
log_to_file( "ERROR_SQL.txt", "Error al conectar." );
return pause( "a" );
}
g_hTuple = SQL_MakeDbTuple( "", "", "", szNameDb );
g_hConnect = SQL_Connect( g_hTuple, iError, szError, sizeof ( szError ) - 1 );
len = 0;
len += formatex( table[ len ], charsmax( table ) - len, "CREATE TABLE IF NOT EXISTS %s", szNameTb );
len += formatex( table[ len ], charsmax( table ) - len, "( Name varchar(32) NOT NULL UNIQUE PRIMARY KEY," );
len += formatex( table[ len ], charsmax( table ) - len, "Kills int NOT NULL DEFAULT '0' ," );
len += formatex( table[ len ], charsmax( table ) - len, "KillsKnife int NOT NULL DEFAULT '0' ," );
len += formatex( table[ len ], charsmax( table ) - len, "KillsHs int NOT NULL DEFAULT '0' ," );
len += formatex( table[ len ], charsmax( table ) - len, "Deaths int NOT NULL DEFAULT '0' ," );
len += formatex( table[ len ], charsmax( table ) - len, "DeathsKnife int NOT NULL DEFAULT '0' ," );
len += formatex( table[ len ], charsmax( table ) - len, "DeathsHs int NOT NULL DEFAULT '0' ," );
len += formatex( table[ len ], charsmax( table ) - len, "Wins int NOT NULL DEFAULT '0' )" );
SQL_ThreadQuery( g_hTuple, "SQL_CreateTable", table );
return PLUGIN_CONTINUE;
}
public SQL_CreateTable( failstate, Handle:query, error[], szerror, data[], szdata, Float:time ) {
switch( failstate ) {
case TQUERY_CONNECT_FAILED:
log_to_file( "SQL_TConnection.txt", "Error: %i - %s", szerror, error );
case TQUERY_QUERY_FAILED:
log_to_file( "SQL_TQuery.txt", "Error: %i - %s", szerror, error );
}
}
public fn_PrepareToChangeMap( ) {
g_firstleader--
if( !g_firstleader ) {
new NextMap[ 65 ];
get_cvar_string( "amx_nextmap", NextMap, 64 );
server_cmd( "changelevel %s", NextMap );
} else {
if( g_firstleader == get_pcvar_num( cvar_winnertime ) - 2 ) client_cmd( 0, "mp3 play ^"%s^"", szWinMusic[ g_music ] );
set_task( 1.0, "fn_PrepareToChangeMap" );
}
}
/* =============================================== */
st_PrepareWinnerMotd( winner, wins ) {
new len = formatex( g_motd, charsmax( g_motd ), "<meta http-equiv=^"Content-Type^" content=^"text/html;charset=UTF-8^">\
<body bgcolor=black style=line-height:1;color:white><center><font color=FFFFFF size=7 face=Tahoma><p>ONLY FRAGGERS" );
len += formatex( g_motd[ len ], charsmax( g_motd ) - len, "<br><p><font color=00CC00 size=6 style=letter-spacing:2px>\
<font size=4 color=white style=letter-spacing:1px>El ganador es " );
len += formatex( g_motd[ len ], charsmax( g_motd ) - len, "<p><div style=height:1px;width:80%%;background-color:00CC00;overflow:hidden></div>\
<font color=00CC00 size=7 style=letter-spacing:2px>%s<div style=height:1px;width:80%%;background-color:00CC00;overflow:hidden></div><p>", player_name( winner ) );
if( wins > 1 )
len += formatex( g_motd[ len ], charsmax( g_motd ) - len, "<font color=FFFFFF size=4>Con esta victoria,<font color=00CC00> %s <font color=FFFFFF>ahora acumula <font color=FF4C4C>%d <font color=FFFFFF>victorias en total.", player_name( winner ), wins );
else len += formatex( g_motd[ len ], charsmax( g_motd ) - len, "<font color=FFFFFF size=4>Esta es la <font color=FF4C4C>primera victoria<font color=FFFFFF> de <font color=00CC00>%s<font color=FFFFFF>.", player_name( winner ) );
return len;
}
stock st_VoteForMap( ) {
if( find_plugin_byfile( "mapchooser.amxx" ) == INVALID_PLUGIN_ID ) return;
new oldWinLimit = get_cvar_num( "mp_winlimit" ), oldMaxRounds = get_cvar_num( "mp_maxrounds" );
set_cvar_num( "mp_winlimit",0 );
set_cvar_num( "mp_maxrounds",-1 );
client_cmd( 0, "spk gungame/gg_brass_bell.wav" );
if( callfunc_begin( "voteNextmap", "mapchooser.amxx" ) == 1 ) callfunc_end( );
set_cvar_num( "mp_winlimit",oldWinLimit );
set_cvar_num( "mp_maxrounds",oldMaxRounds );
}