Raised This Month: $344 Target: $400
 86%   Almost there!

Solved Save user for x time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gena
Member
Join Date: May 2022
Location: Uruguay
Old 06-08-2022 , 14:56   Save user for x time
Reply With Quote #1

I'm creating a plugin that automatically respawns you when you connect (very simple), so you can play without waiting for the game to finish.

But I'm sure that people when they die will simply retry on console and revive, so...
how can I get a player steam id for a while so they don't do this?
__________________
Servers of CS:GO - Private Plugins
Steam ~ GenaEscobar#2338
sorry for my english as a translator d:

Last edited by Gena; 06-12-2022 at 21:39.
Gena is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 06-08-2022 , 15:48   Re: Save user for x time
Reply With Quote #2

Quote:
Originally Posted by Gena View Post
I'm creating a plugin that automatically respawns you when you connect (very simple), so you can play without waiting for the game to finish.

But I'm sure that people when they die will simply retry on console and revive, so...
how can I get a player steam id for a while so they don't do this?
Use a database or clientprefs to save across server restarts.

I think you are best off with a stringmap if you don't need your data to be saved if map changes.

https://github.com/eyal282/l4d2-karm...a_jump_auto.sp
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
VladimirTk
Senior Member
Join Date: Apr 2021
Location: Perú - Latino América
Old 06-11-2022 , 17:28   Re: Save user for x time
Reply With Quote #3

Quote:
Originally Posted by Gena View Post
I'm creating a plugin that automatically respawns you when you connect (very simple), so you can play without waiting for the game to finish.

But I'm sure that people when they die will simply retry on console and revive, so...
how can I get a player steam id for a while so they don't do this?
this might work for you, or at least borrow this code as an example

https://forums.alliedmods.net/showthread.php?p=708036
VladimirTk is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 06-11-2022 , 18:28   Re: Save user for x time
Reply With Quote #4

Quote:
Originally Posted by eyal282 View Post
Use a database or clientprefs to save across server restarts.
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.
__________________

Last edited by azalty; 06-11-2022 at 18:35. Reason: bug fix
azalty is offline
Gena
Member
Join Date: May 2022
Location: Uruguay
Old 06-12-2022 , 05:09   Re: Save user for x time
Reply With Quote #5

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.
..
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.
you missed the includes and the g_bChecked[MAXPLAYERS + 1];

Code:
#include <sourcemod> 
#include <sdktools> 
#include <sdkhooks> 
#include <cstrike>

g_bChecked[MAXPLAYERS + 1];
If I'm not mistaken, I have to add that, when I can I'll try it
__________________
Servers of CS:GO - Private Plugins
Steam ~ GenaEscobar#2338
sorry for my english as a translator d:
Gena is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 06-12-2022 , 05:19   Re: Save user for x time
Reply With Quote #6

Sorry, g_bChecked was a leftover

Code:
#include <sourcemod>
#include <cstrike>

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_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);
}
__________________
azalty is offline
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
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 06-12-2022 , 13:21   Re: Save user for x time
Reply With Quote #8

Quote:
Originally Posted by eyal282 View Post
Average cherry picking enjoyer.
Yea sorry, my bad, wasn't on purpose.
Didn't see that you proposed using a StringMap, just learned about their existence and yea, it seems like an even better solution. Not exactly sure how it works so can't say.
__________________

Last edited by azalty; 06-12-2022 at 13:21.
azalty is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 06-12-2022 , 13:34   Re: Save user for x time
Reply With Quote #9

Quote:
Originally Posted by azalty View Post
Yea sorry, my bad, wasn't on purpose.
Didn't see that you proposed using a StringMap, just learned about their existence and yea, it seems like an even better solution. Not exactly sure how it works so can't say.
It stores key <---> value pair ( like keyvalues ) without nodes or trees, the key is always required to be a string ( like Steam ID, so you don't need IntToString... ) and the value can be anything.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:49.


Powered by vBulletin®
Copyright ©2000 - 2022, vBulletin Solutions, Inc.
Theme made by Freecode