PDA

View Full Version : OnPlayerTab?


Lirbo
29/04/2016, 05:34 PM
How could I do it?

Lordzy
29/04/2016, 05:36 PM
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.

Lirbo
30/04/2016, 02:26 PM
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.

so how i'm supposed to do that?

if(return 0)
{
// Script?
}

Btw there's other ways to check that instead of OnPlayerUpdate? for example with a normal timer? OnPlayerUpdate might lag.

Lordzy
30/04/2016, 03:35 PM
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.

Lirbo
30/04/2016, 03:49 PM
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.

I see, anyway could you explain me how i can do it properly? in addition i'd like to add it seconds (how long he's afk) so i'll have to use a timer anyway.

Lordzy
30/04/2016, 03:53 PM
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/blob/master/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 :

//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);

Lirbo
30/04/2016, 03:58 PM
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/blob/master/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 :

//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);


bro xD i dont wanna sound retard ok but i didnt understand shit from that.
let's say I just want to detect if the player is afk or not, how can i do it, leave the rest to me

Ritzy2K
30/04/2016, 04:27 PM
Search for an include by Emmet, onPlayerPause. It has IsPlayerPaused

Lordzy
30/04/2016, 04:57 PM
If you're using the one I linked, this should do it:

#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);