Players online time in server H/M/S
#1

Hello. How do I detect which player how much time was online on the server. Hours Minutes Seconds. Ladmin system but has a bug. Thanks in advance!
Reply
#2

I would like to know this as well... How could you save the amout of time that the player has played your server?
Reply
#3

What are you using, y_ini, mysql?
Reply
#4

Use a timer.
Reply
#5

https://sampwiki.blast.hk/wiki/Gettime
Reply
#6

Merge this into your script:

pawn Код:
#include <a_samp>
//#include <foreach>

new
    CheckEachTimer,
    PlayerSeconds[MAX_PLAYERS]
;

public OnFilterScriptInit()
{
    CheckEachTimer = SetTimer("CheckEachPlayer", 1000, true);
    return true;
}

public OnFilterScriptExit()
{
    KillTimer(CheckEachTimer);
    return true;
}

public OnPlayerConnect(playerid)
{
    PlayerSeconds[playerid] = 0;
    return true;
}

public OnPlayerDisconnect(playerid, reason)
{
    new hh, mm, ss;
    GetPlayerOnlineTime(playerid, hh, mm, ss);
   
    printf("ID%i was online for %i hours %i minutes %i seconds.",playerid,hh,mm,ss);
    return true;
}

forward CheckEachPlayer();
public CheckEachPlayer()
{
    #if defined foreach
        foreach(Player, i) { if(IsPlayerConnected(i)) PlayerSeconds[i]++; }
    #else
        for(new i=0; i<MAX_PLAYERS; i++) { if(IsPlayerConnected(i)) PlayerSeconds[i]++; }
    #endif
    return true;
}

stock GetPlayerOnlineTime(playerid, &hours, &minutes, &seconds)
{
    hours = (PlayerSeconds[playerid]/(60*60))%24;
    minutes = (PlayerSeconds[playerid]/60)%60;
    seconds = PlayerSeconds[playerid]%60;
}
Reply
#7

But I want to save it in the .ini file using y_ini

eg.

Код:
Name=Tigerbeast11
Password=HasedPassword
Cash=200
Hours On‌line=2
Minutes On‌line=34
So in this .ini file, the player has been online for 2 hours and 34 minutes.
Reply
#8

Quote:
Originally Posted by Tigerbeast11
Посмотреть сообщение
But I want to save it in the .ini file using y_ini

eg.

Код:
Name=Tigerbeast11
Password=HasedPassword
Cash=200
Hours On‌line=2
Minutes On‌line=34
So in this .ini file, the player has been online for 2 hours and 34 minutes.
Look up some Register/Login tutorial for Y_INI.

And then modify this:
pawn Код:
public OnPlayerLogin(playerid, password) //or connect.
{
    //If success:
    //Load the userfile...
    PlayerSeconds[playerid] = PlayerInfo[playerid][pSeconds]; //According to your variable.
    return true;
}
public OnPlayerDisconnect(playerid, reason)
{
    PlayerInfo[playerid][pSeconds] = PlayerSeconds[playerid];
    //Then save the userfile.
    return true;
}
Reply
#9

OK, thanks...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)