Looping through offline players
#1

So, I've been working on a gamemode for like 2-3 weeks and I suddenly got stuck.
I created a dynamic faction system now I want to create some commands for it.

Whenever a player joins a faction, It saves player's faction ID in his variables,
I want to loop through offline players to check their group's ID in order to list them into a dialog

PHP код:
CMD:members(playeridparams[])
{
    new 
userlist[MAX_PLAYERS];
    new 
name[MAX_PLAYER_NAME];
    if(
PlayerVar[playerid][GroupRank] > 5)
    {
        for(new 
iMAX_PLAYERSi++) {
            if(
PlayerVar[i][Group] == PlayerVar[playerid][Group]){
                new 
string[256];
                
GetPlayerName(inamesizeof(name));
                
format(stringsizeof(string), "{068481}%s{FFFFFF} - Rank %d"namePlayerVar[i][GroupRank]);
                
strcat(userliststring);
            }
        }
    }
    return 
ShowPlayerDialog(playerid97DIALOG_STYLE_LIST"UXG RPG: Members"userlist"OK""Cancel");

At this moment the command's only listing online players.

Is it possible to list offline players aswell?
Reply
#2

You should store offline players data somewhere. If player #1 quit the server, his ID will be taken by another player who enters server right after him, and offline player data will be overwritten with data of new player.

Yes, it is possible to list offline players - read them from database or other place where you store all players data
Reply
#3

Obviously you can't use MAX_PLAYERS to loop thru all accounts (It's a keyword ... accounts != online in-game players)
It's easily achievable in mysql thru SELECT `username` WHERE `faction`=%i >(faction ID)
but super resource-heavy thru ini, so don't try if you have INI or save player's names for each faction in a different file.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)