I suggest that you start with just printing the name when the player is put into the server. Get that working first using client_putinserver(). Then, you can add to printing only to admins by replacing your client_print() with a for loop that goes through all connected players and then calling client_print() only on those that have admin access. I suggest that you look for other plugins and threads where you see get_players() being used, most of these will have an example of how to use it and its results in a for loop.
1. The steam ID will not always be available at client_connect(). I recommend using client_authorized() if you require the steam ID.
2. Your code is written to print to only those who have the specified admin status/flags but then you use 0 in client_print, which prints to everyone. So everyone would see the same print <number of players> number of times. Change this to the player id.
3. Capture the steam id in a global variable so it can be re-used when the player disconnects. No sense in calling a native that returns the same value twice.
4. Your code would not work if the Flag variable held more than 1 flags.
5. I would add "ch" flags to get_players() to exclude bots/HLTV.
6. 'stock' should not be used within a plugin, only include files.
@1M1e - I would avoid printing the 'connecting' and 'connected' messages, use connected only since you are guaranteed to have steam ID at authorized(). It would be annoying to see the same message back to back for each player.
Spoiler
PHP Code:
#include <amxmodx>
#define PLUGIN "ConnectDisconnect Message" #define VERSION "1.0" #define AUTHOR "AlliedMods"
#define MAX_PLAYERS 32
new const Flag[] = "d"; //Change the flag to whatever you want
new g_szAuthID[ MAX_PLAYERS + 1 ][ 34 ];
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR) }
public client_authorized( id ) { new szName[ 32 ] , players[ 32 ], num , iPlayer;
get_user_authid(id, g_szAuthID[ id ] , charsmax( g_szAuthID[] )) get_user_name(id, szName, charsmax(szName)) get_players(players, num , "ch" )
for(new i=0; i<num; i++) { iPlayer = players[ i ] if ( is_admin( iPlayer ) ) { client_print( iPlayer , print_chat , "%s has connected SteamID (%s)" , szName , g_szAuthID[ id ] ); } } }
public client_disconnected(id) { new szName[32] , players[ 32 ] , num , iPlayer;
get_user_name(id, szName, charsmax(szName)) get_players(players, num , "ch" )
for(new i=0; i<num; i++) { iPlayer = players[ i ]
if ( is_admin( iPlayer ) ) { client_print( iPlayer , print_chat , "%s has disconnected SteamID (%s)" , szName , g_szAuthID[ id ] ); } } }
bool:is_admin( id ) { new iFlags = read_flags( Flag );
@1M1e - I would avoid printing the 'connecting' and 'connected' messages, use connected only since you are guaranteed to have steam ID at authorized(). It would be annoying to see the same message back to back for each player.
1. The steam ID will not always be available at client_connect(). I recommend using client_authorized() if you require the steam ID.
2. Your code is written to print to only those who have the specified admin status/flags but then you use 0 in client_print, which prints to everyone. So everyone would see the same print <number of players> number of times. Change this to the player id.
3. Capture the steam id in a global variable so it can be re-used when the player disconnects. No sense in calling a native that returns the same value twice.
4. Your code would not work if the Flag variable held more than 1 flags.
5. I would add "ch" flags to get_players() to exclude bots/HLTV.
6. 'stock' should not be used within a plugin, only include files.
@1M1e - I would avoid printing the 'connecting' and 'connected' messages, use connected only since you are guaranteed to have steam ID at authorized(). It would be annoying to see the same message back to back for each player.
Spoiler
PHP Code:
#include <amxmodx>
#define PLUGIN "ConnectDisconnect Message" #define VERSION "1.0" #define AUTHOR "AlliedMods"
#define MAX_PLAYERS 32
new const Flag[] = "d"; //Change the flag to whatever you want
new g_szAuthID[ MAX_PLAYERS + 1 ][ 34 ];
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR) }
public client_authorized( id ) { new szName[ 32 ] , players[ 32 ], num , iPlayer;
get_user_authid(id, g_szAuthID[ id ] , charsmax( g_szAuthID[] )) get_user_name(id, szName, charsmax(szName)) get_players(players, num , "ch" )
for(new i=0; i<num; i++) { iPlayer = players[ i ] if ( is_admin( iPlayer ) ) { client_print( iPlayer , print_chat , "%s has connected SteamID (%s)" , szName , g_szAuthID[ id ] ); } } }
public client_disconnected(id) { new szName[32] , players[ 32 ] , num , iPlayer;
get_user_name(id, szName, charsmax(szName)) get_players(players, num , "ch" )
for(new i=0; i<num; i++) { iPlayer = players[ i ]
if ( is_admin( iPlayer ) ) { client_print( iPlayer , print_chat , "%s has disconnected SteamID (%s)" , szName , g_szAuthID[ id ] ); } } }
bool:is_admin( id ) { new iFlags = read_flags( Flag );
Yeah I know about all those issues, I literally just copied his code and added the flag thing, figured hey if it worked so far why would it not work anymore.
Anyways, thanks for pointing those things out.