I need help with count time of player.
#1

Hello,

I need help, I do not know how to count the player the amount of time that a server - but if the player is in a state away from keyboard then it does not count the hours, I'd be happy if you give me an example.

thank you.
Reply
#2

Create a timer (1 second interval) that loops all players, and increases a variable by one.
OnPlayerUpdate, set that variable to 0.

At that timer, check if the variable has passed 2-x value, if yes he must likely went AFK.
How does it works? OnPlayerUpdate doesn't get called if player is not playing (alt-tabbed/etc), which means it won't set his variable to zero if he is AFKing, and you basically check that by the if statement, if he returned to the game, each second it'll set his variable to zero again, meaning he came back online.


pawn Код:
new someValue[MAX_PLAYERS];

forward timer();
public OnGameModeInit()
{
      SetTimer("timer", 1000, true); //(1 sec interval)
      return 1;
}

public OnPlayerUpdate(playerid)
{
      someValue[playerid] = 0;
      return 1;
}

public timer()
{
    foreach(Player, i)
    {
        someValue[i] ++;
    }
    return 1;
}
Reply
#3

I mean to know how much hours the player was in server without be AFK
Reply
#4

The same way basically, just remove the if(AFKvalue[i] > 3) line.
Create a command to check how much is his value, for instance if 60 then he has been online for 1 minute.
(AFKvalue[playerid]/60) = minutes
(AFKvalue[playerid]/3600) = hours
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)