29.04.2016, 17:34
How could I do it?
OnPlayerUpdate won't get called when the player is paused (either tabbed / paused). There are also includes released which helps to know whether a player is paused or not. Try searching for - "OnPlayerPause".
EDIT : I'm confused whether you're asking to detect if player is pressing TAB button or in case if player's pausing the game. Be more descriptive. |
if(return 0)
{
// Script?
}
No, it will not cause any lag. That's a false opinion by most of the users but the fact is that it's a callback that's called very frequently and having excessive amounts of code can cause lag. OnPlayerUpdate being used for necessary things should not cause any lag.
|
//Here [e_PlayerLastUpdate] is the tickcount taken right before player goes afk.
temp_Tick = GetTickCount();
temp_Seconds = (temp_Tick - g_PlayerAFKData[i][e_PlayerLastUpdate]) / 1000;
temp_Mins = temp_Seconds / 60;
temp_Seconds -= temp_Mins * 60;
format(temp_dString, sizeof(temp_dString), "%s\n\
%s (ID:%d) is AFK since %d minutes, %d seconds.",
temp_dString, temp_Name, i, temp_Mins, temp_Seconds);
This is my old AutoAFK include which was never released. I wrote it a long time ago and it can be a lot optimized. https://github.com/Lordzy/AutoAFK/bl...er/AutoAFK.inc
You don't have to use a timer to know how long a player is AFK. Just store the time when player goes AFK, then compare it with the current time and you can know how long the player's been AFK. The following code is taken from my unreleased AFK filterscript : pawn Код:
|
#include <a_samp>
#include <AutoAFK>
public OnPlayerPause(playerid) {
printf("PlayerID : %d has paused.", playerid);
return 1;
}
public OnPlayerResume(playerid) {
printf("Player ID : %d is now back!", playerid);
return 1;
}
//To check if player is paused:
IsPlayerPaused(playerid);