Junior Member
|
08-19-2018
, 09:39
Re: get_playersnum() help
|
#7
|
Oh, I'm so dumb, sorry
Here's the plugin I'm using
PHP Code:
public client_disconnect( id ) {
g_bLoaded[ id ] = false;
g_iPlayTime[ id ] = 0;
g_iKillers[ id ] = 0;
g_flHealth[ id ] = 0.0;
g_iArmor[ id ] = 0;
if( g_flDamage[ id ] > 0.0 ) {
AchievementProgress( id, ACH_SANDBAG, floatround( g_flDamage[ id ] ) );
g_flDamage[ id ] = 0.0;
}
AddStats( id );
}
public Achv_Connect( const id, const iPlayTime, const iConnects ) {
g_bLoaded[ id ] = true;
g_bFirstConnect[ id ] = true;
g_iPlayTime[ id ] = iPlayTime;
if( g_iPlayTime[ id ] <= TIME_TO_PLAY_AS_CT && is_user_alive( id ) && cs_get_user_team( id ) == CS_TEAM_CT ) {
cs_set_user_team( id, CS_TEAM_T );
ExecuteHamB( Ham_CS_RoundRespawn, id );
}
}
public Achv_Unlock( const id, const iAchievement ) {
new iUserAchs = GetUnlocksCount( id );
if( iUserAchs == g_iTotal )
AchievementProgress( id, ACH_OUTLAW_PRESTIGE );
if( is_user_alive( id ) ) {
new iOrigin[ 3 ];
get_user_origin( id, iOrigin );
message_begin( MSG_PVS, SVC_TEMPENTITY, iOrigin );
write_byte( TE_IMPLOSION );
write_coord( iOrigin[ 0 ] );
write_coord( iOrigin[ 1 ] );
write_coord( iOrigin[ 2 ] );
write_byte( 400 );
write_byte( 100 );
write_byte( 7 );
message_end( );
message_begin( MSG_PVS, SVC_TEMPENTITY, iOrigin );
write_byte( TE_PARTICLEBURST );
write_coord( iOrigin[ 0 ] );
write_coord( iOrigin[ 1 ] );
write_coord( iOrigin[ 2 ] );
write_short( 300 );
write_byte( 111 ); //
write_byte( 40 );
message_end( );
}
}
public EventRoundStart( ) {
g_bDead = false;
g_bTerrorWin = false;
arrayset( g_iKills, 0, 33 );
arrayset( g_iSpray, 0, 33 );
arrayset( _:g_flGuardHealer, _:0.0, 33 );
g_flRoundStart = get_gametime( ) + 60.0;
for( new i = 1; i <= g_iMaxPlayers; i++ ) {
if( g_flDamage[ i ] > 0.0 ) {
AchievementProgress( i, ACH_SANDBAG, floatround( g_flDamage[ i ] ) );
g_flDamage[ i ] = 0.0;
}
}
}
public EventRoundEnd( ) {
new iPlayers[ 32 ], CsTeams:iTeams[ 32 ], iNum, i, iPlayer, iCT;
get_players( iPlayers, iNum );
for( i = 0; i < iNum; i++ ) {
iPlayer = iPlayers[ i ];
iTeams[ i ] = cs_get_user_team( iPlayer );
if( iTeams[ i ] == CS_TEAM_CT )
iCT++;
}
if( iCT >= 3 ) {
new Float:flGameTime = get_gametime( );
for( i = 0; i < iNum; i++ ) {
iPlayer = iPlayers[ i ];
switch( iTeams[ i ] ) {
case CS_TEAM_T: {
if( g_flRoundStart >= flGameTime )
AchievementProgress( iPlayer, ACH_DESTINATION );
}
}
}
}
new iCount, iCts[ 2 ];
get_players( iPlayers, iNum );
for( i = 0; i < iNum; i++ ) {
iPlayer = iPlayers[ i ];
if( !is_user_alive( iPlayer )
|| is_user_bot( iPlayer )
|| cs_get_user_team( iPlayer ) != CS_TEAM_CT )
continue;
if( !g_bOverlife[ iPlayer ] )
AchievementProgress( iPlayer, ACH_SURVIVOR );
if( !g_bTakeDamage[ iPlayer] )
AchievementProgress( iPlayer, ACH_NODMG );
if( iCount < 2 )
iCts[ iCount ] = iPlayer;
iCount++;
}
if( iCount == 4 ) {
for( i = 0; i < 2; i++ )
AchievementProgress( iCts[ i ], ACH_LEFT4DEAD );
}
}
With the API
PHP Code:
enum _:AchievementData {
Achv_Name[ 32 ],
Achv_NeededToGain,
Achv_ProgressModule,
Achv_SqlIndex
};
enum _:ProgressData {
Progress_Num,
Progress_Bits
};
enum _:Forwards {
Fwd_Connect,
Fwd_Unlock
};
public plugin_init( ) {
register_plugin( "Achievements API", "3.0", "xPaw" );
register_dictionary( "time.txt" );
g_iMaxPlayers = get_maxplayers( );
g_aAchievements = ArrayCreate( AchievementData );
g_tSqlIndexes = TrieCreate( );
for( i = 1; i <= g_iMaxPlayers; i++ )
g_aProgress[ i ] = ArrayCreate( 2 );
public plugin_precache( ) {
precache_sound( "events/task_complete.wav" );
}
public plugin_end( ) {
ArrayDestroy( g_aAchievements );
TrieDestroy( g_tSqlIndexes );
new i;
for( i = 1; i <= g_iMaxPlayers; i++ )
ArrayDestroy( g_aProgress[ i ] );
for( i = 0; i < Forwards; i++ )
DestroyForward( g_iForwards[ i ] );
SQL_FreeHandle( g_hSqlTuple );
SQL_FreeHandle( g_hSqlConnection );
}
public plugin_natives( ) {
register_library( "Achievements" );
register_native( "SetAchievementComponentBit", "NativeSetComponentBit" );
register_native( "RegisterAchievement", "NativeRegisterAchievement" );
register_native( "AchievementProgress", "NativeAchievementProgress" );
register_native( "HaveAchievement", "NativeHaveAchievement" );
register_native( "GetProgress", "NativeGetProgress" );
register_native( "GetUnlocksCount", "NativeGetUnlocksCount" );
register_native( "SetLeaderBoard", "NativeSetLeaderBoard" );
register_native( "GetPlayerId", "NativeGetPlayerId" );
}
public client_authorized( id )
if( ( g_iConnected[ id ] |= AUTHORIZED ) & CONNECTED )
UserHasBeenAuthorized( id );
public client_putinserver( id )
if( !is_user_bot( id ) && ( g_iConnected[ id ] |= CONNECTED ) & AUTHORIZED )
UserHasBeenAuthorized( id );
UserHasBeenAuthorized( const id ) {
new szAuthid[ 40 ], EmptyProgress[ ProgressData ];
get_user_authid( id, szAuthid, 39 );
for( new i = 0; i < g_iTotalAchievs; i++ )
ArraySetArray( g_aProgress[ id ], i, EmptyProgress );
new szQuery[ 128 ], szId[ 1 ]; szId[ 0 ] = id;
formatex( szQuery, 127, "SELECT `Id` FROM `GlobalPlayers` WHERE `SteamId` = '%s'", szAuthid );
SQL_ThreadQuery( g_hSqlTuple, "HandlePlayerConnect", szQuery, szId, 1 );
}
public client_disconnect( id ) {
g_iPlayTime[ id ] = 0;
g_iConnected[ id ] = 0;
if( !g_iPlayerId[ id ] )
return;
new iPlayTime = ( get_user_time( id ) / 60 ),
iSysTime = get_systime( 0 );
g_iPlayerId[ id ] = 0;
}
AwardAchievement( const id, const iAchievement, const Achievement[ AchievementData ] ) {
new szName[ 32 ];
get_user_name( id, szName, 31 );
ColorChat( 0, Red, "%s %s^1 has earned the achievement^4 %s^1.", Prefix, szName, Achievement[ Achv_Name ] );
if( is_user_alive( id ) )
emit_sound( id, CHAN_VOICE, "events/task_complete.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
else
client_cmd( id, "spk ^"events/task_complete.wav^"" );
new iReturn;
ExecuteForward( g_iForwards[ Fwd_Unlock ], iReturn, id, iAchievement );
}
public NativeGetProgress( const iPlugin, const iParams ) {
new id = get_param( 1 );
new iAchievement = get_param( 2 );
if( !IsPlayer( id ) ) {
log_error( AMX_ERR_BOUNDS, "GetProgress: index out of bounds for id (%i)", id );
return 0;
}
else if( !IsAchievement( iAchievement ) ) {
log_error( AMX_ERR_BOUNDS, "GetProgress: index out of bounds for iAchievement (%i)", id );
return 0;
}
new Progress[ ProgressData ];
ArrayGetArray( g_aProgress[ id ], iAchievement, Progress );
return Progress[ Progress_Num ];
}
public NativeGetUnlocksCount( const iPlugin, const iParams ) {
new id = get_param( 1 );
if( id == 0 ) {
return g_iTotalAchievs;
}
else if( !IsPlayer( id ) ) {
log_error( AMX_ERR_BOUNDS, "GetUnlocksCount: index out of bounds for id (%i)", id );
return 0;
}
return UTIL_CountUnlocks( id );
}
//-----------------------------------------------------------------------------
// Purpose: sets the specified component bit # if it is not already.
// If it does get set, evaluate if this satisfies an achievement
// Function was found in Steam API :-)
//-----------------------------------------------------------------------------
public NativeSetComponentBit( const iPlugin, const iParams ) {
new id = get_param( 1 );
new iAchievement = get_param( 2 );
if( !IsPlayer( id ) ) {
log_error( AMX_ERR_BOUNDS, "SetAchievementComponentBit: index out of bounds for id (%i)", id );
return;
}
else if( !IsAchievement( iAchievement ) ) {
log_error( AMX_ERR_BOUNDS, "SetAchievementComponentBit: index out of bounds for iAchievement (%i)", id );
return;
}
new Achievement[ AchievementData ], Progress[ ProgressData ];
ArrayGetArray( g_aAchievements, iAchievement, Achievement );
ArrayGetArray( g_aProgress[ id ], iAchievement, Progress );
if( Progress[ Progress_Num ] >= Achievement[ Achv_NeededToGain ] )
return;
return;
}
}
It's written originally by xPaw, and he's not offering any help with his works afaik.
I guess adding this to public EventRoundStart and EventRoundEnd with the function to stop it, should do the work right?
PHP Code:
get_players(players,num,"ch","")
new Players = get_playersnum()
if( get_playersnum( ) <= 6 ) {
return;
}
|
|