Quote:
Originally Posted by ZeeX
When they minimize the game, it doesn't send the data to the server, i.e. OnPlayerUpdate won't be called for them (I've tested it recently). So if you check the time between two packets are sent (use timer to do this) and it is over than some value, e.g. one second, then you know that the player paused his game.
Edit:
Here is implementation of my idea:
pawn Code:
#include <a_samp>
#define abs(%1) \ ((%1 < 0) ? (-(%1)) : (%1))
new gPlayerTicks[MAX_PLAYERS], gPlayerIsAFK[MAX_PLAYERS];
#define UPDATE_TIMEOUT 10000
public OnPlayerUpdate(playerid) { new ticks = GetTickCount(); if (playerid < MAX_PLAYERS) { if (gPlayerIsAFK[playerid]) { gPlayerIsAFK[playerid] = false; printf("player #%d is back", playerid); } else { SetTimerEx("OnPlayerUpdate", UPDATE_TIMEOUT + 1000, false, "i", playerid + MAX_PLAYERS); } gPlayerTicks[playerid] = ticks; } else { playerid -= MAX_PLAYERS; if (!gPlayerIsAFK[playerid]) { if (abs(gPlayerTicks[playerid] - ticks) > UPDATE_TIMEOUT) { gPlayerIsAFK[playerid] = true; printf("player #%d is AFK now", playerid); } } } return 1; }
public OnPlayerConnect(playerid) { gPlayerIsAFK[playerid] = false; return 1; }
|
Code doesn't work, you never see the print.