AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Read File question (https://forums.alliedmods.net/showthread.php?t=173951)

EDUTz 12-13-2011 07:25

Read File question
 
Code:

        new auth = get_user_authid(id)
        format(holder, charsmax(holder), "%s", auth)

        new configdir[200]
        get_configsdir(configdir,199)

        new configfile1[200]

        format(configfile1,199,"%s/timer.ini",configdir)
       
        new text[512], len
        new pnum = file_size(configfile1,1)
        for(new i = 1; i < pnum; i++)
        {
                read_file(configfile1, i, text, 511, len)
                if ( contain(text, holder) != -1 )
                {
                        //here is the problem, explained below
                }
        }

so in that ini file i have some authids and for each one an expiration date in format m%dd%dy%d, something like:
"authid" "pass" "flags" expiration date: m12d25y2011 ...
How can i read that part of the line that holds the date?
something like this:
if ( contain(text, "m%dd%dy%d") != -1 ){ // is this wrong also ?
new day = ?
new month = ?
new year = ?
client_print(id, print_chat, "your access expires on %d.%d.%d", day, month, year)
}

joshknifer 12-13-2011 13:10

Re: Read File question
 
Try looking at the code from this plugin:
https://forums.alliedmods.net/showthread.php?t=138273

It does something similar to what you want i believe.

fysiks 12-13-2011 21:16

Re: Read File question
 
You need to parse the date string manually (break it down until you get "12", "25" and "2011") then you can use those to get numbers with str_to_num().

Also, make sure that if you have a single digit month or day that you prepend it with a zero so that the number is always two characters wide.

Here is one I just came up with for parsing the date string:

test "12252011"

PHP Code:

#include <amxmodx>

public plugin_init()
{
    
register_plugin("Plugin""0.1""Author")
    
register_concmd("test""cmdTest")
}
public 
cmdTest(id)
{
    new 
szDate[32], szNum[6]
    
read_argv(1szDatecharsmax(szDate))

    
formatex(szNum2"%c%c"szDate[0], szDate[1])
    new 
month str_to_num(szNum)
    
formatex(szNum2"%c%c"szDate[2], szDate[3])
    new 
day str_to_num(szNum)
    
formatex(szNum4"%c%c%c%c"szDate[4], szDate[5], szDate[6], szDate[7])
    new 
year str_to_num(szNum)
    
server_print("Date: %d/%d/%d"monthdayyear)



EDUTz 12-13-2011 21:39

Re: Read File question
 
that isn't good for me.
we have a text: j3jn34fb4im12d15y2011
how to read and save those numbers from this part of the text: j3jn34fb4im12d15y2011
i've searched for hours but i didn't find anything

fysiks 12-13-2011 22:11

Re: Read File question
 
Quote:

Originally Posted by EDUTz (Post 1612799)
that isn't good for me.
we have a text: j3jn34fb4im12d15y2011
how to read and save those numbers from this part of the text: j3jn34fb4im12d15y2011
i've searched for hours but i didn't find anything

What is all that random stuff in front of the date?

Also, you could just use my user extra info plugin and then you can just put the expiration in users.ini.

EDUTz 12-13-2011 23:00

Re: Read File question
 
ok, i understand now what you're saying.
So its better to rewrite the lines in timer.ini to loook like this:
"authid" "pass" "flags" Exp:25102011
What you said there is allright, but how to extract the date from a whole line ?
it should read the line, search for the numbers and then date[32]="thosenumebers" ... i can't think at something else.

fysiks 12-13-2011 23:47

Re: Read File question
 
Quote:

Originally Posted by EDUTz (Post 1612822)
ok, i understand now what you're saying.
So its better to rewrite the lines in timer.ini to loook like this:
"authid" "pass" "flags" Exp:25102011
What you said there is allright, but how to extract the date from a whole line ?
it should read the line, search for the numbers and then date[32]="thosenumebers" ... i can't think at something else.

Your file should look like this:

Code:

"STEAM_0:0:12345" "password" "abc" "12252011"
Then you parse that line with parse(). Then use the concept I show in my code above on the date variable.

EDUTz 12-14-2011 09:05

Re: Read File question
 
Thanks for helping me :)

fysiks 12-14-2011 18:08

Re: Read File question
 
Quote:

Originally Posted by EDUTz (Post 1613014)
Thanks for helping me :)

Yep, no problem. Good Luck.


All times are GMT -4. The time now is 12:06.

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