Add GetClientOriginalLanguage#1810
Conversation
asherkin
left a comment
There was a problem hiding this comment.
The IGamePlayer change here will break extensions, you need to add the functions to the end of the interface and adjust the compatibility check function so that old exts can load on the new version (and new ones only on the new one).
I'm not sure it really makes sense to add ResetLanguageId / ResetClientLanguage - it seems fairly straightforward that it's just SetLanguage(GetOriginalLanguage()). I'm also not sure about the term "reset" - as the "initial" language is the server language.
Storing and exposing the original language ID definitely seems useful though.
Where would I find that? My guess is I would increment |
Yeah - look at |
|
I think I did it? public void OnPluginStart()
{
HookEvent("player_team", Event_PlayerTeam);
}
public void Event_PlayerTeam(Event event, const char[] name, bool bDontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (client == 0 || IsFakeClient(client))
return;
int original = GetOriginalLanguage(client);
PrintToServer("LANG: %i, %i", GetClientLanguage(client), original);
SetClientLanguage(client, GetLanguageByCode("pl"));
original = GetOriginalLanguage(client);
PrintToServer("LANG: %i, %i", GetClientLanguage(client), original);
SetClientLanguage(client, original);
PrintToServer("LANG: %i, %i", GetClientLanguage(client), original);
} |
|
Yep the logic looks fine now and we're safe with the iface version bump. I think it'd just be good to validate that it's non-breaking and my brain isn't up to checking the |
|
I'd prefer following SMs other API naming scheme by mentioning the target of the function |
I was going to call it that originally but I thought it was too long, fixed |
|
Don't worry, that name isn't even in the same league as Java names for length. |
|
This looks good. Thank you! I did catch that the line below is unnecessary and can be pulled (see sourcemod/core/PlayerManager.cpp Line 518 in b2265da |

It seems reasonable that while there are functions to change a client's language, there should also be function to restore it back--both with the natives and also internally.
My use case for this is I was making a language selection menu and had to implement this logic manually.
In fact, every plugin that modifies the client's language would have to do so (particularly during OnPluginEnd) to be correctly written.
It makes sense then that a correct implementation is built in natively instead.
I'm not entirely sure that I'm supposed to set it inside PlayerManager::HandleConVarQuery(), but it looks like that's just an async way of getting the client's language for certain games, so I did.
Tested with the following code