Recording total playing time
#1

I'm trying to save how long a person has played in the server. I get a warning:
Код:
warning 204: symbol is assigned a value that is never used: "time"
Here is what my code is.

PHP код:
new gPlayerJoin[MAX_PLAYERS];
enum pInfo
{
       
pTotalTime
}
new 
PlayerInfo[MAX_PLAYERS][pInfo];
public 
LoadUser_data(playerid,name[],value[])
{
    
INI_Int("TotalTime",PlayerInfo[playerid][pTotalTime]);
}
public 
OnPlayerConnect(playerid)
{
          
gPlayerJoin[playerid] = gettime();
        return 
1;
}
public 
OnPlayerDisconnect(playeridreason);
{
           new 
time gettime() - gPlayerJoin[playerid];
        new 
INI:File INI_Open(UserPath(playerid));
        
INI_SetTag(File"data");
        
INI_WriteInt(File,"TotalTime",PlayerInfo[playerid][pTotalTime]);
        
INI_Close(File);
        return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
....
                
Register...
                
INI_WriteInt(File,"TotalTime",0);
                                        
Login
                    PlayerInfo
[playerid][pTotalTime] = GetPVarInt(playerid"TotalTime");
       return 
1;

I'm also trying to make this /checkplayer command. However I'm not too sure how to do it with getting just the seconds from the gettime();
PHP код:
CMD:checkplayer(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] >= 1)
    {
        new 
IDstring[256],str[256], hms;
        if(
sscanf(params,"i"ID)) return SendClientMessage(playeridCOLOR_ADMIN"Usage: /checkplayer [ID]");
        if(
IsPlayerConnected(ID) && ID  != INVALID_PLAYER_ID && ID != playerid)
        {
            if(!
strlen(params)) ID playerid;
            else 
ID strval(params);
            
PlayerInfo[playerid][pTotalTime](IDhms);
             
format(stringsizeof(string),
             
"{6EF83C}Score: {FFFFFF}%d\n{6EF83C}Money: {FFFFFF}$%d\n{6EF83C}Hours: {FFFFFF}%d\n{6EF83C}Min: {FFFFFF}%d\n{6EF83C}Sec: {FFFFFF}%d"GetPlayerScore(ID), GetPlayerMoney(ID),h,m,s);
            
format(str,sizeof(str),"{6EF83C}%s's {FFFFFF}Player Stats",GetName(ID));
            return 
ShowPlayerDialog(playerid2002DIALOG_STYLE_MSGBOXstrstring"OK","");
        }
    }
    else
      {
           return 
0;
    }
    return 
1;

With the command I get 1 error and 2 warnings.
Код:
(1979)warning 215: expression has no effect
(1978) : error 001: expected token: ";", but found "("
(1978) : warning 215: expression has no effect
The line all these are on is
PHP код:
        PlayerInfo[playerid][pTotalTime](IDhms); 
Reply
#2

PHP код:
public OnPlayerDisconnect(playeridreason);
{
           new 
time gettime() - gPlayerJoin[playerid];
        new 
INI:File INI_Open(UserPath(playerid));
        
INI_SetTag(File"data");
        
INI_WriteInt(File,"TotalTime",time); // You should write the time you just subtracted.
        
INI_Close(File);
        return 
1;

And this makes no sense:

PHP код:
PlayerInfo[playerid][pTotalTime](IDhms); 
What are you trying to do here. :/
Reply
#3

Quote:
Originally Posted by DarkSkull
Посмотреть сообщение
PHP код:
public OnPlayerDisconnect(playeridreason);
{
           new 
time gettime() - gPlayerJoin[playerid];
        new 
INI:File INI_Open(UserPath(playerid));
        
INI_SetTag(File"data");
        
INI_WriteInt(File,"TotalTime",time); // You should write the time you just subtracted.
        
INI_Close(File);
        return 
1;

And this makes no sense:

PHP код:
PlayerInfo[playerid][pTotalTime](IDhms); 
What are you trying to do here. :/
Thanks. Haha, I'm TRYING, and when I say trying I mean failing. I'm trying to get the saved time (It's saved into seconds? Using gettime();? And format it into hours minutes and seconds.
Reply
#4

Now that code appears to only be tracking the last sessions time and storing it.


You need to do more with your variables. As the error said, you'd used time, and hadn't done anything with it.

It was also just a warning, and likely output a usable AMX file.
Reply
#5

How would you suggest I do it? I copied what ****** said here. https://sampforum.blast.hk/showthread.php?tid=187306 I'm not very familiar with gettime();
Reply
#6

You're only missing one vital step... You want to add time, to PlayerTotalTime.


Say
PHP код:
PlayerTotalTime PlayerTotalTime time
Reply
#7

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
You're only missing one vital step... You want to add time, to PlayerTotalTime.


Say
PHP код:
PlayerTotalTime PlayerTotalTime time
Where should I add that? OnPlayerDisconnect?
Reply
#8

Quote:
Originally Posted by Tass007
Посмотреть сообщение
Where should I add that? OnPlayerDisconnect?
Indeed. You weren't doing what you were thinking with time, that was what the compiler was saying.


I think you envisioned a feature, and implemented some parts, but forgot about that portion. It is definitely needing a
PHP код:
Totaltime TotalTime time
if you haven't got anything like this, for this purpose.


I only say this because the last portion of code given to you, even though it works, what it's doing is putting the last sessions playtime, as total time. So each time that will be checked, it'll only show how long they played for, last time they were on.
Reply
#9

Awesome yeah I need that then. However the variable TotalTime is in my enum with the constants of my PlayerInfo, how do I make that global? So that I don't get error's when adding
PHP код:
Totaltime TotalTime time
into my code?
Reply
#10

PHP код:
PlayerInfo[playerid][pTotalTime] = PlayerInfo[playerid][pTotalTime] + time
Now this may not work, but it's simply using your variables, compared to me simply saying what you need.



Now that code, should work if
PHP код:
new time gettime() - gPlayerJoin[playerid]; 
is still present and
PHP код:
gPlayerJoin[playerid
is the gettime count at the time the player connected, or logged in.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)