Raised This Month: $29 Target: $400
 7% 

About string question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yl2401
Member
Join Date: Nov 2011
Old 08-03-2015 , 03:14   About string question
Reply With Quote #1

PHP Code:
new g_data[33][6][33]
public 
CheckClient(id)
{
    if(
is_user_bot(id))
        return 
PLUGIN_HANDLED
    
    
new szName[32], check_name[33], check_data[6][33], loaddata[5120]
    new 
file fopen("addons/amxmodx/configs/data.ini""r")
    
get_user_name(idszNamecharsmax(szName))
    while(!
feof(file))
    {
        
fgets(fileloaddatacharsmax(loaddata))
        
        if(!
loaddata[0] || loaddata[0] == ';' || loaddata[0] == '^n' || (loaddata[0] == '/' && loaddata[1] == '/'))
            continue
        
        
parse(loaddatacheck_namecharsmax(check_name), check_data[0], 32check_data[1], 32check_data[2], 32check_data[3], 32check_data[4], 32check_data[5], 32)
        
        if(
equal(check_nameszName))
        {
            for(new 
i=0i<6i++)
            {
                for(new 
ii=0ii<33ii++)
                    
g_data[id][i][ii] = check_data[i][ii]
                    
//log_amx("%d", check_data[i][ii])
            
}
            
            break
        }
        continue
    }
    
fclose(file)
    return 
PLUGIN_CONTINUE
}

public 
SaveData(id)
{
    new 
iLen 0
    
new szName[32], loaddata[5120]
    
get_user_name(idszNamecharsmax(szName))
    new 
linefile fopen("addons/amxmodx/configs/data.ini""r")
    
    while(!
feof(file))
    {
        
fgets(fileloaddata5119)
        
line++
        
parse(loaddataloaddatacharsmax(loaddata))
        
        if(
equal(loaddataszName))
        {
            
iLen += formatex(loaddata[iLen], (5120 iLen), "^"%s^""szName)
            
            for(new 
i=0i<6i++)
            {
                
iLen += formatex(loaddata[iLen], (5120 iLen), " ^"")
                for(new ii=0; ii<33; ii++)
                    iLen += formatex(loaddata[iLen], (5120 - iLen), "
%d", g_data[id][i][ii])
                
                iLen += formatex(loaddata[iLen], (5120 - iLen), "
^"")
            }
            
            
write_file("addons/amxmodx/configs/data.ini"loaddataline 1)
            
            break
        }
    }
    
fclose(file)
    return 
PLUGIN_HANDLED

data.ini
PHP Code:
"Player" "100000000000000000000000000000000" "010000000000000000000000000000000" "110000000000000000000000000000000" "000000000000000000000000000000000" "000000000000000000000000000000000" "000000000000000000000000000000000" 
When I save, it was changed to:
data.ini
PHP Code:
"Player" "49484848484848484848484848484848484848484848484848484848484848480" "48494848484848484848484848484848484848484848484848484848484848480" "49494848484848484848484848484848484848484848484848484848484848480" "48484848484848484848484848484848484848484848484848484848484848480" "48484848484848484848484848484848484848484848484848484848484848480" "48484848484848484848484848484848484848484848484848484848484848480" 
I have used "log_amx("%d", check_data[i][ii])" to test:
check_data[0][0]: 100000000...
check_data[0][1]: 000000000...
check_data[0][2]: 000000000...
...

How to make "check_data[0][0]" output only "1", not "100000000..."?
And "check_data[0][1]" output only "0", not "000000000..."?

Last edited by yl2401; 08-03-2015 at 23:43.
yl2401 is offline
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 08-03-2015 , 06:51   Re: About string question
Reply With Quote #2

Format your post with PHP tags instead of HTML
vitorrossi is offline
yl2401
Member
Join Date: Nov 2011
Old 08-03-2015 , 07:23   Re: About string question
Reply With Quote #3

Quote:
Originally Posted by vitorrossi View Post
Format your post with PHP tags instead of HTML
OK
yl2401 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-03-2015 , 08:39   Re: About string question
Reply With Quote #4

You are storing the ASCII value for each individual character. I'm not at a PC right now but I can fix it later if no one else gets to it.
__________________
Bugsy is offline
yl2401
Member
Join Date: Nov 2011
Old 08-03-2015 , 10:40   Re: About string question
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
You are storing the ASCII value for each individual character. I'm not at a PC right now but I can fix it later if no one else gets to it.
Thank you!
I look forward to your reply!
yl2401 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-03-2015 , 18:29   Re: About string question
Reply With Quote #6

This is not efficient and can be done better. If you explain the purpose of what you are saving I can show you a better way.
Spoiler

Quote:
I have used "log_amx("%d", check_data[i][ii])" to test:
check_data[0][0]: 100000000...
check_data[0][1]: 000000000...
check_data[0][2]: 000000000...
...

How to make "check_data[0][0]" output only "1", not "100000000..."?
And "check_data[0][1]" output only "0", not "000000000..."?
You can use str_to_num() for that, but again, tell me what you are saving and it can be done better.
__________________

Last edited by Bugsy; 08-03-2015 at 19:38.
Bugsy is offline
yl2401
Member
Join Date: Nov 2011
Old 08-03-2015 , 23:57   Re: About string question
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
This is not efficient and can be done better. If you explain the purpose of what you are saving I can show you a better way.
Spoiler


You can use str_to_num() for that, but again, tell me what you are saving and it can be done better.
Thank you very much!!
I want to use it to do a survey. When players select "1", only save "1." When the player selects "2" , only save "2", etc. In addition, the admin can read data, and statistics.
What can be better?
yl2401 is offline
yl2401
Member
Join Date: Nov 2011
Old 08-04-2015 , 00:05   Re: About string question
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
This is not efficient and can be done better. If you explain the purpose of what you are saving I can show you a better way.
Spoiler


You can use str_to_num() for that, but again, tell me what you are saving and it can be done better.
Yes, when I want to read data, I have to use str_to_num () many times. When I make a menu, I have to use it 10++ times. I do not want to use it many times. How can I do?
yl2401 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-04-2015 , 06:58   Re: About string question
Reply With Quote #9

Explain how much data needs to be stored for each player. You are currently storing 6 pieces of 33-length 0's and 1's? Is the intention to save just 6 numbers, or what? The more detail you give the better I can help.
__________________

Last edited by Bugsy; 08-04-2015 at 18:11.
Bugsy is offline
yl2401
Member
Join Date: Nov 2011
Old 08-04-2015 , 22:07   Re: About string question
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
Explain how much data needs to be stored for each player. You are currently storing 6 pieces of 33-length 0's and 1's? Is the intention to save just 6 numbers, or what? The more detail you give the better I can help.
For now, just save 6 pieces of 33-length 0's, 1's and 2's. It was enough.
In addition, I want to identify the data, I should use str_to_num (g_data [id] [0] [0]) or g_data [id] [0] [0] or other?
like: formatex(option, charsmax(option), " %s", str_to_num(g_data[id][0][0])? "\rYes":"\dNo")
How should I do?
THX

Last edited by yl2401; 08-04-2015 at 23:27.
yl2401 is offline
Reply


Thread Tools
Display Modes

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 17:35.


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