I am trying to keep the list of players in my server with details on them as follows:
PHP Code:
playerName : newplayerName : IP address
I initialized a 2d array as follows:
PHP Code:
new players[32][3];
The Functions are pretty self explanatory:
PHP Code:
// ----------------------------------------------------------------------------
// ------------------------Add details to playerlist---------------------------
public add_players(id) {
new ip[16];
new playerName[32]
// Get the name and ip
get_user_name(id, playerName, 31);
get_user_ip(id, ip, 15, 1/*no port*/);
// Add these to our array using id as key
format(players[id - 1][0], strlen(playerName), "%s", playerName);
format(players[id - 1][1], strlen(playerName), "%s", playerName);
format(players[id - 1][2], 15, "%s", ip);
}
// ----------------------------------------------------------------------------
// -----------------------Record new name for Player---------------------------
public client_infochanged(id) {
new new_name[32];
new old_name[32];
get_user_info(id, "name", new_name, 31);
get_user_name(id, old_name, 31);
if(!equal(new_name, old_name)){
// Put his new name in details :)
format(players[id - 1][1], sizeof(new_name), "%s", new_name);
}
}
// ----------------------------------------------------------------------------
// -----------------------Delete old player details---------------------------
public del_players(id) {
format(players[id - 1][0], 32, "[none]");
format(players[id - 1][1], 32, "[none]");
format(players[id - 1][2], 16, "PLAYER_LEFT");
}
// ----------------------------------------------------------------------------
// --------------------Detect when a client disconnects-------------------------
public client_disconnect(id) {
del_players(id);
}
// ----------------------------------------------------------------------------
// --------------------List all players on server :)-------------------------
public list_players(id) {
client_print(id, print_chat, "Check console for Players' Details")
for (new i=0; i<sizeof(players); i++)
{
console_print(id, "%s : %s : %s", players[i][0], players[i][1], players[i][2])
}
}
My issue is when I call list_players as clcmd (client command e.g "say /players"), I get the following output in the players console:
PHP Code:
tt127.0.0.1 : t127.0.0.1 : 127.0.0.1
27.0.0.1 : 7.0.0.1 : .0.0.1
0.0.1 : .0.1 : 0.1
.1 : 1 :
: :
: :
Why does the output appear so strangely? Am I doing something wrong?
The ideal output I'm needing should be:
PHP Code:
test123 : test123 : 127.0.0.1
Thanks guys..
__________________