Random() question?
#1

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?
Reply
#2

Just call random three times? What's the problem?
Reply
#3

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"
Reply
#4

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);
Reply
#5

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.
Reply
#6

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);
Reply
#7

Thank you so much, that's what I meant exactly. REP +
Reply
#8

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]);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)