SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 08/10/2018, 10:09 PM   #1
AmirSavand
Big Clucker
 
AmirSavand's Avatar
 
Join Date: Sep 2018
Location: Behind Schedule
Posts: 78
Reputation: 8
Lightbulb pause.inc (Handle players pause status.)

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 Code:
hook OnPlayerPause(playerid)
{
    
printf("%s has paused."RGetPlayerName(playerid));
}

hook OnPlayerResume(playeridduration)
{
    
printf("%s just resumed after %i seconds."RGetPlayerName(playerid), duration);

__________________

GitHub - Website - Contact

C# - Python - PHP - Angular
Unity 3D - Django - Electron


Last edited by AmirSavand; 24/10/2018 at 02:05 AM.
AmirSavand is offline   Reply With Quote
Old 08/10/2018, 11:23 PM   #2
TheToretto
Huge Clucker
 
TheToretto's Avatar
 
Join Date: Jul 2015
Posts: 268
Reputation: 22
Default Re: pause.inc (Check for players pause/AFK status.)

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

But still, good job.
TheToretto is offline   Reply With Quote
Old 08/10/2018, 11:37 PM   #3
AmirSavand
Big Clucker
 
AmirSavand's Avatar
 
Join Date: Sep 2018
Location: Behind Schedule
Posts: 78
Reputation: 8
Default Re: pause.inc (Check for players pause/AFK status.)

Quote:
Originally Posted by TheToretto View Post
Thanks for the feedback!

That include is pretty useful too.
__________________

GitHub - Website - Contact

C# - Python - PHP - Angular
Unity 3D - Django - Electron

AmirSavand is offline   Reply With Quote
Old 09/10/2018, 12:06 AM   #4
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,170
Reputation: 351
Default Re: pause.inc (Check for players pause/AFK status.)

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

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

Code:
#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:
Code:
#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
__________________

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link


RogueDrifter is offline   Reply With Quote
Old 09/10/2018, 12:30 AM   #5
AmirSavand
Big Clucker
 
AmirSavand's Avatar
 
Join Date: Sep 2018
Location: Behind Schedule
Posts: 78
Reputation: 8
Default Re: pause.inc (Check for players pause/AFK status.)

Quote:
Originally Posted by RogueDrifter View Post
Okay so CallLocalFunction is slower than a direct call, so if i were you i'd do it like this:

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

Code:
#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:
Code:
#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 View Post
Here's my implementation for an afk checker with a pause checker too. LINK
Nice script, I left a comment on it.
__________________

GitHub - Website - Contact

C# - Python - PHP - Angular
Unity 3D - Django - Electron

AmirSavand is offline   Reply With Quote
Old 09/10/2018, 12:48 AM   #6
Variable™
Gangsta
 
Variable™'s Avatar
 
Join Date: Jul 2015
Location: Somewhere...
Posts: 747
Reputation: 153
Default Re: pause.inc (Check for players pause/AFK status.)

Pretty common and easy to script. GJ for the effort though.
__________________
MW4 Community
Variable™ is offline   Reply With Quote
Old 09/10/2018, 08:07 PM   #7
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,818
Reputation: 831
Default Re: pause.inc (Check for players pause/AFK status.)

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

My GitHub:

Gammix is online now   Reply With Quote
Old 12/10/2018, 07:11 PM   #8
AmirSavand
Big Clucker
 
AmirSavand's Avatar
 
Join Date: Sep 2018
Location: Behind Schedule
Posts: 78
Reputation: 8
Default Re: pause.inc (Check for players pause/AFK status.)

Quote:
Originally Posted by Gammix View Post
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
__________________

GitHub - Website - Contact

C# - Python - PHP - Angular
Unity 3D - Django - Electron

AmirSavand is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] Pause Check & Kick! Vanter Filterscripts 7 02/07/2014 04:54 AM
Players appearing pause BroZeus Scripting Help 2 22/02/2014 12:50 PM
Check Player Pause Petricko Scripting Help 3 18/04/2013 03:21 AM
After teleport all players in interior pause klotebandit Scripting Help 5 24/03/2013 11:37 AM
[FilterScript] Pause check GameStar. Filterscripts 11 22/08/2012 09:29 AM


All times are GMT. The time now is 03:29 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.