AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Testing to write custom letter and number to txt (https://forums.alliedmods.net/showthread.php?t=329286)

erickvan 12-17-2020 09:16

Testing to write custom letter and number to txt
 
Hello. I need to write into .txt file custom text like "a44fG3D3o".

Every time delete old and write newone. My script:

PHP Code:

public WriteMatchID()
{
new 
0;
new 
mixid i++;
new 
writedata[128];
new 
filename[256]
get_configsdir(filename,255)
format(filename,255,"%s/mixid.txt",filename)
formatex(writedata,127,"%s",mixid)
write_file(filename,writedata)


But nothing. Any ideas? Im new pls dont hate me :D

lexzor 12-17-2020 09:30

Re: Testing to write custom letter and number to txt
 
https://forums.alliedmods.net/showthread.php?t=46218

you have to parse all line of that file and write data on a new line

erickvan 12-17-2020 09:34

Re: Testing to write custom letter and number to txt
 
Quote:

Originally Posted by lexzor (Post 2729054)
https://forums.alliedmods.net/showthread.php?t=46218

you have to parse all line of that file and write data on a new line

Thanks for helping. Can someone make code to understand?

erickvan 12-17-2020 09:38

Re: Testing to write custom letter and number to txt
 
I try:

PHP Code:

public WriteMatchID()
{
new 
configsdir[200]
get_configsdir(configsdir,199)
new 
0;
new 
mixid i++;
new 
configfile[200]
format(configfile,199,"%s/mixid.txt",configsdir)
write_file(configfile,"%s",mixid)


but im getting in file %s text

fysiks 12-17-2020 23:40

Re: Testing to write custom letter and number to txt
 
Simply open a file with the "w" mode in fopen(). This will delete all existing contents and write your new text in the newly blank file.

PHP Code:

new fopen("filename.txt""w")
if( 
)
{
    
fputs(f"new text")
    
fclose()



erickvan 12-18-2020 02:43

Re: Testing to write custom letter and number to txt
 
Quote:

Originally Posted by fysiks (Post 2729140)
Simply open a file with the "w" mode in fopen(). This will delete all existing contents and write your new text in the newly blank file.

PHP Code:

new fopen("filename.txt""w")
if( 
)
{
    
fputs(f"new text")
    
fclose()



Thanks! Working :)

Now any ideas how to open filename, read the number and count? Then add +1.

Example: filename.txt has numer 7. Read that number and put +1.

HamletEagle 12-18-2020 04:39

Re: Testing to write custom letter and number to txt
 
Quote:

Originally Posted by erickvan (Post 2729151)
Thanks! Working :)

Now any ideas how to open filename, read the number and count? Then add +1.

Example: filename.txt has numer 7. Read that number and put +1.

https://forums.alliedmods.net/showthread.php?t=46218
Check the new file commands section.

erickvan 12-18-2020 04:43

Re: Testing to write custom letter and number to txt
 
Quote:

Originally Posted by HamletEagle (Post 2729160)
https://forums.alliedmods.net/showthread.php?t=46218
Check the new file commands section.

Can someone make a code to understand? :) thanks

erickvan 12-18-2020 06:44

Re: Testing to write custom letter and number to txt
 
I try to do something like that:

PHP Code:

public WriteMatchID()
{
new 
configsdir[200]
get_configsdir(configsdir,199)
new 
configfile[200]
formatex(configfile,199,"%s/mixid.txt",configsdir)
new 
szText[64],len
read_file
("addons/amxmodx/configs/mixid.txt",0,szText,63,len)
new 
countID szText[63]++;
new 
writedata[128]
formatex(writedata,127,"%s",countID)
new 
fopen(configfile"r+")
if( 
)
{
    
fputs(fwritedata)
    
fclose)



but nothing, any ideas?

Th3822 12-18-2020 21:23

Re: Testing to write custom letter and number to txt
 
Try this:
Code:

public WriteMatchID()
{
        new const szAllowedChars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

        static szSavePath[234];
        if (!szSavePath[0])
        {
                get_configsdir(szSavePath, charsmax(szSavePath));
                add(szSavePath, charsmax(szSavePath), "/mixid.txt");
        }

        new i, szMatchID[10]; // 9 "random" chars
        while (i < charsmax(szMatchID))
        {
                szMatchID[i++] = szAllowedChars[random_num(0, sizeof(szAllowedChars) - 2)];
        }
        szMatchID[i] = 0;

        new pFile = fopen(szSavePath, "w");
        if (pFile)
        {
                fputs(pFile, szMatchID);
                fclose(pFile);
        }
}



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

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