How can I fix that
#1

So, I have a timer (6,5 seconds) that start when OnPlayerDeath is called and check if OnPlayerSpawn was called for player, if hasn't, i use SpawnPlayer(playerid). Everything is good, he is called, but i have a little problem.

When the player get afk in the animation when he died and he put the game in bar timer still runing behind (i think) for player, and when he come back, OnPlayerSpawn and Timer is simultaneously called and he will be spawned twice and when this happen, he doesn't spawn at his normal zone, he spawn in air or 0.0, 0.0, 0.0 (x,y,z) or grove street zone (another vw), typically samp. Or he get first spawn from the timer after 6,5 sec, and when he come back OnPlayerSpawn is called (same, spawned twice)...

I use a variabile (Alive[playerid]) to OnPlayerDeath " = 0 " and OnPlayerSpawn " = 1 " to check if the function was called.

How can I do to fix this? Or I can't?
Reply
#2

When you're saying AFK, you're meaning he is tabbed... So check if he's tabbed, and then don't spawn him in the first place.

The reason why it happens is because the client isn't updating whilst he is tabbed.
Reply
#3

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Define what you mean by 'afk'...
When he put his game in bar.
Reply
#4

https://github.com/emmet-jones/New-SA-MP-callbacks

pass your code through the forward OnPlayerPause
create a new variable say afk
so,

Код:
new afk[MAX_PLAYER];
public OnPlayerPause(playerid)
{
    afk[playerid]=1;
}

public OnPlayerResume(playerid, time)
{
    afk[playerid]=0;
}


public OnPlayerSpawn(playerid)
{
    if(afk[playerid]==1)
        {
            //your code here for paused player
        }
    else
        {
             //not paused player
         }
}
Reply
#5

^^ That is a waste to add an entire include showing a heap of shit, for just one function.

Instead of adding in the entire include, you could make the AFK monitor, in about 20 lines.
Reply
#6

Just use gettickcount at onplayerupdate and save it in a player's variable and compare it at a timer that counts every few seconds to check if gettickcount > savedticksinvariable+4000 to see when was onplayerupdate last called supposedly its called many times in a second so gettickcount will never be bigger than opu's ticks+4000 only if the player is tabbed (paused) because only then opu is not being updated (called).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)