Unique phone numbers
#1

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);
}
Reply
#2

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.
Reply
#3

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
Reply
#4

Just use sqlite/mysql.
Reply
#5

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

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!
Reply
#7

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)