SA-MP Forums Archive
8 Numbers - need them split in two, randomly - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: 8 Numbers - need them split in two, randomly (/showthread.php?tid=270300)



8 Numbers - need them split in two, randomly - Donya - 19.07.2011

Okay, I have 8 playerid's

0,1,2,3,4,5,6,7 are online..Ii need to randomly select 4 of those 8

so I randomly select 2,5,3,7 that leaves 0,1,4,6

Group 1:

Var[0] = 2
Var[1] = 5
Var[2] = 3
Var[3] = 7

Group 2:

Var[4] = 0
Var[5] = 1
Var[6] = 4
Var[7] = 6

and i can't do new = random, because playerid's can be yea..you know


Re: 8 Numbers - need them split in two, randomly - lolumadd_ - 19.07.2011

with foreach of course:

Код:
new count=0, group1[MAX_PLAYERS], group2[MAX_PLAYERS];
do
{
     group1[count]=Iter_Random(Player);
     count++;
}
while (count < Iter_Count(Player)/2);
count=0;
foreach(Player, i)
{
     if(group1[i]) continue;
     else
     {     
          group2[count] = i;
          count++;
     }    
}
Just made that now, may need some editing.


Re: 8 Numbers - need them split in two, randomly - Donya - 19.07.2011

err no not that, sorry I didn't mean all online players, i meant 8 selected playerid's

like 8 players are in a waiting room, and I need to split them into 2 teams, 4 on each team. sorry I didn't explain it better


Re: 8 Numbers - need them split in two, randomly - Shadoww5 - 19.07.2011

This works perfectly:

pawn Код:
stock randomplayer()
{
    new z = 0, w, y = GetMaxPlayers();
    static Conectados[MAX_PLAYERS];
    while(z < y)
    {
        if(IsPlayerConnected(z))
        {
            Conectados[w] = z;
            w++;
        }
        z++;
    }
    return !w ? -1 : Conectados[random(w)];
}
How to Use:

pawn Код:
printf("Random ID: %d", randomplayer());
Credits: rjjj


Re: 8 Numbers - need them split in two, randomly - Donya - 19.07.2011

Quote:
Originally Posted by Shadoww5
Посмотреть сообщение
This works perfectly:
you didn't read the post...


Okay ******, the 8 player id data is not selected, but given. as in 8 random players went on top of a building to race,
so they have all checked in and setup themselves for the race

given that playerid's are say.. 7,32,12,52,24,16,3 order by check-in right? the 8 values will be stored in a global variable

pawn Код:
new Var[8], Count;
public OnPlayerCheckin(playerid)
{
    Var[Count] = playerid;
    Count++;
    return 1;
}
so Var[ 0 - 7 ] has the playerid's stored, now i need to select 4 of them (randomly) and output the remaining 4


Re: 8 Numbers - need them split in two, randomly - Gamer_Z - 19.07.2011

You could use the vector plugin, then add playerid to a vector and make a new vector where you randomize the first vector and select the first four indexes.


Re: 8 Numbers - need them split in two, randomly - Donya - 19.07.2011

and in "Select4(size)" size would be...? 8 right..


AW: Re: 8 Numbers - need them split in two, randomly - Nero_3D - 19.07.2011

Quote:
Originally Posted by Donya
Посмотреть сообщение
and in "Select4(size)" size would be...? 8 right..
doesnt matter, but in your case 8

Edit: I am not sure if the code works correctly

Lets say we use the size of 8

and ret[0] would be as example 5
and ret[1] one number below, also 4

now if ret[2] would be 4 again it will be raised to 5, so 5 would be twice