[FilterScript] Pause check
#1

:: 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
Reply
#2

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.
Reply
#3

Fixed, thanks.
Reply
#4

Good!

Thanks for the basic code!
Reply
#5

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!
Reply
#6

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?
Reply
#7

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)