Raised This Month: $ Target: $400
 0% 

[SOLVED]Enum players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 04-24-2007 , 09:25   [SOLVED]Enum players
Reply With Quote #1

Hi.I have this plugin which show's how many players have steam...

Ex: "On server are 3 players with steam!"...but i want to add something to show their names too...but dunno! to look somehting like this "On server are 3 players with steam!(Alka,LoL,Jhon)!"


Thanks
Attached Files
File Type: sma Get Plugin or Get Source (steam_players.sma - 625 views - 824 Bytes)
__________________
Still...lovin' . Connor noob! Hello

Last edited by Alka; 04-24-2007 at 14:54.
Alka is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-24-2007 , 10:39   Re: Enum players
Reply With Quote #2

I would do like this :

Code:
#include <amxmodx> #define PLUGIN  "Steam players" #define VERSION "1.0" #define AUTHOR  "Alka" new showsteamplayers; public plugin_init() {     register_plugin( PLUGIN, VERSION, AUTHOR );     register_clcmd( "say /steamppl", "Cmd_Steamppl" );         showsteamplayers = register_cvar( "amx_showsteamplayers", "1" ); } public Cmd_Steamppl( id ) {     if( !get_pcvar_num( showsteamplayers ) )         return PLUGIN_HANDLED;         new pid, iNum, count;     static iPlayers[32], userName[32], authid[12], lstUserName[192];         get_players( iPlayers, iNum, "a" );         for( new i = 0; i < iNum; i++ )     {         pid = iPlayers[i];                 get_user_authid( pid, authid, 11 );                 if( authid[8] == '1' || authid[8] == '0' )  // "STEAM_0:1" or "STEAM_0:0"         {             get_user_name( pid, userName, 31 );                         // -- 'Myname'  become  'Myname, ' or 'Myname.' if end.             format( userName, 31, "%s%s", userName, i < iNum - 1 ? ", " : "." );                         // -- Concatenates string. Ie : 'Myname1, Myname2'             strcat( lstUserName, userName, 191 );                         count++;         }     }         client_print( id, print_chat, "On server %s %d player%s with STEAM!", count == 1 ? "is" : "are", count, count == 1 ? "" : "s");     client_print( id, print_chat, "Full list: %s", lstUserName );         return PLUGIN_HANDLED; }


Now as an improvement, it would be safe to check each username length to not be out of chat limits through multiple print_chat() if necessary.
__________________

Last edited by Arkshine; 04-24-2007 at 10:42.
Arkshine is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 04-24-2007 , 12:53   Re: Enum players
Reply With Quote #3

Thanks...but is not working properly ! When i type first time /steamppl is showing "Full List:Alka." if i type again is showing "Full List:Alka.Alka" if i type again "Full List:Alka.Alka.Alka" ! can you fix this?

Thanks...
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-24-2007 , 13:19   Re: Enum players
Reply With Quote #4

Because 'static' on lstUserName is using, I think.

Try to put : lstUserName[0] = '^0'; to reset this array.

Code:
#include <amxmodx> #define PLUGIN  "Steam players" #define VERSION "1.0" #define AUTHOR  "Alka" new showsteamplayers; public plugin_init() {     register_plugin( PLUGIN, VERSION, AUTHOR );     register_clcmd( "say /steamppl", "Cmd_Steamppl" );         showsteamplayers = register_cvar( "amx_showsteamplayers", "1" ); } public Cmd_Steamppl( id ) {     if( !get_pcvar_num( showsteamplayers ) )         return PLUGIN_HANDLED;         new pid, iNum, count;     static iPlayers[32], userName[32], authid[12], lstUserName[192];         lstUserName[0] = '^0';         get_players( iPlayers, iNum );         for( new i = 0; i < iNum; i++ )     {         pid = iPlayers[i];                 get_user_authid( pid, authid, 11 );                 if( authid[8] == '1' || authid[8] == '0' /*||  authid[6] == 'N'*/)  // "STEAM_0:1" or "STEAM_0:0"         {             get_user_name( pid, userName, 31 );                         // -- 'Myname'  become  'Myname, ' or 'Myname.' if end.             format( userName, 31, "%s%s", userName, i < iNum - 1 ? ", " : "" );                         // -- Concatenates string. Ie : 'Myname1, Myname2'             strcat( lstUserName, userName, 191 );                         count++;         }     }         client_print( id, print_chat, "On server %s %d player%s with STEAM!", count == 1 ? "is" : "are", count, count == 1 ? "" : "s");         if( count > 0 )         client_print( id, print_chat, "Full list: %s", lstUserName );         return PLUGIN_HANDLED; }
__________________
Arkshine is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 04-24-2007 , 14:54   Re: Enum players
Reply With Quote #5

