SA-MP Forums Archive
[Include] pause.inc (Check for players pause/AFK status.) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] pause.inc (Check for players pause/AFK status.) (/showthread.php?tid=659604)



pause.inc (Handle players pause status.) - AmirSavand - 08.10.2018

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




Re: pause.inc (Check for players pause/AFK status.) - TheToretto - 08.10.2018

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

But still, good job.


Re: pause.inc (Check for players pause/AFK status.) - AmirSavand - 08.10.2018

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

That include is pretty useful too.


Re: pause.inc (Check for players pause/AFK status.) - RogueDrifter - 08.10.2018

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


Re: pause.inc (Check for players pause/AFK status.) - AmirSavand - 08.10.2018

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.


Re: pause.inc (Check for players pause/AFK status.) - Variable™ - 08.10.2018

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


Re: pause.inc (Check for players pause/AFK status.) - Gammix - 09.10.2018

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


Re: pause.inc (Check for players pause/AFK status.) - AmirSavand - 12.10.2018

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