Raised This Month: $30 Target: $400
 7% 

get_playersnum() help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thisisinfuriating
Junior Member
Join Date: Aug 2018
Old 08-19-2018 , 09:39   get_playersnum() help
Reply With Quote #1

I'm aware of the use of get_playersnum(), but I'm a somewhat a beginner in the world of AMXX

I have a plugin that counts stats(kills/deaths,etc..) and I want to disable it if players are less than 6

Does anyone have an idea how to do it?

I searched this forum for about an hour and didn't find an answer yet, checked far too many plugins too
thisisinfuriating is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-19-2018 , 09:45   Re: get_playersnum() help
Reply With Quote #2

get_playersnum() returns the total number of connected players in a server, you'd have to check the return value of it to check if there's less than 6 players.

PHP Code:
if( get_playersnum( ) < 
Although it doesn't check whether these 6 players are alive, dead or bots. If you want to add more checks, you'll have to use get_players.

Code:
/* Sets indexes of players. * Flags: * "a" - don't collect dead players. * "b" - don't collect alive players. * "c" - skip bots. * "d" - skip real players. * "e" - match with team. * "f" - match with part of name. * "g" - ignore case sensitivity. * "h" - skip HLTV. * Example: Get all alive CTs: get_players(players,num,"ae","CT") */ native get_players(players[32], &num ,const flags[]="", const team[]="");
__________________
edon1337 is offline
thisisinfuriating
Junior Member
Join Date: Aug 2018
Old 08-19-2018 , 09:53   Re: get_playersnum() help
Reply With Quote #3

So should it look like this?

PHP Code:
    get_players(players,num,"ch","")
    
    new 
Players get_playersnum()
    
    if( 
get_playersnum( ) <= ) {
        
        
        return;
    } 
If yes, how do I disable the stats after this?

Last edited by thisisinfuriating; 08-19-2018 at 09:54.
thisisinfuriating is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-19-2018 , 09:58   Re: get_playersnum() help
Reply With Quote #4

Quote:
Originally Posted by thisisinfuriating View Post
So should it look like this?

PHP Code:
    get_players(players,num,"ch","")
    
    new 
Players get_playersnum()
    
    if( 
get_playersnum( ) <= ) {
        
        
        return;
    } 
If yes, how do I disable the stats after this?
1) So are you trying to check the overall number of connected players, or you want them to be custom picked (dead, alive, bot) ?
2) Show the function that disables the stats.
__________________
edon1337 is offline
thisisinfuriating
Junior Member
Join Date: Aug 2018
Old 08-19-2018 , 10:04   Re: get_playersnum() help
Reply With Quote #5

Quote:
Originally Posted by edon1337 View Post
1) So are you trying to check the overall number of connected players, or you want them to be custom picked (dead, alive, bot) ?
2) Show the function that disables the stats.
1) I'm trying to check how many players are in the server to enable stats if the players <= 6
2) Well, that's the problem, I don't have it
thisisinfuriating is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-19-2018 , 10:20   Re: get_playersnum() help
Reply With Quote #6

Quote:
Originally Posted by thisisinfuriating View Post
1) I'm trying to check how many players are in the server to enable stats if the players <= 6
2) Well, that's the problem, I don't have it
Well, you didn't give me a proper answer to any of my questions, how am I supposed to know how to disable something that I don't even have a clue what it does or how it works?
__________________

Last edited by edon1337; 08-19-2018 at 10:20.
edon1337 is offline
thisisinfuriating
Junior Member
Join Date: Aug 2018
Old 08-19-2018 , 10:39   Re: get_playersnum() help
Reply With Quote #7

Oh, I'm so dumb, sorry

Here's the plugin I'm using
PHP Code:

public client_disconnectid ) {
    
g_bLoadedid ] = false;
    
g_iPlayTimeid ] = 0;
    
g_iKillersid ] = 0;
    
g_flHealthid ] = 0.0;
    
g_iArmorid ] = 0;
    
    if( 
g_flDamageid ] > 0.0 ) {
        
AchievementProgressidACH_SANDBAGfloatroundg_flDamageid ] ) );
        
        
g_flDamageid ] = 0.0;
    }
    
    
AddStatsid );
}

public 
Achv_Connect( const id, const iPlayTime, const iConnects ) {
    
g_bLoadedid ] = true;
    
g_bFirstConnectid ] = true;
    
g_iPlayTimeid ] = iPlayTime;
    
    if( 
g_iPlayTimeid ] <= TIME_TO_PLAY_AS_CT && is_user_aliveid ) && cs_get_user_teamid ) == CS_TEAM_CT ) {
        
cs_set_user_teamidCS_TEAM_T );
        
ExecuteHamBHam_CS_RoundRespawnid );
        
    }
}

