Race Sorting [Looking For Advice]
#1

Example of my race array:
Код:
AndomadaRace
BuffaloRace
Crazyness
DeadRinger
ElevenAndOut
Friggin3
Grafting
HarryHi.... and so on.
We use a different random() to the one that's default to SA-MP. But still, with random, you will probably get the same number a few times. We use random 8 times per race, it's very possible we will get the same number (or race ID in my case) in the vote.
When the race list is generated it reads from A-Z as my example above shows.

What I need help with:
I'd like that when we generate the list, it gives the race a unique ID, but I'm clueless on how to do this. The unique ID would then be used in order to create the race list, 0-7 first vote, 8-15 second vote and so on.
Код:
AndomadaRace // 7
BuffaloRace // 4
Crazyness // 2
DeadRinger // 3
ElevenAndOut // 5
Friggin3 // 0
Grafting // 1
HarryHill // 6
Above is example shows only 8 races, but our actual race list is 2,114.

My alternative solution was that when a number (race) is added to the vote list, it's given a value of -1, then when the vote list is generated again, it would not add races with a value of -1.
The problem with this would be if most of the races have a value of -1, it could create an endless loop while it tries to find races which don't have a value of -1.

Any idea's?

Reply
#2

pawn Код:
new array[][] = {
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"A2",
"B2",
"C2",
"D2",
"E2",
"F2",
"G2",
"A3",
"B3",
"C3",
"D3",
"E3",
"F3",
"G3",
"A4",
"B4",
"C4",
"D4",
"E4",
"F4",
"G4",
"A5",
"B5",
"C5",
"D5",
"E5",
"F5",
"G5",
"A6",
"B6",
"C6",
"D6",
"E6",
"F6",
"G6"
};
pawn Код:
#define RANDOM_RACES floatround(floatsqroot(sizeof(array))) // Takes the square root out of the array and makes the array 'group' sizes that way.

// If you don't want the group sizes be the sqroot of the array size, just simply put some number in this define. (#define RANDOM_RACES 10)

new votepointer; // This is the pointer which tells the script which 'group' the voting is going at.
pawn Код:
votepointer = (votepointer + RANDOM_RACES) < sizeof(array) ? (votepointer + RANDOM_RACES) : RANDOM_RACES; // Makes sure the pointer won't get over the size of the array.

new race = votepointer - random(RANDOM_RACES); // Takes the random race from the 'group'
_________________________________________________

I used this script and it gave pretty random array string every time.

pawn Код:
new array[][] = {
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"A2",
"B2",
"C2",
"D2",
"E2",
"F2",
"G2",
"A3",
"B3",
"C3",
"D3",
"E3",
"F3",
"G3",
"A4",
"B4",
"C4",
"D4",
"E4",
"F4",
"G4",
"A5",
"B5",
"C5",
"D5",
"E5",
"F5",
"G5",
"A6",
"B6",
"C6",
"D6",
"E6",
"F6",
"G6"
};
   
#define RANDOM_RACES floatround(floatsqroot(sizeof(array)))

new votepointer;
   
for(new i; i < 100; i++)
{
  votepointer = (votepointer + RANDOM_RACES) < sizeof(array) ? (votepointer + RANDOM_RACES) : RANDOM_RACES;

  new race = votepointer - random(RANDOM_RACES);

  print(array[race]);
}
_________________________________________________

Dunno, maybe someone else has a better method to get random race. Maybe use some plugin which generates very random number.
Reply
#3

I'll try it out soon on the server soon. Hopefully this will reduce the same race being placed over and over from the vote menu.

Thanks Finn, I'll let you know how it pans out.
Reply
#4

Sorry, made a small mistake in the code, but fixed it now.

Yeah, test it and see how it goes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)