Thanks arkshine now it's working!...
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-25-2007 , 09:08   Re: [SOLVED]Enum players
Reply With Quote #6

For that :

Quote:
it would be safe to check each username length to not be out of chat limits through multiple print_chat() if necessary.
New code:

Code:
#include <amxmodx> #define PLUGIN  "Steam players" #define VERSION "1.0" #define AUTHOR  "Alka" #define CHAT_MAX_PRINT  10 #define CHAT_LEN_MAX    106 new lstSteam[CHAT_MAX_PRINT][CHAT_LEN_MAX] new g_txtFullList[]     = "Full list:" new g_txtFullListNext[] = "(next):" new g_txtFullListEnd[]  = "(end):" new g_txtSeparation[]   = ", " new showsteamplayers; public plugin_init() {     register_plugin( PLUGIN, VERSION, AUTHOR );     register_clcmd( "say /steamppl", "Cmd_Steamppl" );         showsteamplayers = register_cvar( "amx_showsteamplayers", "1" ); } public Cmd_Steamppl( id ) {     if( !get_pcvar_num( showsteamplayers ) )         return PLUGIN_HANDLED;         new pid, iNum, count, nTab ,lenUserName;     static iPlayers[32], userName[32], authid[12];         for( new i = 0; i < CHAT_MAX_PRINT; i++ )   // clean up array         lstSteam[i][0] = '^0';         get_players( iPlayers, iNum );     for( new i = 0; i < iNum; i++ )     {         pid = iPlayers[i];                 get_user_authid( pid, authid, 11 );                 if( authid[8] == '1' || authid[8] == '0' /*||  is_user_bot( pid )*/ )  // "STEAM_0:1" or "STEAM_0:0"         {             get_user_name( pid, userName, 31 );                         format( userName, 31, "%s%s", userName, i < iNum - 1 ? g_txtSeparation : "." );             lenUserName = strlen( userName );                     if( ( strlen( lstSteam[nTab] ) + lenUserName > CHAT_LEN_MAX - 1 ) )                 nTab++;             strcat( lstSteam[nTab], userName, CHAT_LEN_MAX - 1 );             count++;         }     }         client_print( id, print_chat, "On server %s %d player%s with STEAM!", count == 1 ? "is" : "are", count, count == 1 ? "" : "s");         client_print( id, print_chat, "%s %s", g_txtFullList, lstSteam[0] );             if( nTab > 0 )     {         for( new i = 1; i <= nTab; i++ )             client_print( id, print_chat, "%s %s %s", g_txtFullList, i < nTab - 1 ? g_txtFullListNext : g_txtFullListEnd, lstSteam[i] );     }         return PLUGIN_HANDLED; }
__________________

Last edited by Arkshine; 04-25-2007 at 10:05. Reason: Forget to modify a line
Arkshine is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 04-25-2007 , 09:18   Re: [SOLVED]Enum players
Reply With Quote #7

^^!! Thanks...this is perfect! +k
__________________
Still...lovin' . Connor noob! Hello

Last edited by Alka; 04-25-2007 at 09:23.
Alka is offline
Reply



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 06:37.


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