public 
Achv_Unlock( const id, const iAchievement ) {
    new 
iUserAchs GetUnlocksCountid );

    
    if( 
iUserAchs == g_iTotal )
        
AchievementProgressidACH_OUTLAW_PRESTIGE );
        
    if( 
is_user_aliveid ) ) {
        new 
iOrigin];
        
get_user_originidiOrigin );
        
        
message_beginMSG_PVSSVC_TEMPENTITYiOrigin );
        
write_byteTE_IMPLOSION );
        
write_coordiOrigin] );
        
write_coordiOrigin] );
        
write_coordiOrigin] );
        
write_byte400 );
        
write_byte100 );
        
write_byte);
        
message_end( );
        
        
message_beginMSG_PVSSVC_TEMPENTITYiOrigin );
        
write_byteTE_PARTICLEBURST );
        
write_coordiOrigin] );
        
write_coordiOrigin] );
        
write_coordiOrigin] );
        
write_short300 );
        
write_byte111 ); //
        
write_byte40 );
        
message_end( );
    }
}


public 
EventRoundStart( ) {
    
    
g_bDead false;
    
g_bTerrorWin false;
    
arraysetg_iKills033 );
    
arraysetg_iSpray033 );
    
arrayset_:g_flGuardHealer_:0.033 );
    
g_flRoundStart get_gametime( ) + 60.0;
    
    for( new 
1<= g_iMaxPlayersi++ ) {
        if( 
g_flDamage] > 0.0 ) {
            
AchievementProgressiACH_SANDBAGfloatroundg_flDamage] ) );
            
            
g_flDamage] = 0.0;
        }
    }
}

public 
EventRoundEnd( ) {
    new 
iPlayers32 ], CsTeams:iTeams32 ], iNumiiPlayeriCT;
    
get_playersiPlayersiNum );
    
    for( 
0iNumi++ ) {
        
iPlayer iPlayers];
        
        
iTeams] = cs_get_user_teamiPlayer );
        
        if( 
iTeams] == CS_TEAM_CT )
            
iCT++;
    }
    
    if( 
iCT >= ) {
        new 
Float:flGameTime get_gametime( );
        
        for( 
0iNumi++ ) {
            
iPlayer iPlayers];
            
            switch( 
iTeams] ) {
                case 
CS_TEAM_T: {
                    if( 
g_flRoundStart >= flGameTime )
                        
AchievementProgressiPlayerACH_DESTINATION );
                }
            }
        }
    }
    new 
iCountiCts];
    
get_playersiPlayersiNum );
    for( 
0iNumi++ ) {
        
iPlayer iPlayers];
        
        if( !
is_user_aliveiPlayer )
        || 
is_user_botiPlayer )
        || 
cs_get_user_teamiPlayer ) != CS_TEAM_CT )
            continue;
        
        if( !
g_bOverlifeiPlayer ] )
            
AchievementProgressiPlayerACH_SURVIVOR );
        if( !
g_bTakeDamageiPlayer] )
            
AchievementProgressiPlayerACH_NODMG );
        
        if( 
iCount )
            
iCtsiCount ] = iPlayer;
        
        
iCount++;
    }
    
    if( 
iCount == ) {
        for( 
02i++ )
            
AchievementProgressiCts], ACH_LEFT4DEAD );
    }

With the API
PHP Code:


enum _
:AchievementData {
    
Achv_Name32 ],
    
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 ArrayCreateAchievementData );
    
g_tSqlIndexes   TrieCreate( );
    
    for( 
1<= g_iMaxPlayersi++ )
        
g_aProgress] = ArrayCreate);



public 
plugin_precache( ) {
    
precache_sound"events/task_complete.wav" );
    
}

public 
plugin_end( ) {
    
ArrayDestroyg_aAchievements );
    
TrieDestroyg_tSqlIndexes );
    
    new 
i;
    for( 
1<= g_iMaxPlayersi++ )
        
ArrayDestroyg_aProgress] );
    
    for( 
0Forwardsi++ )
        
DestroyForwardg_iForwards] );
    
    
SQL_FreeHandleg_hSqlTuple );
    
SQL_FreeHandleg_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_authorizedid )
    if( ( 
g_iConnectedid ] |= AUTHORIZED ) & CONNECTED )
        
UserHasBeenAuthorizedid );

public 
client_putinserverid )
    if( !
is_user_botid ) && ( g_iConnectedid ] |= CONNECTED ) & AUTHORIZED )
        
UserHasBeenAuthorizedid );

UserHasBeenAuthorized( const id ) {
    new 
szAuthid40 ], EmptyProgressProgressData ];
    
get_user_authididszAuthid39 );
    
    for( new 
0g_iTotalAchievsi++ )
        
ArraySetArrayg_aProgressid ], iEmptyProgress );
    
    new 
