Raised This Month: $ Target: $400
 0% 

Testing to write custom letter and number to txt


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
erickvan
Junior Member
Join Date: Dec 2020
Old 12-17-2020 , 09:16   Testing to write custom letter and number to txt
Reply With Quote #1

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
erickvan is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 12-17-2020 , 09:30   Re: Testing to write custom letter and number to txt
Reply With Quote #2

https://forums.alliedmods.net/showthread.php?t=46218

you have to parse all line of that file and write data on a new line
lexzor is offline
erickvan
Junior Member
Join Date: Dec 2020
Old 12-17-2020 , 09:34   Re: Testing to write custom letter and number to txt
Reply With Quote #3

Quote:
Originally Posted by lexzor View Post
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 is offline
erickvan
Junior Member
Join Date: Dec 2020
Old 12-17-2020 , 09:38   Re: Testing to write custom letter and number to txt
Reply With Quote #4

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

Last edited by erickvan; 12-17-2020 at 09:56.
erickvan is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-17-2020 , 23:40   Re: Testing to write custom letter and number to txt
Reply With Quote #5

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()

__________________
fysiks is offline
erickvan
Junior Member
Join Date: Dec 2020
Old 12-18-2020 , 02:43   Re: Testing to write custom letter and number to txt
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
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.
erickvan is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-18-2020 , 04:39   Re: Testing to write custom letter and number to txt
Reply With Quote #7

Quote:
Originally Posted by erickvan View Post
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.
__________________
HamletEagle is online now
erickvan
Junior Member
Join Date: Dec 2020
Old 12-18-2020 , 04:43   Re: Testing to write custom letter and number to txt
Reply With Quote #8

Quote:
Originally Posted by HamletEagle View Post
https://forums.alliedmods.net/showthread.php?t=46218
Check the new file commands section.
Can someone make a code to understand? thanks
erickvan is offline
erickvan
Junior Member
Join Date: Dec 2020
Old 12-18-2020 , 06:44   Re: Testing to write custom letter and number to txt
Reply With Quote #9

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?

Last edited by erickvan; 12-18-2020 at 06:44.
erickvan is offline
Th3822
Member
Join Date: Jan 2013
Location: Venezuela
Old 12-18-2020 , 21:23   Re: Testing to write custom letter and number to txt
Reply With Quote #10

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);
	}
}
Th3822 is offline
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 14:59.


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