Day of Defeat Plugins Community
This site is an archive — everything is readable and downloadable, nothing can be posted. Admin
Archive › Old Forum Threads › Help › Tutorials › Quick Tut - Read from "text" file
2 posts, 2 people · 2,072 views Thread Rating: ★★★★★
closedQuick Tut - Read from "text" file
Started by =|[76AD]|= TatsuSaisei on 04-17-2007, 05:04 PM
=|[76AD]|= TatsuSaisei
started this thread
Posts: 794
Threads: 54
Joined: May 2005
04-17-2007, 05:04 PM #1

Not the best tutorial in the world, but it is a quick example of how to read from a "text" file and store/evaluate this information...n n

 nnew List[] = "filename.ini" //does not need to be ini, can be .txt or .log or any other extensionn npublic check_rank(id)n{nnew authid[36]; //string array to store user's steamidn new lineNum = 0; //set line number variable to start at 0n new configLine[64]; //string array to store 1 line of information from a "text" filen new RankFile[64]; //string array to stor the name of the file holding infosn playerRank[id] = -1; //for this example, it is the "default" players rank, meaning they have none (0 is used "Honorary Guests" - not a part of this tut)n get_configsdir(RankFile, 64); //this "gets" the path of the configs directory (should it be different then a normal instal path) and assigns this info INTO RankFile string arrayn format(bugleRankFile, 64, "%s/%s", RankFile, List); // create a string of path/to/config/text_filenamen//format is a method used to "create" strings from different types of info, many uses...n get_user_authid(id, authid, 35); //"get" and store the users steam id into the arrayn // If the file exists, get rankn if(file_exists(RankFile)) //checks for actual existance of the "text" filen {n  new iLen, first_info[36], second_info[1]; //iLen is for the length of the line in charactersn  while(read_file(bugleRankFile,lineNum++,configLine,38,iLen)) //read_file will return the next line number or NULL when it has reached the end of the file, therefore a while loop will run through the entire file (unless you "break" out of the loop)n  {n    parse(configLine, first_info, 35, second_info, 1); //parse "reads" the file and assigns information found into variables - by default seperated by spacesn    if(strfind(configLine,authid,0,0) != -1) //here is where the whole line is "searched" for a steamid and if it matches the steam id of the player being checked... could have just as easily checked first_info as well...n    {n     playerRank[id] = str_to_num(second_info); //since the id of the line and the id of the "caller" equal each other, then take the second bit of info (second_info) and convert it from a string into a value we want (integer in this case) and then assign it into a variable designed to hold such...n     break; //stops the while loop and prevent any more of the file being read since we found what we wanted...n    }n  }n }n}n
H Hood [10th MD]
posted here
Posts: 84
Threads: 7
Joined: Nov 2006
03-09-2008, 05:59 PM #2

any chance of help with writing to a file?rnthe read seems to work fine, but i can't get fputs to work correctly.rn

new line[68]rnformat(line,67,"%s|%s",targetsteam,targetname)rnfputs(idFile,line)
rnrnbefore that, i check to make sure the file exists, but nothing more - do i need to open a stream or anything like that?

Archive › Old Forum Threads › Help › Tutorials › Quick Tut - Read from "text" file
DoD Plugins Archive · Repository · Old Forum Threads · Maps · Admin · built 14 Sep 2026 00:34 UTC