[CS:S] Admin Tag [toggle]

FORYOU145

Участник
Сообщения
39
Реакции
16
Здрасте форумчане, помогите оптимизировать код.
C-подобный:
#include <sourcemod>

new bool:ClientUseTag[MAXPLAYERS+1] = {false,...};

public Plugin:myinfo =
{
	name = "Custom Admin Prefixes",
	author = "Marcus",
	description = "A plugin that addes special prefixes to your name if you are admin.",
	version = "1.0.0",
	url = "http://snbx.info"
};
enum AdminLevel{
	AL_None=0,
	AL_Admin
};
public OnClientPostAdminCheck(client)
{
	new AdminId:id = GetUserAdmin(client);
	if (id != INVALID_ADMIN_ID)
	{
		ClientUseTag[client] = true;
	}
} 
public OnPluginStart()
{
	RegAdminCmd("sm_admintag", Command_ATag, ADMFLAG_GENERIC);
	AddCommandListener(HookPlayerChat, "say");
}
public Action:Command_ATag(client, args)
{
	if (!ClientUseTag[client])
	{
		PrintToChat2(client, "\x070069DC[Notice]\x01 You have now enabled your admin tag.");
		ClientUseTag[client] = true;
	}
	else if (ClientUseTag[client])
	{
		PrintToChat2(client, "\x070069DC[Notice]\x01 You have now disabled your admin tag.");
		ClientUseTag[client] = false;
	}
}
public AdminLevel:GetAdmin(client)
{
	if(IsValidClient(client))
	{
		if(!GetUserFlagBits(client))
			return AL_None;
		else if(GetUserFlagBits(client)&ADMFLAG_GENERIC > 0)
			return AL_Admin;
	}
	return AL_None;
}
stock bool:IsValidClient( client ) 
{
    if((1<=client<= MaxClients ) && IsClientInGame(client)) 
        return true; 
     
    return false; 
}
public Action:HookPlayerChat(client, const String:command[], args)
{
	if (IsClientInGame(client) && ClientUseTag[client])
	{
		decl String:szText[256], String:szAuthId[32];
		szText[0] = '\0';
		GetCmdArg(1, szText, sizeof(szText));
		GetClientAuthString(client, szAuthId, 32);

		if (szText[0] != '/' && szText[0] != '!')
		{
			
			if (GetAdmin(client) == AL_Admin)
			{
				PrintToChatAll2("\x07DC6900[Admin]\x01 %N: \x070069DC%s\x01",client, szText);
			}
			if (GetAdmin(client) == AL_None)
			{
				return Plugin_Handled;
			}
		}
		return Plugin_Handled;
	}
	return Plugin_Continue;
}
public PrintToChat2(client, const String:format[], any:...)
{
	decl String:buffer[256];
	SetGlobalTransTarget(client);
	VFormat(buffer, sizeof(buffer), format, 3);
	
	new Handle:bf = StartMessageOne("SayText2", client, USERMSG_RELIABLE|USERMSG_BLOCKHOOKS);
	BfWriteByte(bf, -1);
	BfWriteByte(bf, true);
	BfWriteString(bf, buffer);
	EndMessage();
}
public PrintToChatAll2(const String:format[], any:...)
{
	decl String:buffer[256];
	VFormat(buffer, sizeof(buffer), format, 2);
	
	new Handle:bf = StartMessageAll("SayText2", USERMSG_RELIABLE|USERMSG_BLOCKHOOKS);
	BfWriteByte(bf, -1);
	BfWriteByte(bf, true);
	BfWriteString(bf, buffer);
	EndMessage();
}
 
Последнее редактирование:

R1KO

fuck society
Сообщения
9,457
Реакции
7,786
  • Команда форума
  • #2
PHP:
#include <sourcemod>

new bool:ClientUseTag[MAXPLAYERS+1] = {false,...};

public Plugin:myinfo =
{
	name = "Custom Admin Prefixes",
	author = "Marcus",
	description = "A plugin that addes special prefixes to your name if you are admin.",
	version = "1.0.0",
	url = "http://snbx.info"
};


public OnClientPostAdminCheck(client)
{
	ClientUseTag[client] = (!IsFakeClient(client) && GetUserAdmin(client) != INVALID_ADMIN_ID);

}

public OnPluginStart()
{
	RegAdminCmd("sm_admintag", Command_ATag, ADMFLAG_GENERIC);
	AddCommandListener(HookPlayerChat, "say");
}

public Action:Command_ATag(client, args)
{
	if (!ClientUseTag[client])
	{
		PrintToChat2(client, "\x070069DC[Notice]\x01 You have now enabled your admin tag.");
		ClientUseTag[client] = true;
	}
	else if (ClientUseTag[client])
	{
		PrintToChat2(client, "\x070069DC[Notice]\x01 You have now disabled your admin tag.");
		ClientUseTag[client] = false;
	}
}

public Action:HookPlayerChat(client, const String:command[], args)
{
	if (client && IsClientInGame(client) && ClientUseTag[client])
	{
		decl String:szText[256];
		szText[0] = '\0';
		GetCmdArg(1, szText, sizeof(szText));

		if (szText[0] != '/' && szText[0] != '!')
		{
			PrintToChatAll2("\x07DC6900[Admin]\x01 %N: \x070069DC%s\x01",client, szText);
			
			return Plugin_Handled;
		}
	}
	return Plugin_Continue;
}

public PrintToChatAll2(const String:format[], any:...)
{
	decl String:buffer[256];
	VFormat(buffer, sizeof(buffer), format, 2);
	
	new Handle:bf = StartMessageAll("SayText2", USERMSG_RELIABLE|USERMSG_BLOCKHOOKS);
	BfWriteByte(bf, -1);
	BfWriteByte(bf, true);
	BfWriteString(bf, buffer);
	EndMessage();
}
 

FORYOU145

Участник
Сообщения
39
Реакции
16
C-подобный:
/groups/sourcemod/upload_tmp/textT6rr2B.sp(31) : error 017: undefined symbol "PrintToChat2"
/groups/sourcemod/upload_tmp/textT6rr2B.sp(36) : error 017: undefined symbol "PrintToChat2"
 

R1KO

fuck society
Сообщения
9,457
Реакции
7,786
  • Команда форума
  • #4
FORYOU145, верни функцию
PHP:
public PrintToChat2(client, const String:format[], any:...)
{
	decl String:buffer[256];
	SetGlobalTransTarget(client);
	VFormat(buffer, sizeof(buffer), format, 3);
	
	new Handle:bf = StartMessageOne("SayText2", client, USERMSG_RELIABLE|USERMSG_BLOCKHOOKS);
	BfWriteByte(bf, -1);
	BfWriteByte(bf, true);
	BfWriteString(bf, buffer);
	EndMessage();
}
А то я не заметил где она юзается и удлалил.
 

The End Is Near...

Russian Roulette
Сообщения
874
Реакции
691
R1KO
PHP:
public Action:Command_ATag(client, args)
{
	PrintToChat2(client, "\x070069DC[Notice]\x01 You have now %s your admin tag.", (ClientUseTag[client] = !ClientUseTag[client]) ? "enabled" : "disabled");

	return Plugin_Handled;
}
 

AlecsandeR

Участник
Сообщения
14
Реакции
1
Hello, how I can add my custom tags? I need a plugin for SCOREBOARD and Chat. Thanks!
 
Сверху Снизу