Random() question? - 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: Random() question? (
/showthread.php?tid=457472)
Random() question? -
Dokins - 11.08.2013
Quick question, regarding random. I'm trying to make a random 3 gun parts in a gun package (Small Grip, Medium Grip, Large Grip), right? The player has to get 3, but ANY 3. How can I do that? Even if it's 2 of the same one?
Re: Random() question? -
Vince - 11.08.2013
Just call random three times? What's the problem?
Re: Random() question? -
Dokins - 11.08.2013
I see, that is logical aha. How could I obtain the result from the Randoms? as in....How can I do something like
"You retrieved a (result), a (result) and a (result) from the package"
Re: Random() question? -
[XST]O_x - 11.08.2013
pawn Код:
new random[3];
new string[64];
random[0] = random();
random[1] = random();
random[2] = random();
format(string, sizeof(string), "You got a %d, a %d and a %d from the package.", random[0], random[1], random[2]);
SendClientMessage(playerid, -1, string);
Re: Random() question? -
Dokins - 11.08.2013
Thanks, but I mean....
pawn Код:
new rand = Random(3);
if(rand == 1)
{
SmallGrip[playerid] ++;
}
if(rand == 2)
{
MedGrip[playerid] ++;
}
if(rand == 3)
{
LargeGrip[playerid] ++;
}
// from this it's only going to select 1, I need 3, but I need to know the result from it so I can put it in a string.
Re: Random() question? -
[XST]O_x - 11.08.2013
pawn Код:
new rand[3];
new randStr[3][15];
new string[64];
for(new i = 0; i < sizeof rand; i++)
{
rand[i] = random(3);
switch(rand[i]) {
case 0: {format(randStr[i], 15, "SmallGrip"); SmallGrip[playerid]++;}
case 1: {format(randStr[i], 15, "MedGrip"); MedGrip[playerid]++;}
case 2: {format(randStr[i], 15, "LargeGrip");LargeGrip[playerid]++;}
}
}
format(string, sizeof(string),"You got a %s, a %s and a %s from the package.", randStr[0], randStr[1], randStr[2]);
SendClientMessage(playerid, -1, string);
Re: Random() question? -
Dokins - 11.08.2013
Thank you so much, that's what I meant exactly. REP +
AW: Random() question? -
Nero_3D - 11.08.2013
Not that it matters now, I would have done it like that, maybe add at the end some checks for empty results
pawn Код:
new
i,
result[3]
;
while(i++ < 3) {
result[random(sizeof result)]++;
}
SmallGrip[playerid] += result[0];
MedGrip[playerid] += result[1];
LargeGrip[playerid] += result[2];
printf("You got %d SmallGrip, %d MedGrip and %d LargeGrip from the package.", result[0], result[1], result[2]);