Save all the used numbers in a file. Then, when someone buys a new number, loop through the file's context and use strcmp between the line of the file and the number (formatted to strings [wiki => strcmp helps]).
If the file is read to the end, and the strcmp was never same, then he/she may use the number, in case that there is a line same to the number, stop the loop and return that the number is already in usage. Got that? ^^ Jeffry |
I think i got it ^^. Then if they get a new number then delete it from the file again. Well im gonna try to make this thanks for your suggestion/help .
|
No, if they get a new number, you have to add it to the file (Filename e.g.: UsedNumbers.txt). There are all the numbers inside which are in use.
If you have any questions feel free to ask. Jeffry |
Yes, but if i get number 4444 and i will have a new number i get number 5555 i have to delete that from the file so other people can get number 4444 since its not in use anymore .
|
new PhoneNumber[MAX_PLAYERS];//you already got an array for the phonenumbers. use yours indeed..
new filename[64]; new filecontent[64]; new PlayerName[MAX_PLAYER_NAME]; GetPlayerName(playerid,PlayerName,sizeof(PlayerName)); format(filename,sizeof(filename),"PhoneNumbers/%d",PhoneNumber[playerid]); format(filecontent,sizeof(filecontent),"%s",PlayerName); new File:PhoneFile=fopen(filename,io_readwrite);//open file "11275".. fwrite(PhoneFile,filecontent);//write "Babul" into it, fclose(PhoneFile);//and close the file. done.
i suggest you to waste some harddisc space for creating one file per number, and let the filesystem do the dirty work (sorting) for you:
Код:
new PhoneNumber[MAX_PLAYERS];//you already got an array for the phonenumbers. use yours indeed.. Код:
your code.. if i would get the number 11275 as "Babul", then the file "scriptfiles/PhoneNumbers/11275" would contain simply "Babul". if you want a /GetPhoneNumberFromPlayer <Name> command, its also a good idea to store the PhoneNumber in another file with the PlayerName as filename... |
#define ALL_NUMBER_FILE "AllNumbers.txt" // on top
new string[128], Number; // when i buy a phone
Player[playerid][PhoneN] = 940+random(699);
format( string, sizeof( string ), "You have purchased a cellphone. Your number is %d.", Player[playerid][PhoneN]);
SendClientMessage( playerid, WHITE, string);
Number = Player[playerid][PhoneN];
AddNumberToFile(ALL_NUMBER_FILE, Number);
stock AddNumberToFile(DFileName[], Number) // a stock.
{
new File:NumFile, Line[128];
format(Line, sizeof(Line), "%i\r\n", Number);
NumFile = fopen(DFileName, io_append);
fwrite(NumFile, Line);
fclose(NumFile);
return 1;
}
new string[128], Number;
NEWNUMBER:
Number = 940+random(699);
new numberstr[50];
format(numberstr, sizeof(numberstr), "/Numbers/%d.txt", Number); //Create a folder called 'Numbers'.
if(fexist(numberstr)) //Checks if the number is already created
{
goto NEWNUMBER;
//Will get a new number, in case the current ones does already exist.
}
else
{
//Creates the file for the corresponding number:
new File:num;
num=fopen(numberstr, io_readwrite);
//Use 'fwrite' here to write something into the file.
fclose(num);
Player[playerid][PhoneN] = Number;
}
format( string, sizeof( string ), "You have purchased a cellphone. Your number is %d.", Player[playerid][PhoneN]);
SendClientMessage( playerid, WHITE, string);
//DialogResponse...
new string[128], Number;
Number = strval(inputtext);
if(Number > 2000000000 || Number < 10000) return SendClientMessage(playerid, RED, "ERROR: Invalid number.");
new numberstr[50];
format(numberstr, sizeof(numberstr), "/Numbers/%d.txt", Number); //Create a folder called 'Numbers'.
if(fexist(numberstr)) //Checks if the number is already created
{
return SendClientMessage(playerid, RED, "ERROR: Number already in use, take another..");
}
else
{
... same as obove