[Help]Command /Activity
#2

Unfortunately with each calling of that command you have to generate that list anew (you could do that with y_iterate, and shift players accordingly when someone disconnects). You could also cache the result to not recalculate each time, maybe with 10 seconds delay. Anyway: first fix your indentation. Remove redundant code. Notice that there is no pConnectTime present, and add that. Then grab this sorting include, as you have to sort array by player online times.
The result is something like this:

pawn Код:
#define DIALOG_ACTIVITY (13)

enum pInfo
{
    pMinutes,
    pHours,
    pSeconds,
    pConnectTime
};

new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerConnect(playerid)
{
    PlayerInfo[playerid][pConnectTime] = gettime();
}

CMD:test(playerid,params[])
{
    new
        playerOnlineTimes[MAX_PLAYERS][2],
        currentTime = gettime(), //might be off by fraction of a second for many players
        i = 0
    ;

    foreach(Player, pid)
    {
        if(Prijavljen[pid])
        {
            playerOnlineTimes[i][0] = pid;
            playerOnlineTimes[i][1] = clamp(currentTime - PlayerInfo[pid][pConnectTime], 0);
            i++;
        }
    }

    SortDeepArray(playerOnlineTimes, 1, .order = SORT_DESC);

    new mins, hour, day;
    new aktivnost[2048];

    format(aktivnost, sizeof aktivnost, "%s{FF0000}|----------------------------------------------------------------------|\n\n");

    for(new place = 0; place != 30)
    {
        if (0 == playerOnlineTimes[i][1]) {
            //We don't want players with 0 seconds played
            //Also we can't trust [0], because we didn't set it to INVALID_PLAYER_ID
            //And I don't want to explain memset here
            break;
        }
        ConvertTime(playerOnlineTimes[i][1], mins, hour, day);
        format(aktivnost, sizeof aktivnost, "%s{FFFFFF}%d.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n", aktivnost, i + 1, /* Maybe get player name here */, day, hour, mins, playerOnlineTimes[i][1]);    
    }

    format(aktivnost, sizeof aktivnost, "%s{FF0000}|----------------------------------------------------------------------|\n\n");

    ShowPlayerDialog(playerid, DIALOG_ACTIVITY, DIALOG_STYLE_MSGBOX, "{FF0000}GAMING {FFFFFF} Top Lista 30 sa najvise ne-afk vreme na serveru", aktivnost, "OK", "OK");
    return 1;
}
Reply


Messages In This Thread
[Help]Command /Activity - by Markoni990 - 07.03.2015, 14:48
Re: [Help]Command /Activity - by Misiur - 07.03.2015, 16:37
Respuesta: [Help]Command /Activity - by Markoni990 - 07.03.2015, 17:11
Re: [Help]Command /Activity - by Misiur - 07.03.2015, 17:32
Respuesta: [Help]Command /Activity - by Markoni990 - 07.03.2015, 17:44
Re: [Help]Command /Activity - by Misiur - 07.03.2015, 17:47
Respuesta: [Help]Command /Activity - by Markoni990 - 07.03.2015, 17:50
Re: [Help]Command /Activity - by Misiur - 07.03.2015, 17:53
Respuesta: [Help]Command /Activity - by Markoni990 - 07.03.2015, 17:57
Respuesta: [Help]Command /Activity - by Markoni990 - 07.03.2015, 22:51

Forum Jump:


Users browsing this thread: 1 Guest(s)