Raised This Month: $12 Target: $400
 3% 

Constant string return only first letter...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-05-2014 , 19:54   Constant string return only first letter...
Reply With Quote #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(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say""cmdSay")
    
register_clcmd("say_team""cmdSayTeam")
    
    
g_nVault nvault_open("RandomVault")
    
    
g_iMaxPlayers get_maxplayers()
}

public 
cmdSay(id)
    
MainActionPrefixes(idfalse)
public 
cmdSayTeam(id)
    
MainActionPrefixes(idtrue)
    
stock MainActionPrefixes(const id, const bool:IsTeamMsg)
{
    new 
szMessage[192], szText[192]
    
read_args(szTextcharsmax(szText))
    
remove_quotes(szText)
    
    if(
szText[0] == '/' || szText[0] == '#' || szText[0] == '.' || szText[0] == '!')
        return 
PLUGIN_CONTINUE
        
    
new szName[32]
    
get_user_name(idszNamecharsmax(szName))
    
    new 
alive[11], isAlive is_user_alive(id)
    
copy(alivecharsmax(alive), isAlive "" "^1*DEAD*")
    
    
    
formatex(szMessagecharsmax(szMessage), "^1%s%s^3[^4%s^3] %s^1 :%s %s"aliveIsTeamMsg g_szTeamNames[get_user_team(id)] : ""player_flags[id] ? g_szAdminPrefixes[player_flags[id]][string] : g_szPlayerRanks[player_rank[id]][string], szNameplayer_flags[id] ? "^4" "^1"szText)

    new 
icolor
    
switch(get_user_team(id))
    {
        case 
0icolor GREY
        
case 1icolor RED
        
case 2icolor BLUE
        
case 3icolor GREY
    
}
    
    for(new 
player 1player g_iMaxPlayersplayer++)
        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(playericolorszMessage)
                    
    return 
PLUGIN_CONTINUE
}

