[Help]Command /Activity
#1

there is any way to record the total played time for each player and showing into activity top 30 player?
I write /activity : The most active players on server no afk
Total time played: XX days / XX minutes / XX seconds
Thanks.


Код:
enum pInfo
{
 	pMinutes,
	pHours,
	pSeconds,
};

new PlayerInfo[MAX_PLAYERS][pInfo];

Cуdigo:

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

Cуdigo:

CMD:test(playerid,params[])
{
foreach(Player,i)
{
if(Prijavljen[i]==1)
{
prvomjestoigrac=i;
}
}
new mins, hour, day;
new seconds = gettime() - PlayerInfo[playerid][pConnectTime];
new aktivnost[2024];

format(aktivnost,2024,"%s{FF0000}|----------------------------------------------------------------------|\n\n");
format(aktivnost,2024,"%s{FFFFFF}1.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}2.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}3.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}4.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}5.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}6.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}7.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}8.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}9.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}10.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}11.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}12.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}13.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}14.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}15.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}16.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}17.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}18.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}19.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}20.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}21.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}22.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}23.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}24.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}25.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}26.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}27.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}28.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}29.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FFFFFF}30.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n",aktivnost,prvomjestoigrac,ConvertTime(seconds,mins,hour,day));
format(aktivnost,2024,"%s{FF0000}|----------------------------------------------------------------------|\n\n");
ShowPlayerDialog(playerid, 13, DIALOG_STYLE_MSGBOX,"{FF0000}GAMING {FFFFFF} Top Lista 30 sa najvise ne-afk vreme na serveru",aktivnost,"OK","OK");
return 1; }
Reply
#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
#3

PHP код:
for(new place 0place != 30
PHP код:
C:\Users\HOME\Downloads\samp03z_svr_R1_win32\gamemodes\FAIRPLAY GAMING 05.02.2015\Bacrup\New folder\bacrup\ss.pwn(42719) : error 001expected token";"but found ")" 
Show the name of the player
PHP код:
format(aktivnostsizeof aktivnost"%s{FFFFFF}%d.%s:%d dana %d h %d min %d sec\n"aktivnost1place,dayhourminsplayerOnlineTimes[i][1]); 
Reply
#4

Oh sorry, it's place not i.
pawn Код:
for(new place = 0; place != 30; ++place)
    {
        if (0 == playerOnlineTimes[place][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[place][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, place + 1, /* Maybe get player name here */, day, hour, mins, playerOnlineTimes[place][1]);    
}
I have no idea how you store your playernames, if you have some function like PlayerName just pass playerOnlineTimes[place][0]
Reply
#5

Can like this?
PHP код:
new sendername[MAX_PLAYER_NAME];
GetPlayerName(playeridsendernamesizeof(sendername));
format(aktivnostsizeof aktivnost"%s{FFFFFF}%d.%s:%d dana %d h %d min %d sec\n2.%s:%d dana %d h %d min %d sec\n"aktivnostsendername,place 1/* Maybe get player name here */dayhourminsplayerOnlineTimes[place][1]); 
Reply
#6

Almost, just
1) The name comes after place, so swap "sendername, place+1"
2) This fetches the name of player who called this command, you don't want that. Instead in GetPlayerName change playerid to "playerOnlineTimes[place][0]".
3) You want MAX_PLAYER_NAME + 1, so it won't take away last letter in case someone has 24 characters in his name.
Reply
#7

Like this? GetPlayerName[place][0]
Reply
#8

More like
pawn Код:
GetPlayerName(playerOnlineTimes[place][0], sendername, sizeof(sendername));
Reply
#9

Here is the picture who show me dialog, but don`t show me how long player was on the server http://prntscr.com/6dwtal
Reply
#10

BUMP!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)