[Include] pause.inc (Check for players pause/AFK status.)
#1

Pause (v1.1)

View code and download: https://gist.github.com/AmirSavand/9...57570cc5902221

Leave comments here or on the GitHub page if you have any questions/suggestions.


Installation

Just include it in the gamemode or filterscript.


Usage

Default PAUSE_LIMIT (Time to set player as inactive/paused) value is 3 seconds, you can change that.

Watch OnPlayerPause(playerid) to handle player pause.

Watch OnPlayerResume(playerid, duration) to handle player resume (duration in seconds).

Call IsPlayerPaused(playerid) to check player pause/AFK status (returns boolean).


Example

PHP код:
hook OnPlayerPause(playerid)
{
    
printf("%s has paused."RGetPlayerName(playerid));
}
hook OnPlayerResume(playeridduration)
{
    
printf("%s just resumed after %i seconds."RGetPlayerName(playerid), duration);

Reply
#2

https://github.com/emmet-jones/New-S...lbacks.inc#L14

But still, good job.
Reply
#3

Quote:
Originally Posted by TheToretto
Посмотреть сообщение
Thanks for the feedback!

That include is pretty useful too.
Reply
#4

Okay so CallLocalFunction is slower than a direct call, so if i were you i'd do it like this:

Код:
#if defined OnPlayerPause
    OnPlayerPause(playerid);
#endif
then anywhere in the include just forward it with a check as well.

Код:
#if defined OnPlayerPause
    forward OnPlayerPause(playerid);
#endif
instead of the CallLocalFunction usage and you didn't forward the function.

You should also mention the usage of y_hooks along with the credits in the post. There's also the protection against double including, this:
Код:
#if defined afkChecker_included_
    #endinput
#endif

#define afkChecker_included_
Also i don't recommend Emmet_'s include at all, it's outdated and needs an update. It has useful code but i wouldn't use it for one function and if i do ever use it it'll still need an update for functions parameters alongside a few more things.

Here's my implementation for an afk checker with a pause checker too. LINK
Reply
#5

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
Okay so CallLocalFunction is slower than a direct call, so if i were you i'd do it like this:

Код:
#if defined OnPlayerPause
    OnPlayerPause(playerid);
#endif
then anywhere in the include just forward it with a check as well.

Код:
#if defined OnPlayerPause
    forward OnPlayerPause(playerid);
#endif
instead of the CallLocalFunction usage and you didn't forward the function.

You should also mention the usage of y_hooks along with the credits in the post. There's also the protection against double including, this:
Код:
#if defined afkChecker_included_
    #endinput
#endif

#define afkChecker_included_
I hook the functions in different includes in my mode so I need them to be called like that and less code this way lol.

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
Here's my implementation for an afk checker with a pause checker too. LINK
Nice script, I left a comment on it.
Reply
#6

Pretty common and easy to script. GJ for the effort though.
Reply
#7

When player is in class selection they don't call OnPlayerUpdaye, so that will be a false detection in this case.
Reply
#8

Quote:
Originally Posted by Gammix
Посмотреть сообщение
When player is in class selection they don't call OnPlayerUpdaye, so that will be a false detection in this case.
Thanks for your awesome feedback!

I finally had some time and updated it: revisions#diff-6701a637455914255c0741977f75a2a7
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)