Problem with random number function
#1

I want to create random number for player when he register and with stock function to make sure that number isn't duplicated for any player. Problem is that it wont work. Does anyone know what i'm missing here?

pawn Код:
do
{
PlayerInfo[playerid][pPin] = 1000 + random(8999);
}
while(PinUsed(playerid));


pawn Код:
stock PinUsed(playerid)
{
    for(new i=0; i<MAX_PLAYERS; i++)
        if(PlayerInfo[playerid][pPin] == PlayerInfo[playerid][pPin] && i != playerid) return 1;
    return 1;
}
Reply
#2

pawn Код:
do
{
PlayerInfo[playerid][pPin] = 1000 + random(8999);
}
while(!PinUsed(playerid));
pawn Код:
stock PinUsed(playerid)
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;

        if(PlayerInfo[playerid][pPin] == PlayerInfo[i][pPin] && i != playerid) return 0; // You were comparing the same playerid's pin
    }
    return 1; //return true if it don't matches.
}
Try it and let me know if it works or not.
Reply
#3

Nope i also tryed before that and it won't work.
Reply
#4

Quote:
Originally Posted by caki
Посмотреть сообщение
Nope i also tryed before that and it won't work.
Show me the code once again. The code which has been compiled.
Reply
#5

Here it is. So if i run do function register function fails to load properly...

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                new strText[179], naslov2[128];
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                format(naslov2, sizeof(naslov2), ""COL_GREEN2"     Welcome"COL_WHITE" %s!", GetName(playerid)); //formating our title
                format(strText, 179, ""COL_WHITE"______________________________\n\n"COL_GREEN2"Name"COL_WHITE" %s"COL_GREEN2" isn't registered!\n\n{F81414}Password must be between 4 and 35 characters!", GetName(playerid));
                new INI:playerFile = INI_Open(UserPath(playerid));
                new HashPass[129];
                WP_Hash(HashPass, sizeof(HashPass), inputtext);
                INI_SetTag(playerFile,"DATA");
                INI_WriteString(playerFile, "Password", HashPass);
                INI_WriteInt(playerFile, "Admin",0);
                INI_WriteInt(playerFile, "VIP",0);
                INI_WriteInt(playerFile, "BankAccount",0);
                INI_WriteInt(playerFile, "Money",0);
                INI_WriteInt(playerFile, "Score",0);
                INI_WriteInt(playerFile, "Kills",0);
                INI_WriteInt(playerFile, "Deaths",0);
                INI_WriteInt(playerFile, "Online",0);
                INI_WriteInt(playerFile, "Skin",0);
                INI_WriteInt(playerFile, "Class",0);
                INI_WriteInt(playerFile, "LastX",0);
                INI_WriteInt(playerFile, "LastY",0);
                INI_WriteInt(playerFile, "LastZ",0);
                INI_WriteInt(playerFile, "Interior",0);
                INI_WriteInt(playerFile, "VirtualWorld",0);
                INI_WriteInt(playerFile, "Warned",0);
                INI_WriteInt(playerFile, "Kicked",0);
                INI_WriteInt(playerFile, "Banned",0);
                INI_WriteInt(playerFile, "BanReason",0);
                INI_WriteInt(playerFile, "Muted",0);
                INI_WriteInt(playerFile, "Jailed",0);
                INI_WriteInt(playerFile, "AdminJail",0);
                INI_WriteInt(playerFile, "BizID",0);
                INI_WriteInt(playerFile, "Rank",0);
                INI_WriteInt(playerFile, "Faction",0);
                INI_WriteInt(playerFile, "Leader",0);
                INI_WriteInt(playerFile, "Vehicles",0);
                INI_WriteInt(playerFile, "PhoneNumber",0);
                INI_WriteInt(playerFile, "Pin",0);
                INI_WriteInt(playerFile, "GunLic",0);
                INI_WriteInt(playerFile, "DrivingLic",0);
                INI_WriteInt(playerFile, "FlyingLic",0);
                INI_WriteInt(playerFile, "Wanted",0);
                INI_WriteInt(playerFile, "Cuffed",0);
                INI_WriteInt(playerFile, "Drunk",0);
                INI_WriteInt(playerFile, "UsedDrugs",0);
                INI_WriteInt(playerFile, "Job",0);
                INI_WriteInt(playerFile, "FishingLic",0);
                INI_WriteInt(playerFile, "WantedLvl",0);
                INI_WriteInt(playerFile, "Exp",0);
                INI_WriteInt(playerFile, "Gps",0);
                INI_WriteInt(playerFile, "JailTime",0);
                INI_Close(playerFile);
                format(strText, 179, "You have registered with name {FFFFFF}'%s' {FFFF00}and password {FFFFFF}'%s'{FFFF00}, you are automatic logged in!", GetName(playerid), inputtext);
                ShowInfoDialog(playerid, strText);
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Fell free to have fun while server is in beta!","Ok","");
                SetPVarInt(playerid, "Registered", 0);
                SetPVarInt(playerid, "Logged", 1);
               // do
            //  {
            //  PlayerInfo[playerid][pPin] = 1000 + random(8999);
            //  }
            //  while(PinUsed(playerid));
            }
        }
Reply
#6

pawn Код:
do
{
PlayerInfo[playerid][pPin] = 1000 + random(8999);
}
while(!PinUsed(playerid));
pawn Код:
stock PinUsed(playerid)
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;

        if(PlayerInfo[playerid][pPin] == PlayerInfo[i][pPin] && i != playerid) return 0; // You were comparing the same playerid's pin
    }
    return 1; //return true if it don't matches.
}
Try it and let me know if it works or not.
Reply
#7

Quote:
Originally Posted by T0pAz
Посмотреть сообщение
pawn Код:
do
{
PlayerInfo[playerid][pPin] = 1000 + random(8999);
}
while(!PinUsed(playerid));
pawn Код:
stock PinUsed(playerid)
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;

        if(PlayerInfo[playerid][pPin] == PlayerInfo[i][pPin] && i != playerid) return 0; // You were comparing the same playerid's pin
    }
    return 1; //return true if it don't matches.
}
Try it and let me know if it works or not.
Pin = 3472

It works!!!
Thank you i was already pissed out with this.
Reply
#8

Quote:
Originally Posted by caki
Посмотреть сообщение
Pin = 3472

It works!!!
Thank you i was already pissed out with this.
You're welcome. Those kind of things always get on my nerves.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)