The rest of the methods I've seen about detecting is the position if it has not changed but it is not accurate in my opinion.
|
#include <YSI\y_hooks>
#define TIME_DIF 2000 //Decreasing will make it more accurate, leave it like that, it's fine.
// #define USECALLBACKS
forward C_Paused(playerid);
#if defined USECALLBACKS
forward OnPlayerPause(playerid);
forward OnPlayerUnPause(playerid);
#endif
new g_Paused[MAX_PLAYERS];
new bool:g_Requesting[MAX_PLAYERS];
new bool:g_IsPaused[MAX_PLAYERS];
hook OnPlayerConnect(playerid)
{
g_IsPaused[playerid] = false;
g_Requesting[playerid] = false;
return 1;
}
hook OnPlayerUpdate(playerid)
{
g_Paused[playerid] = GetTickCount();
return 1;
}
hook OnPlayerRequestClass(playerid)
{
g_Requesting[playerid] = true;
g_IsPaused[playerid] = false;
return 1;
}
hook OnPlayerDisconnect(playerid)
{
g_Requesting[playerid] = false;
g_IsPaused[playerid] = false;
return 1;
}
hook OnPlayerSpawn(playerid)
{
g_Requesting[playerid] = false;
g_IsPaused[playerid] = false;
return 1;
}
public C_Paused(playerid)
{
if(GetTickCount()-g_Paused[playerid] > TIME_DIF && g_Requesting[playerid] != true && g_IsPaused[playerid] != true && InvalidStates(playerid) != 1)
{
#if defined USECALLBACKS
OnPlayerPause(playerid);
#endif
g_IsPaused[playerid] = true;
}
else if(GetTickCount()-g_Paused[playerid] < TIME_DIF && g_Requesting[playerid] != true && g_IsPaused[playerid] != false && InvalidStates(playerid) != 1)
{
#if defined USECALLBACKS
OnPlayerUnPause(playerid);
#endif
g_IsPaused[playerid] = false;
}
return 1;
}
stock IsPlayerPaused(playerid) { return g_IsPaused[playerid]; }
stock InvalidStates(playerid)
{
new pState = GetPlayerState(playerid);
if(pState == 0 || pState == 7) return 1;
else return 0;
}
task PauseUpdate[1000]() { foreach(new i : Player) { C_Paused(i); } }
#if defined USECALLBACKS
public OnPlayerPause(playerid) { SendClientMessage(playerid, STEALTH_GREEN, "Paused"); }
public OnPlayerUnPause(playerid) { SendClientMessage(playerid, STEALTH_GREEN, "UnPaused"); }
#endif
#include < a_samp >
#include < foreach >
#undef MAX_PLAYERS
#define MAX_PLAYERS (50)
// Change to your amount of max players you want.
new
bool: IsPlayerPaused[ MAX_PLAYERS ],
PlayerPausedCount[ MAX_PLAYERS ],
Paused_Timer
;
main( ) { }
public OnGameModeInit( )
{
Paused_Timer = SetTimer( "OnPlayersPaused", 1000, true );
return 1;
}
public OnGameModeExit( )
{
KillTimer( Paused_Timer );
return 1;
}
public OnPlayerConnect( playerid )
{
IsPlayerPaused[ playerid ] = false;
PlayerPausedCount[ playerid ] = 0;
return 1;
}
public OnPlayerUpdate( playerid )
{
PlayerPausedCount[ playerid ] = 0;
if( IsPlayerPaused[ playerid ] )
{
CallLocalFunction( "OnPlayerUnpaused", "i", playerid );
IsPlayerPaused[ playerid ] = false;
}
return 1;
}
forward OnPlayerPaused( playerid );
public OnPlayerPaused( playerid )
{
}
forward OnPlayerUnpaused( playerid );
public OnPlayerUnpaused( playerid )
{
}
forward OnPlayersPaused( );
public OnPlayersPaused( )
{
foreach(new playerid : Player)
{
if( IsPlayerSpawned( playerid ) )
{
if( PlayerPausedCount[ playerid ] < 2 ) PlayerPausedCount[ playerid ]++;
else
{
CallLocalFunction( "OnPlayerPaused", "i", playerid );
IsPlayerPaused[ playerid ] = true;
}
}
}
}
stock IsPlayerSpawned( playerid )
{
switch( GetPlayerState( playerid ) )
{
case 0, 7, 9: return 0;
}
return 1;
}
Timer:OneSecondInterval[1000]() { }
timer OneSecondInterval[1000]() { }
Thanks to both! But I'm having problems using YSI, I've already posted something about this and there were no replies for resolution. I already have YSI and included it onto the game-mode without errors nor warnings.
Each time I try to use timers(y_timers), it doesn't work at all. First, I had this: pawn Код:
pawn Код:
|
#include <YSI\y_timers>
task RepeatingTimer[1000]()
{
printf("Called every 1 seconds.");
}
timer DelayedTimer[500](playerid)
{
printf("May be called after 0.5 seconds");
}
main()
{
defer DelayedTimer(42);
}