Pause timer when player is AFK(minimized or ESC)
#1

Hi SA-MP Community,

I have a system in which every hour the player gets some score. So some players might abuse this by logging in and minimizing the game and earning those scores for free. I want to prevent this.

Regards.
Reply
#2

PHP код:
#include <a_samp>
#include <zcmd>

new PlayerIsAfk[MAX_PLAYERS],
    
PlayerAfkTime[MAX_PLAYERS],
    
OldVW[MAX_PLAYERS],
    
Text:Afk[MAX_PLAYERS][5],
    
Float:OldPos[MAX_PLAYERS][4];


public 
OnGameModeInit()
{
    for(new 
0MAX_PLAYERSi++)
    {
        
Afk[i][0] = TextDrawCreate(641.5555411.500000"usebox");
        
TextDrawLetterSize(Afk[i][0], 0.00000049.405799);
        
TextDrawTextSize(Afk[i][0], -2.0000000.000000);
        
TextDrawAlignment(Afk[i][0], 1);
        
TextDrawColor(Afk[i][0], 0);
        
TextDrawUseBox(Afk[i][0], true);
        
TextDrawBoxColor(Afk[i][0], 151);
        
TextDrawSetShadow(Afk[i][0], 0);
        
TextDrawSetOutline(Afk[i][0], 0);
        
TextDrawBackgroundColor(Afk[i][0], 128);
        
TextDrawFont(Afk[i][0], 0);

        
Afk[i][1] = TextDrawCreate(641.555541137.393341"usebox");
        
TextDrawLetterSize(Afk[i][1], 0.0000005.656665);
        
TextDrawTextSize(Afk[i][1], -2.0000000.000000);
        
TextDrawAlignment(Afk[i][1], 1);
        
TextDrawColor(Afk[i][1], 0);
        
TextDrawUseBox(Afk[i][1], true);
        
TextDrawBoxColor(Afk[i][1], 102);
        
TextDrawSetShadow(Afk[i][1], 0);
        
TextDrawSetOutline(Afk[i][1], 0);
        
TextDrawFont(Afk[i][1], 0);

        
Afk[i][2] = TextDrawCreate(641.555541235.455551"usebox");
        
TextDrawLetterSize(Afk[i][2], 0.0000006.707531);
        
TextDrawTextSize(Afk[i][2], -2.0000000.000000);
        
TextDrawAlignment(Afk[i][2], 1);
        
TextDrawColor(Afk[i][2], 0);
        
TextDrawUseBox(Afk[i][2], true);
        
TextDrawBoxColor(Afk[i][2], 102);
        
TextDrawSetShadow(Afk[i][2], 0);
        
TextDrawSetOutline(Afk[i][2], 0);
        
TextDrawFont(Afk[i][2], 0);

        
Afk[i][3] = TextDrawCreate(245.333282189.155563"RETOUR");
        
TextDrawLetterSize(Afk[i][3], 1.0033334.288000);
        
TextDrawAlignment(Afk[i][3], 1);
        
TextDrawColor(Afk[i][3], -1);
        
TextDrawSetShadow(Afk[i][3], 0);
        
TextDrawSetOutline(Afk[i][3], 1);
        
TextDrawBackgroundColor(Afk[i][3], 51);
        
TextDrawFont(Afk[i][3], 2);
        
TextDrawSetProportional(Afk[i][3], 1);
        
TextDrawSetSelectable(Afk[i][3], 1);

        
Afk[i][4] = TextDrawCreate(204.88899223.395574"Vous кtes en AFK");
        
TextDrawLetterSize(Afk[i][4], 0.7811102.729955);
        
TextDrawAlignment(Afk[i][4], 1);
        
TextDrawColor(Afk[i][4], -1);
        
TextDrawSetShadow(Afk[i][4], 0);
        
TextDrawSetOutline(Afk[i][4], 1);
        
TextDrawBackgroundColor(Afk[i][4], 51);
        
TextDrawFont(Afk[i][4], 3);
        
TextDrawSetProportional(Afk[i][4], 1);
   }
   return 
1;
}

