View Single Post
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin D.
Old 02-26-2022 , 05:05   Re: Rename players to prevent taking CLAN tag
Reply With Quote #6

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"OnPlayerChangedNameEventHookMode_Pre);
    
PrintToServer("Loaded %s v%s"PLUGIN_NAMEPLUGIN_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(clientstrNicknamesizeof(strNickname));
    
ReplaceString(strNicknamesizeof(strNickname), TAG"");
    
TrimString(strNickname);
    
Format(strNicknamesizeof(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(clientstrNickname);


Action OnPlayerChangedName(Event event, const char[] namebool 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"oldnamesizeof(oldname));
    
event.GetString("newname"newnamesizeof(newname));
    
    if (
ReplaceString(newnamesizeof(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(clientnewname);
    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
__________________

Last edited by finishlast; 02-26-2022 at 05:06.
finishlast is offline