How to save random number! - 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: How to save random number! (
/showthread.php?tid=468247)
How to save random number! -
Scrillex - 07.10.2013
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..
Re: How to save random number! -
Konstantinos - 07.10.2013
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.
Re: How to save random number! -
Scrillex - 07.10.2013
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)
Re: How to save random number! -
Konstantinos - 07.10.2013
Into your register part:
pawn Код:
new pBloodtype;
pBloodtype = 1 + random(6);
PlayerInfo[playerid][BloodType] = pBloodtype;
Basically what you did before.
Re: How to save random number! -
Scrillex - 07.10.2013
Thank you mate it worked