Rangos Por Horas
Explicación:
Pd: Las Horas Se Ganan Jugando en el Servidor
Changelog:
/*
Changelog:
- 1.0 - Lanzamiento Oficial
- 1.5 - Re estructurando partes del codigo
- 1.7 - Agregando Privilegios a los Jugadores
*/
Mejoras en la 1.7:
- Habilidades Especiales ( desbloqueables por Rangos & Actiavar/Desactivar al gusto del jugador );
CVARS:
- rh_habilidades - 1/0 Activas/Desactivas - [ Habilidades Especiales ]
Créditos:
Jollero = Idea,
Destro = Su ingenioso Advanced_vault;
Necesitas:
Advanced Vault LINK: https://amxmodx-es.com/Thread-API-Advanc...#pid104596
#include < amxmodx >
#include < adv_vault >
#define HUD_ID (taskid-TASK_HOURS)
#define TASK_HOURS 100
new const g_iCredits[ ][ ] = { "Rangos Por Horas", "1.0b", "ImBuggimen" };
/* =====================================================
* <<<<<<<<<<<< INICIA SECCION MODIFICABLE >>>>>>>>>>>>>
* ===================================================*/
enum _:_STRUCT_RANGE { RNAME[ 90 ], HOURS_REQUIRED };
enum _:_STRUCT_TIME { SEGUNDOS, MINUTOS, HORAS };
enum { FIELD_TIMES, FIELD_RANGES, MAX_FIELDS };
#pragma semicolon 1
new const g_szRangos[ ][ _STRUCT_RANGE ] =
{
{ "Miembro Nuevo", 0 },
{ "Miembro Reconocido", 3 },
{ "Miembro Sr.", 10 },
{ "Miembro Heroe", 15 },
{ "Veterano", 20 },
{ "", 999999 } // Fix Bug del Hud
};
new g_iRangos[ 33 ];
new g_iTime[ 33 ][ _STRUCT_TIME ];
new g_iPlayerName[ 33 ][ 32 char ];
new g_iFields[ MAX_FIELDS ];
new g_iHud;
new g_iGuardado;
public plugin_init( )
{
register_plugin( g_iCredits[ 0 ], g_iCredits[ 1 ], g_iCredits[ 2 ] );
g_iHud = CreateHudSyncObj( );
g_iGuardado = adv_vault_open( "GuardadoRanges", false );
g_iFields[ FIELD_RANGES ] = adv_vault_register_field( g_iGuardado, "Ranges" );
g_iFields[ FIELD_TIMES ] = adv_vault_register_field( g_iGuardado, "Times", DATATYPE_ARRAY, 3 );
adv_vault_init( g_iGuardado );
}
public client_putinserver( index )
{
get_user_name( index, g_iPlayerName[ index ], charsmax( g_iPlayerName[ ] ) );
arrayset( g_iTime[ index ], 0, sizeof( g_iTime[ ] ) );
g_iRangos[ index ] = 0;
set_task( 1.0, "ShowHRangos", index+TASK_HOURS, _, _, .flags = "b" );
iCargar( index );
}
public client_infochanged( index )
{
if( !is_user_connected( index ) ) return;
static NewName[ 32 ];
get_user_info( index, "name", NewName, 31 );
if( !equal( NewName, g_iPlayerName[ index ] ) )
{
copy( g_iPlayerName[ index ], 31, NewName );
iCargar( index );
}
}
public client_disconnect( index )
{
remove_task( index+TASK_HOURS );
iGuardar( index );
}
public ShowHRangos( taskid )
{
static index; index = HUD_ID;
if( is_user_connected( index ) )
{
if( g_iTime[ index ][ SEGUNDOS ] > 59 )
{
g_iTime[ index ][ SEGUNDOS ] = 0;
g_iTime[ index ][ MINUTOS ]++;
}
else g_iTime[ index ][ SEGUNDOS ]++;
if( g_iTime[ index ][ MINUTOS ] > 59 )
{
g_iTime[ index ][ MINUTOS ] = 0;
g_iTime[ index ][ HORAS ]++;
Range_check( index );
}
}
set_hudmessage( 200, 100, 0, 0.1, 0.03, 1 );
ShowSyncHudMsg( index, g_iHud, "[ Rango: %s ]^n^n[ Tiempo Jugado ]^n[ Segundos: %d ]^n[ Minutos: %d ]^n[ Horas: %d ]",
g_szRangos[ g_iRangos[ index ] ][ RNAME ], g_iTime[ index ][ SEGUNDOS ], g_iTime[ index ][ MINUTOS ], g_iTime[ index ][ HORAS ] );
}
public Range_check( index )
{
new Range_Up = false;
if( g_iTime[ index ][ HORAS ] >= g_szRangos[ g_iRangos[ index ] ][ HOURS_REQUIRED ] )
{
g_iRangos[ index ]++;
Range_Up = true;
}
if( Range_Up ) iChat( index, "^4Haz Sido Promovido a %s", g_szRangos[ g_iRangos[ index ] ][ RNAME ] ), Range_Up = false;
}
public iGuardar( index )
{
adv_vault_set_start( g_iGuardado );
adv_vault_set_field( g_iGuardado, g_iFields[ FIELD_TIMES ], g_iTime[ index ] );
adv_vault_set_field( g_iGuardado, g_iFields[ FIELD_RANGES ], g_iRangos[ index ] );
adv_vault_set_end( g_iGuardado, 0, g_iPlayerName[ index ] );
}
public iCargar( index )
{
if( !adv_vault_get_prepare( g_iGuardado, _, g_iPlayerName[ index ] ) ) return;
g_iRangos[ index ] = adv_vault_get_field( g_iGuardado, g_iFields[ FIELD_RANGES ] );
adv_vault_get_field( g_iGuardado, g_iFields[ FIELD_TIMES ], g_iTime[ index ], sizeof ( g_iTime[ ] ) );
}
stock iChat( index, const input[ ], any:... )
{
static iSayText, sziMsg[ 191 ];
if ( !iSayText )
iSayText = get_user_msgid( "SayText" );
replace_all( sziMsg, 190, "!g", "^4" );
replace_all( sziMsg, 190, "!y", "^1" );
replace_all( sziMsg, 190, "!team", "^3" );
vformat( sziMsg, 190, input, 3 );
message_begin( index ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, iSayText, .player = index );
write_byte( index ? index : 33 );
write_string( sziMsg );
message_end( );
}
Version 1.7:
/*
Changelog:
- 1.0 - Lanzamiento Oficial
- 1.5 - Re estructurando partes del codigo
- 1.7 - Agregando Privilegios a los Jugadores
*/
new const g_szCustom[ ] = { "Rangos Por Horas", "1.7b", "I'mBuggimen." };
#include < amxmodx.inc >
#include < amxmisc.inc >
#include < fun.inc >
#include < hamsandwich.inc >
#include < fakemeta.inc >
#include < adv_vault.inc >
// =========================[~~]===========================
#define TASK_HOURS 1212
#define HUD_ID ( taskid - TASK_HOURS )
#define SetPlayerBit(%0,%1) ( %0 |= ( 1 << ( %1 & 31 ) ) )
#define GetPlayerBit(%0,%1) ( %0 & ( 1 << ( %1 & 31 ) ) )
#define ClearPlayerBit(%0,%1) ( %0 &= ~( 1 << ( %1 & 31 ) ) )
#define ClearString(%0) ( %0[ 0 ] = EOS )
#define GET_SIZE(%0) ( sizeof( %0 ) - 1 )
// =========================[~~]===========================
enum
{
LOAD = 0,
SAVE
};
enum
{
FIELD_TIMES,
FIELD_RANGES,
MAX_FIELDS
};
enum _: TIME_STRUCTURE
{
SECS = 0,
MINS,
HOURS
};
enum _: RANGE_STRUCTURE
{
RANGE_NAME[ 32 ],
RANGE_REQUIRED
};
enum _: HABS_STRUCTURE
{
Updates_Name[ 32 ],
Updates_Desc[ 150 ],
Updates_Required
} ;
// =========================[~~]===========================
new const g_szRangos[ 6 ][ RANGE_STRUCTURE ] =
{
{ "Miembro Nuevo", 0 },
{ "Miembro Reconocido", 3 },
{ "Miembro Sr.", 10 },
{ "Miembro Heroe", 15 },
{ "Veterano", 20 },
{ "Miembro Destacado", 25 }
};
new const g_szMejoras[ ][ HABS_STRUCTURE ] =
{
{ "Bullet's Damage", "Esta Habilidad Es Muy Util^nTe Permite Ver El Daño INFLINGIDO", 1 },
{ "BunnyHop", "Esta Habilidad te va a permitir Saltar Sucesivamente Como Conejo^nTendras mas control del mapa", 2 },
{ "Probabilidad de Daño Critico!", "Dicha Habilidad Hara que Aumente un probabilidad de Daño critico^nEs decir si pegas 50 normal con critico pegas 100", 3 }
};
// =========================[~~]===========================
new g_iRangos[ 33 ];
new g_iTime[ 33 ][ TIME_STRUCTURE ];
new g_szPN[ 33 ][ 32 ];
new g_iFields[ MAX_FIELDS ];
new sycn;
new g_iHud;
new g_iGuardado;
new g_bConnected;
new g_bAlive;
new KEYUPDT = ( 1 << 0 )|( 1 << 9 ) ;
new g_szTxt[ 500 ];
new g_iIdMejoras[ 32 + 1 ] ;
new g_iMejoras[ 32 + 1 ][ sizeof( g_szMejoras[ ] ) ];
new g_Mp;
const XO_PLAYER = 5
const m_iTeam = 114
new g_iTeam[ 33 ];
new pcvar_allowhabs;
public plugin_init( )
{
register_plugin( g_szCustom[ 0 ], g_szCustom[ 1 ], g_szCustom[ 2 ] );
RegisterHam( Ham_Spawn, "player", "fHam_Spawn_Post", 1 )
RegisterHam( Ham_Player_Jump, "player", "fHam_Jump_Pre", 0 ) ;
RegisterHam( Ham_TakeDamage, "player", "fHam_TakeDamage_Pre", 0 );
register_menu( "Menu Habilidades" , KEYUPDT , "mh_mejoras_inf" ) ;
register_clcmd( "say /habilidades", "func_habilities" );
g_iHud = CreateHudSyncObj( );
g_Mp = get_maxplayers( );
pcvar_allowhabs = create_cvar( "rh_habilidades", "1", _, "< 1/0 Activas/Desactivas - [ Habilidades Especiales ] >" );
Adv_Initialize( );
sycn = CreateHudSyncObj( );
}
public Adv_Initialize( )
{
g_iGuardado = adv_vault_open( "GuardadoRangos", false );
g_iFields[ FIELD_RANGES ] = adv_vault_register_field( g_iGuardado, "Ranges" );
g_iFields[ FIELD_TIMES ] = adv_vault_register_field( g_iGuardado, "Times", DATATYPE_ARRAY, 3 );
adv_vault_init( g_iGuardado );
}
public fHam_Spawn_Post( const index )
{
if( GetPlayerBit( g_bConnected, index ) && !( GetPlayerBit( g_bAlive, index ) ) && is_user_alive( index ) )
SetPlayerBit( g_bAlive, index );
if( GetPlayerBit( g_bAlive, index ) )
{
g_iTeam[ index ] = get_pdata_int( index, m_iTeam, XO_PLAYER );
}
}
public fHam_Killed_Post( const iVictim, const iKiller, const bool: bShouldgib )
{
if( iVictim == iKiller || !iKiller || g_iTeam[ iKiller ] == g_iTeam[ iVictim ] )
return HAM_IGNORED;
ClearPlayerBit( g_bAlive, iVictim );
return HAM_IGNORED;
}
public fHam_Jump_Pre( const index )
{
if( !get_pcvar_num( pcvar_allowhabs ) )
return HAM_IGNORED;
if ( GetPlayerBit( g_bAlive, index ) && g_iMejoras[ index ][ 1 ] )
{
pev( index, pev_fuser2, 0.0 ) ;
static flags ; flags = pev( index, pev_flags );
if ( ( flags & FL_WATERJUMP ) || !( flags & FL_ONGROUND ) || pev( index , pev_waterlevel ) >= 2 )
return HAM_IGNORED ;
static Float: vec[ 3 ] ; pev( index, pev_velocity, vec ) ;
vec[ 2 ] += 250.0 ;
set_pev( index , pev_velocity, vec ) ;
}
return HAM_HANDLED;
}
public fHam_TakeDamage_Pre( const victim, const Inflictor, const attacker, const Float:damage, const damage_type )
{
if ( victim == attacker || !( 1 <= attacker <= g_Mp && GetPlayerBit( g_bConnected , attacker ) ) )
return HAM_IGNORED ;
if ( !( 1 <= victim <= g_Mp ) || g_iTeam[ attacker ] == g_iTeam[ victim ] )
return HAM_IGNORED ;
if( !get_pcvar_num( pcvar_allowhabs ) )
return HAM_IGNORED;
if ( g_iMejoras[ attacker ][ 2 ] )
{
if( random_num( 0, 100 ) < random_num( 0, 100 ) < random_num( 0, 100 ) )
{
SetHamParamFloat( 4, damage * 2 );
set_hudmessage( 0, 255, 0, -1.0, -1.0, 0, 6.0, 1.1, 3.0, 3.0, 3 );
show_hudmessage( attacker, "Golpe Critico!!!!" ) ;
}
}
if( g_iMejoras[ attacker ][ 0 ] )
{
set_hudmessage( 255, 0, 0, 0.45, 0.50, 2, 0.1, 4.0, 0.1, 0.1, -1 );
ShowSyncHudMsg( attacker, sycn, "Daño Inflingido: %i^n", floatround( damage ) );
}
return HAM_HANDLED;
}
public func_habilities( const index )
{
if( !get_pcvar_num( pcvar_allowhabs ) )
return PLUGIN_CONTINUE;
ShowHabs( index );
return PLUGIN_HANDLED;
}
public ShowHabs( const index )
{
ClearString( g_szTxt );
static menu , r ;
formatex( g_szTxt, GET_SIZE( g_szTxt ), "Lista de \yHabilidades" );
menu = menu_create( g_szTxt , "mh_mejoras" ) ;
for ( r = 0 ; r < sizeof( g_szMejoras ) ; ++ r )
menu_additem( menu, g_szMejoras[ r ][ Updates_Name ] ) ;
menu_setprop( menu, MPROP_NUMBER_COLOR, "\y" );
menu_setprop( menu, MPROP_NEXTNAME, "Siguiente" );
menu_setprop( menu, MPROP_BACKNAME, "Atras" );
menu_setprop( menu, MPROP_EXITNAME, "Salir" );
menu_display( index, menu ) ;
}
public mh_mejoras( const index, const menu , const item )
{
if ( item == MENU_EXIT || get_pcvar_num( pcvar_allowhabs ) < 1 ) { menu_destroy( menu ) ; return PLUGIN_HANDLED; }
g_iIdMejoras[ index ] = item ;
mejoras_inf( index , item ) ;
menu_destroy( menu ) ;
return PLUGIN_HANDLED;
}
public mejoras_inf( const index , const item )
{
ClearString( g_szTxt );
static len ; len = 0 ;
len += formatex( g_szTxt[ len ] , GET_SIZE( g_szTxt ) - len, "\y%s \dHabilidad:^n\y%s^n^n",
g_iMejoras[ index ][ item ] ? "Habilitar \wo \rDesahabilitar" : "Viendo",
g_szMejoras[ item ][ Updates_Name ] ) ;
len += formatex( g_szTxt[ len ] , GET_SIZE( g_szTxt ) - len, "\yDESCRIPCION:^n\d %s^n^n", g_szMejoras[ item ][ Updates_Desc ] );
if( g_iRangos[ index ] < g_szMejoras[ item ][ Updates_Required ] )
{
len += formatex( g_szTxt[ len ] , GET_SIZE( g_szTxt ) - len, "\yNECESARIO:^n" ) ;
len += formatex( g_szTxt[ len ] , GET_SIZE( g_szTxt ) - len, "\y-\d Rango Requerido: \w%s ^n^n", g_szRangos[ g_szMejoras[ item ][ Updates_Required ] ][ RANGE_NAME ] ) ;
}
else
{
len += formatex( g_szTxt[ len ] , GET_SIZE( g_szTxt ) - len, "\y[ \w1 \y]. \w%s \yHabilidad^n^n" ,
g_iMejoras[ index ][ item ] ? "Deshabilitar" : "Habilitar" );
}
len += formatex( g_szTxt[ len ] , GET_SIZE( g_szTxt ) - len, "\y[ \w0 \y]. \wAtras" ) ;
show_menu( index, KEYUPDT, g_szTxt, -1 , "Menu Habilidades" );
}
public mh_mejoras_inf( index , key )
{
switch( key )
{
case 0 :
{
g_iMejoras[ index ][ g_iIdMejoras[ index ] ] = 1 - g_iMejoras[ index ][ g_iIdMejoras[ index ] ] ;
mejoras_inf( index, g_iIdMejoras[ index ] ) ;
}
case 9 :
{
func_habilities( index ) ;
}
}
return PLUGIN_HANDLED ;
}
public client_putinserver( index )
{
SetPlayerBit( g_bConnected, index );
get_user_name( index, g_szPN[ index ], charsmax( g_szPN[ ] ) );
arrayset( g_iTime[ index ], 0, sizeof( g_iTime[ ] ) );
g_iRangos[ index ] = 0;
set_task( 1.0, "ShowHRangos", index+TASK_HOURS, _, _, .flags = "b" );
func_management( index, LOAD );
}
public client_infochanged( index )
{
if( !is_user_connected( index ) ) return;
static NewName[ 32 ];
get_user_info( index, "name", NewName, 31 );
if( !equal( NewName, g_szPN[ index ] ) )
{
copy( g_szPN[ index ], 31, NewName );
func_management( index, SAVE );
}
}
public client_disconnect( index )
{
remove_task( index + TASK_HOURS );
ClearPlayerBit( g_bConnected, index );
func_management( index, SAVE );
}
public ShowHRangos( taskid )
{
static index; index = HUD_ID;
if( GetPlayerBit( g_bConnected, index ) )
{
if( g_iTime[ index ][ SECS ] >= 59 )
{
g_iTime[ index ][ SECS ] = 0;
g_iTime[ index ][ MINS ]++;
}
else
g_iTime[ index ][ SECS ]++;
if( g_iTime[ index ][ MINS ] >= 59 )
{
g_iTime[ index ][ MINS ] = 0;
g_iTime[ index ][ HOURS ]++;
Range_check( index );
}
}
set_hudmessage( 200, 100, 0, 0.1, 0.03, 1 );
ShowSyncHudMsg( index, g_iHud, "Rango: [ %s ]^n^n[ Tiempo Jugado ]^n[ Segundos: %d ]^n[ Minutos: %d ]^n[ Horas: %d ]",
g_szRangos[ g_iRangos[ index ] ][ RANGE_NAME ], g_iTime[ index ][ SECS ], g_iTime[ index ][ MINS ], g_iTime[ index ][ HOURS ] );
}
public Range_check( index )
{
static Range_Up, iLimit; Range_Up = false;
iLimit = ( GET_SIZE( g_szRangos ) );
if( g_iTime[ index ][ HOURS ] >= g_szRangos[ g_iRangos[ index ] ][ RANGE_REQUIRED ] && g_iRangos[ index ] < iLimit )
{
g_iRangos[ index ] += clamp( 1, 0, iLimit ) ;
Range_Up = true;
}
if( Range_Up )
{
CC( 0, "^4%s a sido promovido a ^1%s", g_szPN[ index ], g_szRangos[ g_iRangos[ index ] ][ RANGE_NAME ] );
func_management( index, 0 );
Range_Up = false;
}
}
public func_management( index, iWhat )
{
switch( iWhat )
{
case LOAD:
{
if( !adv_vault_get_prepare( g_iGuardado, _, g_szPN[ index ] ) )
return;
g_iRangos[ index ] = adv_vault_get_field( g_iGuardado, g_iFields[ FIELD_RANGES ] );
adv_vault_get_field( g_iGuardado, g_iFields[ FIELD_TIMES ], g_iTime[ index ], sizeof ( g_iTime[ ] ) );
}
case SAVE:
{
adv_vault_set_start( g_iGuardado );
adv_vault_set_field( g_iGuardado, g_iFields[ FIELD_TIMES ], g_iTime[ index ] );
adv_vault_set_field( g_iGuardado, g_iFields[ FIELD_RANGES ], g_iRangos[ index ] );
adv_vault_set_end( g_iGuardado, 0, g_szPN[ index ] );
}
}
}
stock CC( index, const input[ ], any:... )
{
static iSayText, sziMsg[ 191 ];
if ( !iSayText )
iSayText = get_user_msgid( "SayText" );
replace_all( sziMsg, 190, "!g", "^4" );
replace_all( sziMsg, 190, "!y", "^1" );
replace_all( sziMsg, 190, "!team", "^3" );
vformat( sziMsg, 190, input, 3 );
message_begin( index ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, iSayText, .player = index );
write_byte( index ? index : 33 );
write_string( sziMsg );
message_end( );
}
Criticas Constructivas y/o Sugerencias.