szQuery128 ], szId]; szId] = id;
    
formatexszQuery127"SELECT `Id` FROM `GlobalPlayers` WHERE `SteamId` = '%s'"szAuthid );
    
    
SQL_ThreadQueryg_hSqlTuple"HandlePlayerConnect"szQueryszId);
}


public 
client_disconnectid ) {
    
g_iPlayTimeid ]  = 0;
    
g_iConnectedid ] = 0;
    
    if( !
g_iPlayerIdid ] )
        return;
    
    new 
iPlayTime = ( get_user_timeid ) / 60 ),
        
iSysTime  get_systime);
    
    
    
g_iPlayerIdid ] = 0;
}





AwardAchievement( const id, const iAchievement, const AchievementAchievementData ] ) {

    new 
szName32 ];
    
get_user_nameidszName31 );
    
    
ColorChat0Red"%s %s^1 has earned the achievement^4 %s^1."PrefixszNameAchievementAchv_Name ] );
    
    if( 
is_user_aliveid ) )
        
emit_soundidCHAN_VOICE"events/task_complete.wav"VOL_NORMATTN_NORM0PITCH_NORM );
    else
        
client_cmdid"spk ^"events/task_complete.wav^"" );
    
    new 
iReturn;
    
ExecuteForwardg_iForwardsFwd_Unlock ], iReturnidiAchievement );
}


public 
NativeGetProgress( const iPlugin, const iParams ) {
    new 
id get_param);
    new 
iAchievement get_param);
    
    if( !
IsPlayerid ) ) {
        
log_errorAMX_ERR_BOUNDS"GetProgress: index out of bounds for id (%i)"id );
        return 
0;
    }
    else if( !
IsAchievementiAchievement ) ) {
        
log_errorAMX_ERR_BOUNDS"GetProgress: index out of bounds for iAchievement (%i)"id );
        return 
0;
    }
    
    new 
ProgressProgressData ];
    
ArrayGetArrayg_aProgressid ], iAchievementProgress );
    
    return 
ProgressProgress_Num ];
}

public 
NativeGetUnlocksCount( const iPlugin, const iParams ) {
    new 
id get_param);
    
    if( 
id == ) {
        return 
g_iTotalAchievs;
    }
    else if( !
IsPlayerid ) ) {
        
log_errorAMX_ERR_BOUNDS"GetUnlocksCount: index out of bounds for id (%i)"id );
        return 
0;
    }
    
    return 
UTIL_CountUnlocksid );
}


//-----------------------------------------------------------------------------
// 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);
    new 
iAchievement get_param);
    
    if( !
IsPlayerid ) ) {
        
log_errorAMX_ERR_BOUNDS"SetAchievementComponentBit: index out of bounds for id (%i)"id );
        return;
    }
    else if( !
IsAchievementiAchievement ) ) {
        
log_errorAMX_ERR_BOUNDS"SetAchievementComponentBit: index out of bounds for iAchievement (%i)"id );
        return;
    }
    
    new 
AchievementAchievementData ], ProgressProgressData ];
    
ArrayGetArrayg_aAchievementsiAchievementAchievement );
    
ArrayGetArrayg_aProgressid ], iAchievementProgress );
    

    if( 
ProgressProgress_Num ] >= AchievementAchv_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( ) <= ) { 
         
         
        return; 
    } 
thisisinfuriating is offline
thisisinfuriating
Junior Member
Join Date: Aug 2018
Old 08-19-2018 , 14:06   Re: get_playersnum() help
Reply With Quote #8

PHP Code:
    new id;
    new 
iUserAchs GetUnlocksCountid );
        
    new 
Players[32],iPlayersNum;
    
get_players(Players,iPlayersNum,"ch");
    
    if(
iPlayersNum <= 6)
    {
        if(!
iUserAchs)
        {
            return;
        }
    } 
Is making it like this right?
thisisinfuriating is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-19-2018 , 14:24   Re: get_playersnum() help
Reply With Quote #9

That won't pause anything, so you're trying to pause the entire plugin if there's less than 6 players on the server?
__________________
edon1337 is offline
thisisinfuriating
Junior Member
Join Date: Aug 2018
Old 08-19-2018 , 14:34   Re: get_playersnum() help
Reply With Quote #10

Quote:
Originally Posted by edon1337 View Post
That won't pause anything, so you're trying to pause the entire plugin if there's less than 6 players on the server?
Well, wouldn't that stop it from counting stats if there's less than 6 players, and re-enable it when more or equal to 6 players join?

Last edited by thisisinfuriating; 08-19-2018 at 14:34.
thisisinfuriating is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:53.


Powered by vBulletin®
Copyright ©2000 - 2023, vBulletin Solutions, Inc.
Theme made by Freecode