Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
|
08-05-2014
, 19:54
Constant string return only first letter...
|
#1
|
Hey! I want to ask something, that I was wondering on for a long time... When I use the constant g_szAdminPrefixes with second subscripting of [string], it always returns the first letter of the line...
Is it the problem from formatex() or from the indexing, or what? I can't find out (probably something pretty simple).
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx> #include <nvault> #include <colorchat>
#define PLUGIN "Player Ranks Admin Prefix" #define VERSION "1.0" #define AUTHOR "Flicker"
new player_points[33] new player_rank[33] new player_flags[33]
new g_nVault
new g_iMaxPlayers
//new const g_szPrefix[] = "[SJ Ranks]"
enum _:eData { string[64], integer }
new const g_szAdminPrefixes[][eData] = { "", {"Head Admin", ADMIN_LEVEL_A}, {"Help Admin", ADMIN_LEVEL_B}, {"Test Admin", ADMIN_LEVEL_C}, {"Admin", ADMIN_LEVEL_D}, {"VIP Level 1", ADMIN_LEVEL_E}, {"VIP Level 2", ADMIN_LEVEL_F}, {"VIP Level 3", ADMIN_LEVEL_G} }
new const g_szPlayerRanks[][eData] = { {"Slabak", 20}, {"Napredvam", 30}, {"Pochvam da shvashtam", 40}, {"Novacite sled men", 50}, {"Edin ot nai-dobrite", 60}, {"Pro", 70}, {"Proto na otbora", 80}, {"Proto na botovete", 100}, {"Pro master", 130}, {"Shef na igrachite", 160}, {"Shefa tuk", 200}, {"Shefa v servera", 300}, {"Player VIP", 500}, {"Player Admin", 800}, {"Budesht Admin", 999999999999} }
new const g_szTeamNames[][]= { "^1(Unassigned)", "^1(Terrorist)", "^1(Counter-Terrorist)", "^1(Spectator)" }
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR) register_clcmd("say", "cmdSay") register_clcmd("say_team", "cmdSayTeam") g_nVault = nvault_open("RandomVault") g_iMaxPlayers = get_maxplayers() }
public cmdSay(id) MainActionPrefixes(id, false) public cmdSayTeam(id) MainActionPrefixes(id, true) stock MainActionPrefixes(const id, const bool:IsTeamMsg) { new szMessage[192], szText[192] read_args(szText, charsmax(szText)) remove_quotes(szText) if(szText[0] == '/' || szText[0] == '#' || szText[0] == '.' || szText[0] == '!') return PLUGIN_CONTINUE new szName[32] get_user_name(id, szName, charsmax(szName)) new alive[11], isAlive = is_user_alive(id) copy(alive, charsmax(alive), isAlive ? "" : "^1*DEAD*") formatex(szMessage, charsmax(szMessage), "^1%s%s^3[^4%s^3] %s^1 :%s %s", alive, IsTeamMsg ? g_szTeamNames[get_user_team(id)] : "", player_flags[id] ? g_szAdminPrefixes[player_flags[id]][string] : g_szPlayerRanks[player_rank[id]][string], szName, player_flags[id] ? "^4" : "^1", szText)
new icolor switch(get_user_team(id)) { case 0: icolor = GREY case 1: icolor = RED case 2: icolor = BLUE case 3: icolor = GREY } for(new player = 1; player < g_iMaxPlayers; player++) if(is_user_connected(player)) if(isAlive && is_user_alive(player) || !isAlive && !is_user_alive(player)) if(IsTeamMsg && get_user_team(id) == get_user_team(player) || !IsTeamMsg) ColorChat(player, icolor, szMessage) return PLUGIN_CONTINUE }
public client_putinserver(id) { new iFlags = get_user_flags(id) for(new i = 1; i < sizeof g_szAdminPrefixes; i++) { if(iFlags & g_szAdminPrefixes[i][integer]) { player_flags[id] = i break } else continue } LoadPoints(id) }
public client_disconnect(id) SavePoints(id)
public SavePoints(id) { new szName[32], szKey[32], szData[256] get_user_name(id, szName, charsmax(szName)) formatex(szKey, charsmax(szKey), "%s-XP", szName) formatex(szData, charsmax(szData), "%i#%i#", player_points[id], player_rank[id]) nvault_set(g_nVault, szKey, szData) return PLUGIN_CONTINUE } public LoadPoints(id) { new szName[32], szKey[32], szData[256] get_user_name(id, szName, charsmax(szName)) formatex(szKey, charsmax(szKey), "%s-XP", szName) formatex(szData, charsmax(szData), "%i#%i#", player_points[id], player_rank[id]) nvault_get(g_nVault, szKey, szData, charsmax(szData)) replace_all(szData, charsmax(szData), "#", " ") new szPoints[32], szRank[32] parse(szData, szPoints, charsmax(szPoints), szRank, charsmax(szRank)) player_points[id] = str_to_num(szPoints) player_rank[id] = str_to_num(szRank) return PLUGIN_CONTINUE }
public plugin_end() nvault_close(g_nVault)
The problem actually occurs here:
PHP Code:
formatex(szMessage, charsmax(szMessage), "^1%s%s^3[^4%s^3] %s^1 :%s %s", alive, IsTeamMsg ? g_szTeamNames[get_user_team(id)] : "", player_flags[id] ? g_szAdminPrefixes[player_flags[id]][string] : g_szPlayerRanks[player_rank[id]][string], szName, player_flags[id] ? "^4" : "^1", szText)
when formatexing the chat message. The prefix is got from this const:[php]g_szAdminPrefixes[player_flags[id]][string][php] As you will see below, this way of use usually works, but here there is some problem and it returns only the first letter. Same happens with the const for player ranks here:
PHP Code:
g_szPlayerRanks[player_rank[id]][string]
Is the problem from the indexing, or something with the enum...?
Tested the same method here:
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
enum _:eData { string[64], integer }
new const g_szMyTestConst[][eData] = { {"My First String", 1}, {"My Second String", 2}, {"My Third String", 3} }
public plugin_init() { register_clcmd("say /test", "cmdTest") } public cmdTest(id) { new iRand = random(sizeof g_szMyTestConst) client_print(id, print_chat, "String: %s | Integer: %d", g_szMyTestConst[iRand][string], g_szMyTestConst[iRand][integer]) }
And it works pretty accurate:
Thanks for any help and sorry fro the undescriptive problem.
__________________
Last edited by Flick3rR; 08-06-2014 at 07:01.
|
|