public 
client_putinserver(id)
{
    new 
iFlags get_user_flags(id)
    for(new 
1sizeof g_szAdminPrefixesi++)
    {
        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(idszNamecharsmax(szName))
    
    
formatex(szKeycharsmax(szKey), "%s-XP"szName)
    
    
formatex(szDatacharsmax(szData), "%i#%i#"player_points[id], player_rank[id])
    
    
nvault_set(g_nVaultszKeyszData)
    
    return 
PLUGIN_CONTINUE
}
    
public 
LoadPoints(id)
{
    new 
szName[32], szKey[32], szData[256]
    
get_user_name(idszNamecharsmax(szName))
    
    
formatex(szKeycharsmax(szKey), "%s-XP"szName)
    
    
formatex(szDatacharsmax(szData), "%i#%i#"player_points[id], player_rank[id])
    
    
nvault_get(g_nVaultszKeyszDatacharsmax(szData))
    
    
replace_all(szDatacharsmax(szData), "#"" ")
    
    new 
szPoints[32], szRank[32]
    
parse(szDataszPointscharsmax(szPoints), szRankcharsmax(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(szMessagecharsmax(szMessage), "^1%s%s^3[^4%s^3] %s^1 :%s %s"aliveIsTeamMsg g_szTeamNames[get_user_team(id)] : ""player_flags[id] ? g_szAdminPrefixes[player_flags[id]][string] : g_szPlayerRanks[player_rank[id]][string], szNameplayer_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(idprint_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.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
NikKOo31
Senior Member
Join Date: May 2013
Location: Home
Old 08-05-2014 , 20:12   Re: Constant string return only first letter...
Reply With Quote #2

Idk if you can read user flags in putinserver, maybe you should use client_autorized or client_connect instead
__________________
Hey ^_^
NikKOo31 is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-05-2014 , 20:14   Re: Constant string return only first letter...
Reply With Quote #3

Well, the problem is not from that. I tried to manually put different indexes in this subscript, but it everytime returns the first letter of the line...
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-05-2014 , 21:41   Re: Constant string return only first letter...
Reply With Quote #4

When posting code that you have issues with, you should state the line on which the issue occurs. I shouldn't need to take 5 minutes trying to find the line to which you are originally referring. Or, better yet, you should write a small test plugin that tests just that one little thing that you are having issues with, often, people are able to discover the issue based on simply writing this test code.
__________________
fysiks is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-05-2014 , 21:51   Re: Constant string return only first letter...
Reply With Quote #5

Sorry abou that. I'm right now on my phone, but there is no current line. I was about to give just an example, but people often say "post the whole code". Also, I can't figure out why this is not working, when every other const used in this way works fine. So I'm basicaly out of ideas. Otherwise I wouldn't post here. Sorry, if something...
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-05-2014 , 22:49   Re: Constant string return only first letter...
Reply With Quote #6

Quote:
Originally Posted by Flick3rR View Post
Sorry abou that. I'm right now on my phone, but there is no current line. I was about to give just an example, but people often say "post the whole code". Also, I can't figure out why this is not working, when every other const used in this way works fine. So I'm basicaly out of ideas. Otherwise I wouldn't post here. Sorry, if something...
Well, I'm not even going to try to help if you are not courteous enough to state where the problem is actually occurring. I don't want to take the time to first find where the issue is (since most people can't just up and run the code to see what you are talking about).

I said to create a small test code to test the issue. I did not say that you couldn't post both the test code and the full code. If the issue occurs in the small test code, then there really is no issue with not posting the full code. If the test code works then it is imperative that you post the full code (if you state where in the code the issue occurs).
__________________
fysiks is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-06-2014 , 06:53   Re: Constant string return only first letter...
Reply With Quote #7

Quote:
Originally Posted by Flick3rR View Post
when every other const used in this way works fine
Тhey are actually working. Test plugins, etc. I just can't find the problem here. Will update the main post.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-06-2014 , 07:42   Re: Constant string return only first letter...
Reply With Quote #8

Not sure, but maybe the first element in your g_szAdminPrefixes[][eData] array(the empty string) has to do something with it. Try making it at least {"", 0}, if you already want an empty element.
And you should not recreate chat system like that, you should alter the existing one(hooking "SayText" message). Here's an example:
PHP Code:
public msgSayTextiMsgIdiMsgDestiMsgEnt ) {
    
    static 
szMessage192 ], szNewMessage192 ];
    
    new 
iSender get_msg_arg_int);
    
// Modify only if player is VIP
    
if( is_user_connectediSender ) && g_iVip[iSender]) {
        
        
get_msg_arg_string2szMessagecharsmaxszMessage ) );
            
        if( 
equalszMessage"#Cstrike_Chat_All" ) ) {
            
            
formatexszMessagecharsmaxszMessage ), "^4[VIP] ^3%%s1 ^1: %%s2");
            
set_msg_arg_string2szMessage );
        }
        else if( !
equalszMessage"#Cstrike_Name_Change" ) && !equalszMessage"#Game_radio" ) ) {
            
            
formatexszNewMessagecharsmaxszNewMessage ), "^4[VIP] ^3%s"szMessage );
            
set_msg_arg_string2szNewMessage );
        }
    }


Last edited by klippy; 08-06-2014 at 07:43.
klippy is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-06-2014 , 08:26   Re: Constant string return only first letter...
Reply With Quote #9

Quote:
Originally Posted by KliPPy View Post
Not sure, but maybe the first element in your g_szAdminPrefixes[][eData] array(the empty string) has to do something with it. Try making it at least {"", 0}, if you already want an empty element.
It's not from it, since the second const has the same problem. I returns only the first letter of player's rank. And thanks for the alternative!
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-06-2014 , 09:13   Re: Constant string return only first letter...
Reply With Quote #10

Then it probably means there is a null character for some reason. Try outputting first few letters of the string as they are integers, so you could see their values. Like so:
PHP Code:
// 16 characters should be enough for testing purposes?
for(new 016i++)
       
log_amx("g_szAdminPrefixes[3][string][%i] = %i"ig_szAdminPrefixes[3][string][i]); 
and post here the output you got.

Last edited by klippy; 08-06-2014 at 09:15.
klippy is offline
Old 08-07-2014, 11:39
Flick3rR
This message has been deleted by Flick3rR.
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode