SA-MP Forums Archive
[FilterScript] Pause check - 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)
+--- Thread: [FilterScript] Pause check (/showthread.php?tid=277692)



Pause check - GameStar. - 18.08.2011

:: Pause check ::
This script, we can see that the player is paused or not.

pawn Код:
#include <a_samp>
#include <pause>

public OnPlayerPaused(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new string[128];
    format(string, 128, "%s is paused!", name);
    SendClientMessageToAll(0xFFFFFFFF, string);
    return 1;
}
public OnPlayerUnpaused(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new string[128];
    format(string, 128, "%s is unpaused!", name);
    SendClientMessageToAll(0xFFFFFFFF, string);
    return 1;
}
INC: http://solidfiles.com/d/6f01e/

Tanks to:
Goldkiller - spawn function
AndreT - Idea


Re: Pause check - AndreT - 18.08.2011

Okay that is just PLAIN HORRIBLE.

You should definitely not use PVars in OnPlayerUpdate. And actually you don't even need GetTickCount().

What you should do to detect AFKing is:
1. in OnPlayerUpdate, keep setting a variable to 0
2. in your 1-second timer, keep incrementing the variable until it reaches 2. If it reaches 2, the player is not sending updates anymore (is paused, about to time out, whatever)

pawn Код:
new updating[MAX_PLAYERS char];

public OnGameModeInit()
{
    SetTimer("checkAFK", 1000, true);
}

public OnPlayerUpdate(playerid)
{
    updating{playerid} = 0;
}

forward checkAFK();
public checkAFK()
{
    foreach(Player, i)
    {
        if(updating{i} < 2)
            updating{i} ++;
        else
        {
            // Player went AFK!
        }
    }
}
Basic but you get the idea.


Re: Pause check - GameStar. - 18.08.2011

Fixed, thanks.


Re: Pause check - Davz*|*Criss - 18.08.2011

Good!

Thanks for the basic code!


Re: Pause check - AndreT - 19.08.2011

Nice, I see you updated it to work in a better method. However I think there are still some improvements that can be made and I've made a version of my own: http://pastebin.com/f5NzgDFn (completely untested, but you can report if it works or not)

I made one timer which loops through all players (and if foreach is defined, it is used) instead of timer per player. Also moved one check from the timer to OnPlayerUpdate and made it so the Update value doesn't get incremented too much. You could make it a char array!


Re: Pause check - System64 - 19.08.2011

you should use y_hooks and when I connect my dialog for login doesn't show, when I remove this puase I show, what to do?


Respuesta: Pause check - predator_ - 23.08.2011

Is bugged, if im enter un vehicle and exit, the message is sended (sorry for my english) xD


Re: Pause check - Gh0sT_ - 23.08.2011

AndreT > whats then, if server has more then 255 players? char array is 8 bit, which max value is 255 AFAIK


Re: Pause check - Ivan_Pantovic - 24.08.2011

Hmm, nice.
I'm thinking about adding this on my server.


Re: Pause check - ••• ĤБĶБM ••• - 24.08.2011

Not professionally made but I can say this is better than nothing.