22.06.2011, 15:40
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:
heres a sort of PhoneNumer saving snippet:
a /call or /GetPlayerFromPhoneNumber <number> command is possible very easy this way...
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...
Код:
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.
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...