18.01.2011, 11:43
as the title says code a random number system? i want it to give a random bank pin and it should only be 4digit and non repeating
new pBankPin [ MAX_PLAYERS ];
stock GenerateBankPin() {
new pin = random(9999);
return pin;
}
stock GivePlayerBankPin ( playerid ) {
new bpin = GenerateBankPin();
for ( new i = 0; i < MAX_PLAYERS ; i++ ) {
if ( IsPlayerConnected ( i ) && pBankPin [ i ] == bpin ) {
bpin = GenerateBankPin();
}
}
return bpin;
}
pin = 1000+random(8999);
stock GenerateBankPin(playerid) { new pin = 1000+random(8999); //generates a number for ( new i = 0; i < GetMaxPlayers() ; i++ ) //loops through all the server player slots (defined in server.cfg) { if ( IsPlayerConnected ( i ) && pBankPin [ i ] == bpin && i!=playerid) pin = 1000+random(8999); //checks if player in that slot is connected and if its pin is the same as the playerid's then it generates a new pin. } return pin; }
phonenumber = 10000000+random(89999999);