SA-MP Forums Archive
Unique phone numbers - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Unique phone numbers (/showthread.php?tid=664499)



Unique phone numbers - bosmania - 02.03.2019

I scripted a phone number system but how do i make a number unique like if a player has a phone number,for example,Bob's phone number is 22345,no one can recive the number(22345)again.

I kind of know what i have to do,but im new into scripting and i don't really know how to do it

This is the part where the numbers are generated:

case 0:
{
new rand = 10000 + random(89999),string[64];
if(PlayerInfo[playerid][pCellphone] == 1) return SendClientMessage(playerid, COLOR_GREY, "You already have a phone");
PlayerInfo[playerid][pNumber] = rand;
PlayerInfo[playerid][pCellphone] += 1;
format(string,sizeof(string), "Your new phone number is now %d",PlayerInfo[playerid][pNumber]);
SendClientMessage(playerid, COLOR_WHITE, string);
UpdateVariable(playerid, pNumberx);
UpdateVariable(playerid, pCellphonex);
}


Re: Unique phone numbers - benjaminjones - 02.03.2019

You could generate a random one. random(80000) + 5000. This is most definitely never going to give you the same number. However, if you wish to be absolute to never get the same number for two users, you might create a function to save used numbers and always check, if the number exists in the list.


Re: Unique phone numbers - bosmania - 02.03.2019

Quote:
Originally Posted by benjaminjones
Посмотреть сообщение
You could generate a random one. random(80000) + 5000. This is most definitely never going to give you the same number. However, if you wish to be absolute to never get the same number for two users, you might create a function to save used numbers and always check, if the number exists in the list.
And how do i create this function because like i said,im kind of new into this


Re: Unique phone numbers - Pottus - 03.03.2019

Just use sqlite/mysql.


Re: Unique phone numbers - bosmania - 03.03.2019

and how do i do that,could you please write the code for me


Re: Unique phone numbers - benjaminjones - 03.03.2019

The easiest way for a newbie I can think of, is to save the phone numbers in a text file. I highly recommend you to check how to do that. Then you could convert that into mySQL!


Re: Unique phone numbers - Dignity - 03.03.2019

Quote:
Originally Posted by bosmania
Посмотреть сообщение
and how do i do that,could you please write the code for me
lol no


Re: Unique phone numbers - m3shys - 03.03.2019

It'd be similar to checking if an account exists in database, there's a common example for you. Except your checking phone number row not names row. If it does exist then you can generate another random number. Even could be recursive if you call the function again at this point but it'd require 10 lottery luck to make the same number on two rng. Unless you already have 50k characters and do no cleanup on inactive ones and don't improve the script by then

I recommend you edit a current mySQL gamemode rather than write your own shit if this is your current level