[code]
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Tags"
#define VERSION "1.0"
#define AUTHOR "Khalid"
#define MAX_TAG_CHARACTERS 20
//#define USE_STEAMID
new Trie:gTrie
new g_szTag[33][MAX_TAG_CHARACTERS + 1]
new const FILE[] = "addons/amxmodx/configs/tags.ini"
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say", "hook_say")
gTrie = TrieCreate()
ReadFile()
register_concmd("amx_reload_tags", "AdminReloadTags", ADMIN_RCON)
register_concmd("amx_add_tag", "AdminAddTag", ADMIN_RCON, "<name> <tag> - Adds a tag for a player")
}
public client_putinserver(id)
{
new szAccessCode[35];
#if defined USE_STEAMID
get_user_authid(id, szAccessCode, charsmax(szAccessCode))
#else
get_user_name(id, szAccessCode, charsmax(szAccessCode))
#endif
if(TrieKeyExists(gTrie, szAccessCode))
TrieGetString(gTrie, szAccessCode, g_szTag[id], charsmax(g_szTag[]))
}
public client_disconnect(id)
g_szTag[id][0] = '^0'
public AdminAddTag(id, level, cid)
{
if(!cmd_access(id, level, cid, 3))
return PLUGIN_HANDLED
new szName[32], iPlayer
read_argv(1, szName, 31); read_argv(2, g_szTag[iPlayer], charsmax(g_szTag[]))
if( !( iPlayer = cmd_target(id, szName, CMDTARGET_ALLOW_SELF) ) )
{
console_print(id, "Player must be connected")
return PLUGIN_HANDLED
}
if(g_szTag[id][0])
{
console_print(id, "Player already have a tag")
return PLUGIN_HANDLED
}
#if defined USE_STEAMID
new szAuthId[35]
get_user_authid(iPlayer, szAuthId, charsmax(szAuthId))
#endif
get_user_name(iPlayer, szName, charsmax(szName))
new f = fopen(FILE, "w")
fseek(f, 0, SEEK_END)
#if defined USE_STEAMID
fprintf(f, "^"%s^" ^"%s^"", szAuthId, g_szTag[iPlayer])
#else
fprintf(f, "^"%s^" ^"%s^"", szName, g_szTag[iPlayer])
#endif
fclose(f)
#if defined USE_STEAMID
TrieSetString(gTrie, szAuthId, g_szTag[iPlayer])
#else
TrieSetString(gTrie, szName, g_szTag[iPlayer])
#endif
console_print(id, "Successfully added tag %s for player %s", g_szTag[iPlayer], szName)
return PLUGIN_HANDLED
}
public AdminReloadTags(id, level, cid)
{
if(!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
TrieClear(gTrie)
for(new i; i < sizeof(g_szTag); i++)
{
g_szTag[0] = '^0'
}
console_print(id, "Successfully reloaded file")
ReadFile()
new iPlayers[32], iNum, iPlayer
new szAccessCode[35]
get_players(iPlayers, iNum, "ch")
for(new i; i < iNum; i++)
{
iPlayer = iPlayers
#if defined USE_STEAMID
get_user_authid(iPlayer, szAccessCode, charsmax(szAccessCode))
#else
get_user_name(iPlayer, szAccessCode, charsmax(szAccessCode))
#endif
if(TrieKeyExists(gTrie, szAccessCode))
{
TrieGetString(gTrie, szAccessCode, g_szTag[iPlayer], charsmax(g_szTag[]))
}
}
return PLUGIN_HANDLED
}
ReadFile()
{
new szLine[100]
if(!file_exists(FILE))
{
write_file(FILE, "; Tags File -> By Khalid :)")
write_file(FILE, "; Any line starting with ; is a comment")
write_file(FILE, "; How to put tags?")
#if defined USE_STEAMID
write_file(FILE, "; ^"SteamID^" ^"Tag^"")
#else
write_file(FILE, "; ^"Name^" ^"Tag^"")
#endif
formatex(szLine, charsmax(szLine), "; Tags cannot exceed more than %d characters.", MAX_TAG_CHARACTERS)
formatex(szLine, charsmax(szLine), "; If you want more, edit the sma at line 8")
write_file(FILE, szLine)
return;
}
new f = fopen(FILE, "r")
new szAccessCode[35], szTag[MAX_TAG_CHARACTERS + 1]
while(!feof(f))
{
fgets(f, szLine, 99)
replace(szLine, charsmax(szLine), "^n", "")
if(!szLine[0] || szLine[0] == ';')
continue;
strbreak(szLine, szAccessCode, charsmax(szAccessCode), szTag, charsmax(szTag))
remove_quotes(szAccessCode)
remove_quotes(szTag)
if(TrieKeyExists(gTrie, szAccessCode))
{
#if defined USE_STEAMID
log_amx("Failed to add Tag for player with SteamID: '%s' as he already has a tag.", szAccessCode)
#else
log_amx("Failed to add tag for player with the name '%s' as he already has a tag.", szAccessCode)
#endif
continue;
}
TrieSetString(gTrie, szAccessCode, szTag)
}
fclose(f)
}
public hook_say(id)
{
if(!g_szTag[id][0])
return PLUGIN_CONTINUE
static szMessage[191], szLastFormat[200], szName[32]
new iAlive
read_argv(1, szMessage, charsmax(szMessage))
if(!szMessage[0])
return PLUGIN_CONTINUE
get_user_name(id, szName, 31)
formatex(szLastFormat, charsmax(szLastFormat), "%s^4%s ^3%s ^1: %s", ( ( iAlive = is_user_alive(id) ) ? "" : ( get_user_team(id) == 3 ? "^1*SPEC* " : "^1*DEAD* ") ), g_szTag[id], szName, szMessage)
server_print("get_user_team(id) = %d", get_user_team(id))
Print(id, szLastFormat, iAlive)
return PLUGIN_HANDLED_MAIN
}
Print(id, Message[], iAlive)
{
static SayText
if(!SayText)
SayText = get_user_msgid("SayText")
new players[32], iNum
get_players(players, iNum, iAlive ? "ach" /* Skip Dead */ : "bch" /* Skip Alive */)
for(new i; i < iNum; i++)
{
message_begin(MSG_ONE, SayText,_, players)
write_byte(id)
write_string(Message)
message_end()
}
}[/code]