View Single Post
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 01-23-2021 , 22:06   Re: [ANY] Keep Player Name [Updated 23-01-21] Version 1.1.3
Reply With Quote #26

Quote:
Originally Posted by Teamkiller324 View Post
[...] as i somehow messed that part up lol, my bad
Don't worry, just make it even better...

Quote:
Originally Posted by Teamkiller324 View Post
OnClientSettingsChanged function is not working properly and just spams errors instead and is disabled temporarily
Maybe if you did the actual coding properly, it would work properly too? The errors are signs that you are not doing things "properly".

Your code that included "OnClientSettingsChanged", also seem to be including a
Code:
stock	bool	IsValidClient(int client)
where a lot (BUT NOT ALL!) of your functions uses IsValidClient first.

OnClientSettingsChanged did however not.

Code:
public	void	OnClientSettingsChanged(int client)	{
	if(IsClientInGame(client) && !IsFakeClient(client))	{
		if(GetClientTeam(client) > 0)	{
			setcookies(client,	true);
		}
	}
}
... so maybe, if you changed that one to:

Code:
public	void	OnClientSettingsChanged(int client)	{
/* Added IsValidClient before IsClientInGame */
/* Removed IsFakeClient, as it is already a part of  IsValidClient */
	if(IsValidClient(client) && IsClientInGame(client))	{
		if(GetClientTeam(client) > 0)	{
			setcookies(client,	true);
		}
	}
}
should solve the issue, as IsValidClient already checks if the client id is 1 or below/equal to MaxClients, ... if you really insist on mixing different patterns across your code.


OR, AN ALTERNATIVE WAY FOR MORE CONSISTENCY: Change your IsValidClient bool, to like e.g.:

Code:
stock	bool	IsValidClient(int client)	{
	if(client	<	1)
		return	false;
	if(client	>	MaxClients)
		return	false;
/* ADDITIONS BELOW */
	if(!IsClientInGame(client))
		return	false;
/* ADDITIONS ABOVE */
	if(IsFakeClient(client))
		return	false;
	return	true;
}
And simply used e.g.:

Code:
public	void	OnClientSettingsChanged(int client)	{
/* Changed IsClientInGame, to your IsValidClient */
/* Removed IsFakeClient, as it is already a part of  IsValidClient */
	if(IsValidClient(client))	{
		if(GetClientTeam(client) > 0)	{
			setcookies(client,	true);
		}
	}
}
This way, you can also add multiple sanity checks to your IsValidClient, and make one change stick across all your functions, where you use your IsValidClient.


Code:
if(GetClientTeam(client) > 0)
0 is unassigned, but the actual spectator is above 0, as far as I remember?

Do you really care about spectators? Otherwise, you might want to look into this one somehow else.

From include/cstrike.inc, after commit a615c13, made on 2021-01-14:

Code:
#define CS_TEAM_NONE        0   /**< No team yet. */
#define CS_TEAM_SPECTATOR   1   /**< Spectators. */
#define CS_TEAM_T           2   /**< Terrorists. */
#define CS_TEAM_CT          3   /**< Counter-Terrorists. */
From include/tf2.inc, after commit a615c13, made on 2021-01-14:

Code:
enum TFTeam
{
	TFTeam_Unassigned = 0,
	TFTeam_Spectator = 1,
	TFTeam_Red = 2,
	TFTeam_Blue = 3
};

I cannot guarantee you that all games have the same "team numbers" though, but if you don't care about spectators, just as you don't care about unassigned, ... maybe you should also update your "filters" here?


Just my two cents, ... or maybe a couple of more cents, but whatever.


Quote:
Originally Posted by Tonblader View Post
In Left 4 Dead 2 Listen Server Windows, when i use sm_forcename Tonblader hola , my game crash, no errorlog.
I see many threads saying: SourceMod is NOT supported on "listen servers".

Switch to SRCDS, and most (if not all) of your issues will likely vanish.

Quote:
Originally Posted by Tonblader View Post
It's true, this worked, the bad thing is that the errorlog will be spamming me with the client index 0 problem.
Even with some of the coding suggestions above, it most likely still won't work for you, when you are running a listen server...
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline