• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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.
 
Level 3
Joined
Apr 29, 2010
Messages
54
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?
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
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.
 
Level 10
Joined
Sep 16, 2016
Messages
269
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
 
Level 3
Joined
Apr 29, 2010
Messages
54
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!
 
Level 3
Joined
Apr 29, 2010
Messages
54
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:
 

EdgeOfChaos

E

EdgeOfChaos

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?
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
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.
 
Level 3
Joined
Apr 29, 2010
Messages
54
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.
Top