Offline and Online Members
#1

How can i create something like this, when leader types /allmembers or something like that something like this shows up:




So basically it shows up all players that are in organisation/faction and shows if they're online or offline.


I'm using mysql.
Reply
#2

Anyone ?
Reply
#3

You can do this either by account/user id or username.
Fetch the member list and get the neccesary data (account/user id or username) after then run a loop through all online players and check if their account id / username matches, if it does then this member is connected.

Then collect all of that data and run another loop at the end (seperated) which will output all the members and at the end of the format you can use ternary operator (online==1 ? "online" : "offline").

Hope you understood
Reply
#4

Actually no, I'm new to pwn, only know php so far
Reply
#5

anyone ?
Reply
#6

Are you using MySQL or .ini? You need to be more descriptive when asking for help.
Reply
#7

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Are you using MySQL or .ini? You need to be more descriptive when asking for help.
He clearly mentioned MySQL bruh
Reply
#8

Quote:
Originally Posted by Mark_Weston
Посмотреть сообщение
He clearly mentioned MySQL bruh
Didn't notice. Lmao.

On-Topic:
This should help. Change it to fit with your system/variables.

pawn Код:
mysql_format(MySQLCon, query, sizeof(query), "SELECT * FROM `players` WHERE `faction` = '%d'", pInfo[playerid][faction]);
mysql_tquery(MySQLCon, query, "", "");
new numrows = cache_get_rows();
new username[MAX_PLAYER_NAME], string[128];
if(numrows > 0)
{
     for(new i; i < numrows; i++)
     {
           cache_get_field_content(i, "Username", username, 1, sizeof(username));
           if(ReturnUser(username)) {
            format(string, sizeof(string), "%s[ONLINE]", username);
            return SendClientMessage(playerid, -1, string);
           }
           format(string, sizeof(string), "%s[OFFLINE]", username);
           SendClientMessage(playerid, -1, string);
     }
}
This should work how-ever I did it fast so it might have mistakes.
Reply
#9

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Didn't notice. Lmao.

On-Topic:
This should help. Change it to fit with your system/variables.

pawn Код:
mysql_format(MySQLCon, query, sizeof(query), "SELECT * FROM `players` WHERE `faction` = '%d'", pInfo[playerid][faction]);
mysql_tquery(MySQLCon, query, "", "");
new numrows = cache_get_rows();
new username[MAX_PLAYER_NAME], string[128];
if(numrows > 0)
{
     for(new i; i < numrows; i++)
     {
           cache_get_field_content(i, "Username", username, 1, sizeof(username));
           if(ReturnUser(username)) {
            format(string, sizeof(string), "%s[ONLINE]", username);
            return SendClientMessage(playerid, -1, string);
           }
           format(string, sizeof(string), "%s[OFFLINE]", username);
           SendClientMessage(playerid, -1, string);
     }
}
This should work how-ever I did it fast so it might have mistakes.
How about SQLite?
Reply
#10

Quote:
Originally Posted by xiaoniao
Посмотреть сообщение
How about SQLite?
Basically, it should be very much the same, SQLite uses the same programming language(SQL) just has some different function names.

I don't really use SQLite alot, but this should work:
pawn Код:
CMD:allmembers(playerid, params[])
{
    new query[128], DBResult: result;
    format(query, sizeof(query), "SELECT * FROM `Igraci` WHERE `Clan` = '%d'", PI[playerid][Clan]);
    result = db_query(dbHandle, query);

    SCM(playerid, GREY, "** Svi Clanovi **");
    new username[MAX_PLAYER_NAME], rank, str[25];

    new numrows = db_num_rows(result);

    if(numrows)
    {
        for(new i; i < numrows; i++)
        {
            db_get_field_assoc(i, "Ime", username, sizeof(username));
            db_get_field_assoc(i, "Rank", str, sizeof(str));

            rank = strval(str);
            if(rank == 0) { str = "[RANK - Susp.]"; }
            else if(rank == 1) { str = "[RANK - 1]"; }
            else if(rank == 2) { str = "[RANK - 2]"; }
            else if(rank == 3) { str = "[RANK - 3]"; }
            else if(rank == 4) { str = "[RANK - 4]"; }
            else if(rank == 5) { str = "[RANK - SUB-LEADER]"; }
            else if(rank == 6) { str = "[RANK - LEADER]"; }

            if(ReturnUser(username) != INVALID_PLAYER_ID)
            {
                return SCMF(playerid, WHITE, "%s [%s] {00C0FF}[ONLINE]", username, str);
            }
            SCMF(playerid, WHITE, "%s [%s] {F81414}[OFFLINE]", username, str);
         }
    }
   
    db_free_result(result);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)