So it looks like this now:
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#define PLUGIN_NAME "[INS] Admin TAG"
#define PLUGIN_VERSION "0.02"
#define TAG "[♛]" // The admin tag you want to use. Don't include a space at the end.
#define TAG_SPACE " " // Defines what should be between the tag and the username. Set it to be an empty string "" to have no spacer.
bool g_bNameChanged[MAXPLAYERS + 1];
public Plugin myinfo = {
name = PLUGIN_NAME,
author = "Linothorax",
description = "Add [♛] infront of Playername",
version = PLUGIN_VERSION,
url = ""
};
public void OnPluginStart() {
HookEvent("player_changename", OnPlayerChangedName, EventHookMode_Pre);
PrintToServer("Loaded %s v%s", PLUGIN_NAME, PLUGIN_VERSION);
}
public void OnClientPostAdminCheck(int client) {
g_bNameChanged[client] = false;
if (GetUserAdmin(client) != INVALID_ADMIN_ID) {
GiveAdminTag(client);
}
}
void GiveAdminTag(int client) {
char strNickname[156];
GetClientName(client, strNickname, sizeof(strNickname));
ReplaceString(strNickname, sizeof(strNickname), TAG, "");
TrimString(strNickname);
Format(strNickname, sizeof(strNickname), TAG ... TAG_SPACE ... "%s", strNickname); // refering to strNickname is allowed because we use Format(). It won't work with FormatEx().
g_bNameChanged[client] = true;
SetClientName(client, strNickname);
}
Action OnPlayerChangedName(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
// Prevents infinite loops
if (g_bNameChanged[client]) {
g_bNameChanged[client] = false;
return Plugin_Continue;
}
// Adds back the admin tag
if (GetUserAdmin(client) != INVALID_ADMIN_ID) {
GiveAdminTag(client);
return Plugin_Continue;
}
char oldname[156];
char newname[156];
event.GetString("oldname", oldname, sizeof(oldname));
event.GetString("newname", newname, sizeof(newname));
if (ReplaceString(newname, sizeof(newname), TAG, "") == 0) { // they don't have the admin tag
return Plugin_Continue;
}
// else, we already removed any admin tag in their username
TrimString(newname); // Removes any spaces before and after the username
g_bNameChanged[client] = true; // prevents infinite loops
SetClientName(client, newname);
return Plugin_Continue;
}
When I connect as admin and change name, then I have the ♛ in front of name, when I do
setinfo name "test"
the name stays old with ♛ in front
if I do it a second time, I get the new name without ♛
Connect to server
Name= [♛] Originalname
setinfo name "TEST"
Name= [♛] Originalname
setinfo name "TEST"
Name= TEST
setinfo name "TEST"
Name= TEST
I would think it would strip the crown on player_changename and then readds it for admins but this does not happen.
Thank you for your patience and work btw
__________________