=|[76AD]|= TatsuSaisei
04-17-2007, 06:04 PM
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...
new List[] = "filename.ini" //does not need to be ini, can be .txt or .log or any other extension
public check_rank(id)
{
new authid[36]; //string array to store user's steamid
new lineNum = 0; //set line number variable to start at 0
new configLine[64]; //string array to store 1 line of information from a "text" file
new RankFile[64]; //string array to stor the name of the file holding infos
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)
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 array
format(bugleRankFile, 64, "%s/%s", RankFile, List); // create a string of path/to/config/text_filename
//format is a method used to "create" strings from different types of info, many uses...
get_user_authid(id, authid, 35); //"get" and store the users steam id into the array
// If the file exists, get rank
if(file_exists(RankFile)) //checks for actual existance of the "text" file
{
new iLen, first_info[36], second_info[1]; //iLen is for the length of the line in characters
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)
{
parse(configLine, first_info, 35, second_info, 1); //parse "reads" the file and assigns information found into variables - by default seperated by spaces
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...
{
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...
break; //stops the while loop and prevent any more of the file being read since we found what we wanted...
}
}
}
}
new List[] = "filename.ini" //does not need to be ini, can be .txt or .log or any other extension
public check_rank(id)
{
new authid[36]; //string array to store user's steamid
new lineNum = 0; //set line number variable to start at 0
new configLine[64]; //string array to store 1 line of information from a "text" file
new RankFile[64]; //string array to stor the name of the file holding infos
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)
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 array
format(bugleRankFile, 64, "%s/%s", RankFile, List); // create a string of path/to/config/text_filename
//format is a method used to "create" strings from different types of info, many uses...
get_user_authid(id, authid, 35); //"get" and store the users steam id into the array
// If the file exists, get rank
if(file_exists(RankFile)) //checks for actual existance of the "text" file
{
new iLen, first_info[36], second_info[1]; //iLen is for the length of the line in characters
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)
{
parse(configLine, first_info, 35, second_info, 1); //parse "reads" the file and assigns information found into variables - by default seperated by spaces
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...
{
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...
break; //stops the while loop and prevent any more of the file being read since we found what we wanted...
}
}
}
}