How to save random number!
#1

So I have a problem I need to generate random number and save it..

I have something like this:

pawn Код:
stock BLOODTYPE(playerid)
{
   new pBloodtype;
   pBloodtype =  1 + random(6);
   if(pBloodtype == 1)
   if(pBloodtype == 2)
   if(pBloodtype == 3)
   if(pBloodtype == 4)
   if(pBloodtype == 5)
   if(pBloodtype == 6)
   PlayerInfo[playerid][BloodType] = pBloodtype;
   return pBloodtype;
}
But it ain't working... Idk why..
Reply
#2

Do you know what the code you wrote does?

pawn Код:
if(pBloodtype == 1)
{
    if(pBloodtype == 2)
    {
        if(pBloodtype == 3)
        {
            if(pBloodtype == 4)
            {
                if(pBloodtype == 5)
                {
                    if(pBloodtype == 6)
                    {
                        PlayerInfo[playerid][BloodType] = pBloodtype;
                    }
                }
            }
        }
    }
}
Of course, it's not going to work. If you want to get a random number, assign it to BloodType and return that random number, then use:
pawn Код:
stock BLOODTYPE(playerid)
{
    new pBloodtype;
    pBloodtype =  1 + random(6);
    PlayerInfo[playerid][BloodType] = pBloodtype;
    return pBloodtype;
}
If you want to do something, then please explain it.
Reply
#3

Oh thanks for your answer.. Now I have a question how could I add under player registration to make it save randomly. ( Just ain't that good with stocks)
Reply
#4

Into your register part:

pawn Код:
new pBloodtype;
pBloodtype =  1 + random(6);
PlayerInfo[playerid][BloodType] = pBloodtype;
Basically what you did before.
Reply
#5

Thank you mate it worked
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)