View Single Post
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 10-22-2018 , 15:27   Re: Check all players are fully in-game
Reply With Quote #6

EDIT. Do not use the code below.

Some servers call round_start twice.
So I'll just leave the fix here in case somebody face with the same problem and don't want to call the trigger twice.

Code:
#pragma semicolon 1
#pragma newdecls required

float g_fConnectionTimeMin = 10.0;
float g_fConnectionTimeMax = 60.0;
float g_fConnectionTime;

public void OnPluginStart()
{
	HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
}

public Action Event_RoundStart(Event event, char[] name, bool dontBroadcast)
{
	static float fTime = -0.1;
	if (fTime < 0.0 || GetEngineTime() - fTime > 10.0)
	{
		g_fConnectionTime = g_fConnectionTimeMin;
		CreateTimer(g_fConnectionTimeMin, Timer_CheckConnection, _, TIMER_FLAG_NO_MAPCHANGE);
	}
	fTime = GetEngineTime();
	
	return Plugin_Continue;
}

public Action Timer_CheckConnection(Handle timer)
{
	bool IsPlayerConnecting;
	int i;
	
	for (i = 1; i <= MaxClients; i++)
	{
        if (IsClientConnected(i) && !IsClientInGame(i))
		{
			IsPlayerConnecting = true;
			break;
		}
	}
	
	if (IsPlayerConnecting)
	{
		PrintToChatAll("[SM]: Waiting connecting players: %N", i);
		
		if (g_fConnectionTime <= g_fConnectionTimeMax)
		{
			g_fConnectionTime += 5.0;
			CreateTimer(5.0, Timer_CheckConnection, _, TIMER_FLAG_NO_MAPCHANGE);
		}
		else {
			PrintToChatAll("[SM]: Timeout.");
			OnAllClientsPostAdminCheck(); // timeout
		}
	}
	else {
		OnAllClientsPostAdminCheck();
	}
}

void OnAllClientsPostAdminCheck()
{
	PrintToChatAll("[SM]: Ready!");
}
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 10-27-2018 at 08:00. Reason: added warning
Dragokas is offline