• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Solved] Random Player Name Issue...

Status
Not open for further replies.
Level 3
Joined
Apr 29, 2010
Messages
54
I've been working on a trigger that would allow a certain race to have different names (randomly) depending on the number of players.

For example:
Player1
Race = Human
Names(1) = "..."
Names(2) = "..."
Names(3) = "Knights of Lordearon" <---Let's say this one gets picked (randomly)
Names(4) = "..."
Names(5) = "..."

Player2
Race = Human
Names(1) = "..."
Names(2) = "..."
Names(3) = Knights of Lordearon <---Now this name will be unavailable for the next player
Names(4) = "..."
Names(5) = "..."

and so on...

I've tried here and there, but it doesn't really work...

Can anyone help? :confused:
Thnx.
 
If you have

something[1]
something[2]
...

number = 5

random = random number between 1 and number
do something with something[random]
something[random] = something[number]
number = number - 1

Ummmmmm, I 'kinda' get it yet I can't fully grasp what you mean by "do something".
There's too many "something"s that I can't understand it! :confused:

Can you explain it a bit, I dunno... "straightfoward"...? I guess?
 
set superDuperArray[1]
set superDuperArray[2]
set superDuperArray[3]
set superDuperArray[4]
set superDuperArray[5] <--- size of array stored in a variable ("number" in my example)

set number = 5

randomOfArray = random number between 1 and number

Do whatever you want with superDuperArray[randomOfArray]

set superDuperArray[randomOfArray] = superDuperArray[number]
set number = number - 1

Not really sure how to explain it better.
 
Using array is the best method. StringName[array] with MaxName = 5

StringName[1] = A
StringName[2] = B
StringName[3] = C
StringName[4] = D
StringName[5] = E

P1 chose B. Then

set StringName[2] = StringName[5]
set MaxName = MaxName - 1

P2 then have:

StringName[1] = A
StringName[2] = E
StringName[3] = C
StringName[4] = D
 
set superDuperArray[1]
set superDuperArray[2]
set superDuperArray[3]
set superDuperArray[4]
set superDuperArray[5] <--- size of array stored in a variable ("number" in my example)

set number = 5

randomOfArray = random number between 1 and number

Do whatever you want with superDuperArray[randomOfArray]

set superDuperArray[randomOfArray] = superDuperArray[number]
set number = number - 1

Not really sure how to explain it better.

Haha, I get it, Loud and clear.

THNX a lot everyone. Imma try them out!
 
Hey guys, I've got an issue again...

Everything was going perfectly until I saw that the (random) names for each players (depending on their races) suddenly had duplicate names!
So for example, if there were 4 human players, two of them would have comepletely different names, and the rest of the two will have the same names!

I mainly followed Chaosy's steps and while I was trying to solve this on my own, I've noticed that the "set number = number - 1" suggested by Chaosy doesn't really specify the exact name that has been picked before...
So I think the system just takes a random name out of the possible selections [in this case an unused name was taken out], when I want the specific, picked name to be taken out...

Any suggestions to prevent this from happening...?:confused:
 
Chaosy's method is correct; can you post your implementation of it?

Basically his method moves the final item of the array down to replace the randomly selected one and then "shrinks" the array (not really, but the number is decreased so it functions like you did). Are you sure you're decreasing number by one and making sure to generate a random bounded by that number correctly?
 
I mainly followed Chaosy's steps and while I was trying to solve this on my own, I've noticed that the "set number = number - 1" suggested by Chaosy doesn't really specify the exact name that has been picked before...
So I think the system just takes a random name out of the possible selections [in this case an unused name was taken out], when I want the specific, picked name to be taken out...
The idea is you select an element randomly in the list, remove that element from the list and then use that element. Unless you have duplicates in your list, each time a unique element will be removed until the list is empty.

To remove from a simple array list without caring about order, set the element being removed to the end of the list and decrement list length by 1.
 
Okay, after taking everyone's advice, I 'think' I got it under control...
I guess I messed up one of the steps Chaosy stated before!
Thnx everyone!
 
Status
Not open for further replies.
Back
Top