Thread: [Solved] Save user for x time
View Single Post
eyal282
Veteran Member
Join Date: Aug 2011
Old 06-12-2022 , 13:15   Re: Save user for x time
Reply With Quote #7

Quote:
Originally Posted by azalty View Post
Using a database for that isn't really the best solution. The problem here is that people can just reconnect on the same map and respawn.

Thus, we don't need that info to persist after a server restart, or even, a map change.

Code:
ArrayList g_hConnectHistoryList;
char g_sBuffer[32];
bool g_bShouldRespawn[MAXPLAYERS + 1];

public void OnPluginStart()
{
	g_hConnectHistoryList = new ArrayList(ByteCountToCells(32)); // Let's use a size of 32 for SteamIDs
}

void RespawnPlayer(int client)
{
	// Write your code here to respawn the player, ex:
	CS_RespawnPlayer(client);
}

public void OnMapStart()
{
	g_hConnectHistoryList.Clear();
}

public void OnClientDisconnect(int client)
{
	g_bShouldRespawn[client] = false;
}

public void OnClientAuthorized(int client, const char[] auth)
{
	if (g_bChecked[client])
		return;
	
	if (g_hConnectHistoryList.FindString(auth) == -1)
	{
		if (!IsClientInGame(client))
		{
			g_bShouldRespawn[client] = true;
			return;
		}
		g_hConnectHistoryList.PushString(auth);
		
		RespawnPlayer(client);
	}
}

public void OnClientPutInServer(int client)
{
	if (!g_bShouldRespawn[client])
		return;
	GetClientAuthId(client, AuthId_Steam2, g_sBuffer, sizeof(g_sBuffer));
	g_hConnectHistoryList.PushString(g_sBuffer);
	
	RespawnPlayer(client);
}
If you just want to limit this per round, just hook the "round_prestart" event (because when the start event is called, all the players have already spawned) and clear the arraylist when that event is called.
Average cherry picking enjoyer.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline