SA-MP Forums Archive
How can I fix that - 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: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How can I fix that (/showthread.php?tid=648721)



How can I fix that - None1337 - 27.01.2018

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?


Re: How can I fix that - Sew_Sumi - 27.01.2018

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.


Re: How can I fix that - None1337 - 27.01.2018

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


Re: How can I fix that - iSteve - 27.01.2018

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
         }
}



Re: How can I fix that - Sew_Sumi - 27.01.2018

^^ 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.


Re: How can I fix that - RogueDrifter - 27.01.2018

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).