Hi, I have a problem with this code.
Code:
#include <sourcemod>
#include <cstrike>
#include <clientprefs>
#include <chat-processor>
Handle: OnlyAdmins
Handle: CheckTags
Handle: PrintTagAssign
Handle: OnlyNamed
Handle: NameStr
new Handle: ClientTag = INVALID_HANDLE
new Handle: ClientTagColor = INVALID_HANDLE
new Handle: RestrictedTags = INVALID_HANDLE
new String: RestrictedTagsFile[ PLATFORM_MAX_PATH ]
#define flag ADMFLAG_CUSTOM1
public Plugin:myinfo = {
name = "Rich Client Tags",
author = "tre3fla",
description = "Jucatorii isi pot pune tag-uri in chat si scoreboard",
version = "0.2",
url = "http://extreamcs.com/forum"
}
public OnPluginStart( ) {
OnlyAdmins = CreateConVar( "sm_tag_access_only_admins", "1", "0=toti jucatorii au acces la tag-uri, 1=doar admini cu un anumit flag" )
CheckTags = CreateConVar( "sm_tag_check", "1", "0=jucatorii isi pun ce tag vor, 1=nu isi pot pune tag-urile banate" )
PrintTagAssign = CreateConVar( "sm_print_on_tag_asssign", "1", "0=dezactivat, 1=jucatorului o sa-i apara un mesaj cand i se seteaza tag-ul, inclusiv la connectare" )
OnlyNamed = CreateConVar( "sm_tag_only_advertisers", "1", "0=dezactiva, 1=jucatorii trebuie sa poarte ceva la nume pentru a-l folosi" )
NameStr = CreateConVar( "sm_needed_name", "NEGEV.RO", "Cuvantul care trebuie sa fie in componenta numelui pentru a folosi comanda !tag" )
ClientTag = RegClientCookie( "ClientTag", "Tag-ul ales de jucator", CookieAccess_Protected )
ClientTagColor = RegClientCookie( "ClientTagColor", "Culoarea pentru tag", CookieAccess_Protected )
RegConsoleCmd( "tag", Command_AssignTag )
RegConsoleCmd( "tc", Command_AssignTagColor )
RegConsoleCmd( "tagcolor", Command_AssignTagColor )
RegConsoleCmd( "tagcolorsinfo", Command_ShowColorInfo )
RegConsoleCmd( "tagdisable", Command_DisableTag )
HookEvent( "player_spawn", Event_PlayerSpawn )
HookEventEx( "player_connect_full", player_connect_full )
}
public OnMapStart( ) {
ReadForbiddenTags( )
}
public player_connect_full( Event:event, const String:name[ ], bool:dontBroadcast ) {
new client = GetClientOfUserId( GetEventInt( event, "userid" ) )
if( IsClientConnected( client ) && !IsFakeClient( client ) ) {
CreateTimer( 0.5, TagTheClient, client )
}
}
public Action: Event_PlayerSpawn( Event event, const char[ ] name, bool dontBroadcast ) {
int ClientUserId = GetEventInt( event, "userid" )
int client = GetClientOfUserId( ClientUserId )
decl String: Tag[ 16 ]
GetClientCookie( client, ClientTag, Tag, sizeof( Tag ) )
if( strlen( Tag ) > 0 ) {
CS_SetClientClanTag( client, Tag )
}
}
public Action: Command_AssignTag( client, args ) {
if( GetConVarInt( OnlyAdmins ) > 0 ) {
if( !CheckCommandAccess( client, "sm_someoverride", flag ) ) {
PrintToChat( client, "*\x02 You have no access to this command!" )
return Plugin_Handled
}
}
if( GetConVarInt( OnlyNamed ) > 0 ) {
decl String: SuperName[ 32 ]
GetClientName( client, SuperName, sizeof( SuperName ) )
decl String: SuperWord[ 32 ]
GetConVarString( NameStr, SuperWord, sizeof( SuperWord ) )
if( StrContains( SuperName, SuperWord ) == -1 || StrContains( SuperName, SuperWord, true ) == -1 ) {
PrintToChat( client, " \x02You have to wear\x04 %s\x01 on your name to use this command!", SuperWord )
return Plugin_Handled
}
}
decl String: ChoosenTag[ 32 ]
GetCmdArgString( ChoosenTag, sizeof( ChoosenTag ) )
if( args < 1 ) {
PrintToChat( client, "*\x04 Usage:\x02 !tag\x01 <you tag>" )
return Plugin_Handled
}
if( strlen( ChoosenTag ) > 15 ) {
PrintToChat( client, "*\x02 The tag you have choosen is too long. The tag can be 12 characters long!" )
return Plugin_Handled
}
if( GetConVarInt( CheckTags ) > 0 ) {
decl String: BannedTags[ 1024 ]
for( new i = 0; i < GetArraySize( RestrictedTags ); i++ ) {
GetArrayString( RestrictedTags, i, BannedTags, sizeof( BannedTags ) )
if( StrContains( ChoosenTag, BannedTags ) != -1 ) {
PrintToChat( client, "*\x02 Your tag or a part of it is forbidden, please choose another tag!" )
return Plugin_Handled
}
}
}
CS_SetClientClanTag( client, ChoosenTag )
SetClientCookie( client, ClientTag, ChoosenTag )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "*\x09 Your tag has been succesifull modified!" )
PrintToChat( client, "*\x09 Your new tag is\x04 %s", ChoosenTag )
}
return Plugin_Continue
}
public Action: Command_AssignTagColor( client, args ) {
if( args < 1 ) {
PrintToChat( client, "*\x04 Usage:\x02 !tagcolor\x01 <color>\x04 - type\x02 !tagcolorsinfo\x01 for more info" )
return Plugin_Handled
}
decl String: Color[ 32 ]
GetCmdArg( 1, Color, sizeof( Color ) )
if( StrEqual( Color, "team" ) ) {
SetClientCookie( client, ClientTagColor, "" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now team color!" )
}
}
else if( StrEqual( Color, "white" ) ) {
SetClientCookie( client, ClientTagColor, "\x01" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now white!" )
}
}
else if( StrEqual( Color, "red" ) ) {
SetClientCookie( client, ClientTagColor, "\x07" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now\x07 red!" )
}
}
else if( StrEqual( Color, "darkred" ) ) {
SetClientCookie( client, ClientTagColor, "\x02" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now\x02 darkred!" )
}
}
else if( StrEqual( Color, "lightred" ) ) {
SetClientCookie( client, ClientTagColor, "\x0F" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x0Flightred!" )
}
}
else if( StrEqual( Color, "green" ) ) {
SetClientCookie( client, ClientTagColor, "\x04" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x04green!" )
}
}
else if( StrEqual( Color, "lightgreen" ) ) {
SetClientCookie( client, ClientTagColor, "\x05" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x05lightgreen!" )
}
}
else if( StrEqual( Color, "lime" ) ) {
SetClientCookie( client, ClientTagColor, "\x06" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x06lime!" )
}
}
else if( StrEqual( Color, "purple" ) ) {
SetClientCookie( client, ClientTagColor, "\x03" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x03purple!" )
}
}
else if( StrEqual( Color, "grey" ) ) {
SetClientCookie( client, ClientTagColor, "\x08" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x08grey!" )
}
}
else if( StrEqual( Color, "grey2" ) ) {
SetClientCookie( client, ClientTagColor, "\x0A" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x0Agrey2!" )
}
}
else if( StrEqual( Color, "grey3" ) ) {
SetClientCookie( client, ClientTagColor, "\x0D" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x0Dgrey3!" )
}
}
else if( StrEqual( Color, "yellow" ) ) {
SetClientCookie( client, ClientTagColor, "\x09" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x09yellow!" )
}
}
else if( StrEqual( Color, "blue" ) ) {
SetClientCookie( client, ClientTagColor, "\x0C" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x0Cblue!" )
}
}
else if( StrEqual( Color, "lightblue" ) ) {
SetClientCookie( client, ClientTagColor, "\x0B" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x0Blightblue!" )
}
}
else if( StrEqual( Color, "pink" ) ) {
SetClientCookie( client, ClientTagColor, "\x0E" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x0Epink!" )
}
}
else if( StrEqual( Color, "orange" ) ) {
SetClientCookie( client, ClientTagColor, "\x10" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "* Your tag color is now \x10orange!" )
}
}
else {
PrintToChat( client, "*\x02 Given color is invalid!" )
return Plugin_Handled
}
return Plugin_Continue
}
public Action: Command_ShowColorInfo( client, args ) {
PrintToChat( client, "*\x01 Available colors are:" )
PrintToChat( client, "white, \x07red \x02darkred, \x0Flightred \x03purple, \x04green, \x05lightgreen, \x06lime, \x08grey, \x0Agrey2, \x0Dgrey3 \x09yellow, \x0Blightblue, \x0Cblue, \x0Epink, \x10orange, \x01team" )
}
public Action: CP_OnChatMessage( int& client, ArrayList recipients, char[] flagstring, char[] name, char[] message, bool& processcolors, bool& removecolors ) {
if( GetConVarInt( OnlyAdmins ) > 0 ) {
if( !CheckCommandAccess( client, "sm_someoverride", flag ) ) {
return Plugin_Continue
}
}
decl String: Tag[ 32 ]
GetClientCookie( client, ClientTag, Tag, sizeof( Tag ) )
decl String: Color[ 32 ]
GetClientCookie( client, ClientTagColor, Color, sizeof( Color ) )
if( StrEqual( Tag, "" ) ) {
return Plugin_Continue
}
if( strlen( Color ) > 0 ) {
switch( GetClientTeam( client ) ) {
case CS_TEAM_NONE: {
Format( name, MAXLENGTH_NAME, " %s%s\x01 %s", Color, Tag, name )
}
case CS_TEAM_SPECTATOR: {
Format( name, MAXLENGTH_NAME, " %s%s\x01 %s", Color, Tag, name )
}
case CS_TEAM_T: {
Format( name, MAXLENGTH_NAME, " %s%s\x09 %s", Color, Tag, name )
}
case CS_TEAM_CT: {
Format( name, MAXLENGTH_NAME, " %s%s\x0B %s", Color, Tag, name )
}
}
}
else {
Format( name, MAXLENGTH_NAME, "%s %s", Tag, name )
}
Format( message, MAXLENGTH_MESSAGE, "%s", message )
return Plugin_Continue
}
public Action: Command_DisableTag( client, args ) {
if( IsClientInGame( client ) && client > 0 && client <= MaxClients ) {
SetClientCookie( client, ClientTag, "" )
CS_SetClientClanTag( client, "" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "*\x02 Your tag has been disabled!" )
}
}
}
public Action: TagTheClient( Handle: timer, any: client ) {
if( IsClientInGame( client ) && client > 0 && client <= MaxClients ) {
decl String: Tag[ 32 ]
GetClientCookie( client, ClientTag, Tag, sizeof( Tag ) )
if( strlen( Tag ) > 0 ) {
if( GetConVarInt( CheckTags ) > 0 ) {
decl String: TagsFromFile[ 1024 ]
for( new i = 0; i < GetArraySize( RestrictedTags ); i++ ) {
GetArrayString( RestrictedTags, i, TagsFromFile, sizeof( TagsFromFile ) )
if( StrContains( Tag, TagsFromFile ) != -1 ) {
SetClientCookie( client, ClientTag, "" )
if( GetConVarInt( PrintTagAssign ) > 0 ) {
PrintToChat( client, "*\x02 Your tag is forbidden and it has been deleted!" )
}
}
else {
CS_SetClientClanTag( client, Tag )
}
}
}
else {
CS_SetClientClanTag( client, Tag )
}
}
}
}
public ReadForbiddenTags( ) {
RestrictedTags = CreateArray( 1024 )
BuildPath( Path_SM, RestrictedTagsFile, sizeof( RestrictedTagsFile ), "configs/RestrictedTags.txt" )
new Handle: RestrictedTagsHolder = OpenFile( RestrictedTagsFile, "r" )
new String: ResultsBuffer[ 1024 ]
while( !IsEndOfFile( RestrictedTagsHolder ) && ReadFileLine( RestrictedTagsHolder, ResultsBuffer, sizeof( ResultsBuffer ) ) ) {
ReplaceString( ResultsBuffer, sizeof( ResultsBuffer ), "\n", "", false )
PushArrayString( RestrictedTags, ResultsBuffer )
}
}