AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to get counter on txt? (https://forums.alliedmods.net/showthread.php?t=308196)

jonatat 06-10-2018 03:21

How to get counter on txt?
 
I want to write custom gameid to .txt file, example: a1, a2, a3, a4 and etc then admin runs custom command. And every time that ID increase like example first time i wrote custom command in server and write into .txt file: a1. Next time if i use same command wirte to txt file a2 but removes before a1 text. :) I hope u understand what i neeed. I try do something like that:

PHP Code:

public WriteMatchID()
{
new 
0;
new 
mixid i++;
new 
writedata[128];
formatex(writedata,127,"%s",mixid)
write_file(filename,writedata)


But does not working... Any help? :) Thanks guys!

maqi 06-10-2018 13:26

Re: How to get counter on txt?
 
Simplest way is to write in a new line every time.

Then loop fgets to retrieve the data, and count it or w/e you need to do with it.

EDIT: Oh i misunderstood what you are trying to do ( you wan't to delete the previous input and not leave it )

Thats even easier, you should still retrieve it with with fgets or w/e then close the file and use

PHP Code:

fopensFilename"wt" ); 

( This function with flags wt, deletes the content of the file ( if it exists ) and opens it for writing, also returns a handle )

Use what you retrieved previously to print whatever you need into the file

Also its good practise not to use read_file and write_file, thats why I didn't, but it would be fine to use those in your case, if you want to.


All times are GMT -4. The time now is 18:40.

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