Raised This Month: $ Target: $400
 0% 

Return player name ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hildegaard
New Member
Join Date: Jun 2007
Old 06-23-2007 , 13:24   Return player name ?
Reply With Quote #1

1st of all, im a newbie when it comes to plugin coding, so i need help with something here. The target of my plugin is to save, in a text file, the list of players playing on the server, so i can retrieve it with another script somewhere else. The problem is that apparently (and excuse my ignorance) get_players doesnt actually return the names of the players but some kind of index.
My problem is that im saving these indexes in the file instead of the names, and i have no idea whats the function to get the playernames. Can anyone give me a hand here?

Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Unline^^ Server Stats"
#define VERSION "1.0"
#define AUTHOR "Onyx"

public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR);
    
    set_task(5.0, "SavePlayers", 33,_,_,"b");
}

public SavePlayers(id) {
    new file[129];
    new iPlayers[32];
    new iNum;
    new message[100];

    get_datadir(file, 128);
    format(file, 128, "%2/playerlist.txt", file);

    if (file_exists(file)) {
        delete_file(file);
    }

    iNum = get_playersnum();
    get_players(iPlayers, iNum);

    for(new i=0;i<iNum;i++) {
    
        format(message, 50, "%s", iPlayers[i]);
        write_file(file, message);
    }
}
Thanks in advanced
Bruno
Hildegaard is offline
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 06-23-2007 , 13:49   Re: Return player name ?
Reply With Quote #2

The index is what you'd see if you were to type status in console.

Code:
    new name[32];     get_players(iPlayers, iNum);     for(new i=0; i<iNum; i++)     {         get_user_name(iPlayers[i], name, 31);         write_file(file, name);     }
Code:
//this is unnecessary as get_players() will do this for you iNum = get_playersnum();
When writing strings the len parameter is the maximum size of the buffer excluding the null terminator.

You also don't need to assign an ID to a set_tasK() unless you plan on removing it at a later stage.

Last edited by Lee; 06-23-2007 at 14:04.
Lee is offline
kmal2t
BANNED
Join Date: Apr 2006
Old 06-23-2007 , 13:58   Re: Return player name ?
Reply With Quote #3

There's actually no need for this plugin. Just go get HLSW and when you log on you can go in settings > settings > misc (tab) and select autoadd player name. Then when you want to see it just hit ctrl+w and you'll get a nice formatted list of the player his steamid and all his names which you can also edit easily. Also when people join you can look in HLSW and see their other names right next to the name. If you do decide to use that plugin above there's no need for a loop as you can just do it in public client_connect(id)
kmal2t is offline
Hildegaard
New Member
Join Date: Jun 2007
Old 06-23-2007 , 15:30   Re: Return player name ?
Reply With Quote #4

Thank you very much, got it working.
Hildegaard 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 21:27.


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