public 
OnPlayerConnect(playerid)
{
    
SetTimerEx("OneMinuteTimer",10000,1,"i",playerid);
    return 
1;
}

stock SetPlayerAfk(playerid)
{
    
PlayerIsAfk[playerid] = 1;
    
PlayerAfkTime[playerid] = 0;
    
    
OldVW[playerid] = GetPlayerVirtualWorld(playerid);
    
    
TogglePlayerControllable(playerid,0);
    
    for(new 
05i++)
        
TextDrawShowForPlayer(playeridAfk[playerid][i]);
        
    
SelectTextDraw(playerid0xA3B4C5FF);
    return 
1;
}


public 
OnPlayerClickTextDraw(playeridText:clickedid)
{
    if(
clickedid == Afk[playerid][3]) 
    {
        for(new 
05i++)
            
TextDrawHideForPlayer(playeridAfk[playerid][i]);
            
        
PlayerIsAfk[playerid] = 0;
        
PlayerAfkTime[playerid] = 0;
        
SetPlayerVirtualWorld(playerid,OldVW[playerid]);
        
TogglePlayerControllable(playerid,1);
        
        
CancelSelectTextDraw(playerid);
        return 
1;
        
    }
    return 
1;
}

public 
OneMinuteTimer(playerid)
{
    if(
PlayerIsAfk[playerid] == 1)
    {
        return 
1;
    }
    
    if(
PlayerAfkTime[playerid] == 8)
    {
        
SetPlayerAfk(playerid);
        return 
1;
    }
    
    new 
Float:Pos[3];
    
    
GetPlayerPos(playeridPos[0], Pos[1], Pos[2]);
    
    if(
IsPlayerInRangeOfPoint(playerid,3.0,OldPos[playerid][0],OldPos[playerid][1],OldPos[playerid][2]))
    {
        
PlayerAfkTime[playerid]++;
        return 
1;
    }
        
    
PlayerAfkTime[playerid] = 0;
    
    
OldPos[playerid][0] = Pos[0];
    
OldPos[playerid][1] = Pos[1];
    
OldPos[playerid][2] = Pos[2];
    return 
1;

Reply
#3

I am not looking for that mate.

Off: Your post to rep ratio!
Reply
#4

What ?
Reply
#5

How can I pause(not stop) my timer when a player goes AFK? Thats what I want.
Reply
#6

https://sampforum.blast.hk/showthread.php?tid=277692
Reply
#7

Have a variable to toggle whether the player is AFK or not and when the timer's callback is executed, if the player is AFK skip it. If the timer is global and you use a player loop in it, use continue; else if you used SetTimerEx, just return a value before setting the score.
Reply
#8

You are definitely not getting what I want.
See I made a timer, now when a player minimizes the game or presses ESC, I want that timer to just pause and when the player comes back, resume the timer from where it paused.
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Have a variable to toggle whether the player is AFK or not and when the timer's callback is executed, if the player is AFK skip it. If the timer is global and you use a player loop in it, use continue; else if you used SetTimerEx, just return a value before setting the score.
What about at the time of initiating the timer(say a 60 minute timer), the player is not afk and say around 5 minutes later the player decides to minimize the game, so I want the timer to pause at that time (i.e. 5 minutes after the timer has started) and then resume back the timer when the player comes back now the countdown starts from 55 minutes.

Quote:
Originally Posted by thefatshizms
Посмотреть сообщение
Use timestamps. Check if the player has been active for 1 hour and if so give him the score.
What if the player just interact in the server for 5 minutes decides to switch to some xxx and then come back an hour later to get his score?
Reply
#10

Quote:
Originally Posted by Faisal_khan
Посмотреть сообщение
What if the player just interact in the server for 5 minutes decides to switch to some xxx and then come back an hour later to get his score?
That won't be an hour of "active" time, it'll be 5 minutes. There's no real need for timers here, just use timestamps.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)