Is there any way to give a hero a random name from a list? I have my hero unit, named "Stranded Marine", and I was wondering if it was possible to allocate it a random name from a set of names, as in Warcraft 3
If you have only one type of your hero present in the map at any time per player, you can change the name through the Catalog function. However, if you want to keep the name of the hero type (the big text) and the name of the hero in smaller text below, like in Warcraft 3, you have to conjure some stronger magic.
There's only one hero, but it's shared by many players. I'd like for each instance of this same unit to have a different random name. Is this possible?
It is. When you change data in the Data Editor using the trigger function Catalog you change the values for a specific player only. Unless of course you iterate through a series of players.
Make a String array containing the Hero names and then set the name using the Catalog function, like so:
Variable - Set HeroNames[1] = "Homer"
Variable - Set HeroNames[2] = "Zeratul"
Variable - Set HeroNames[3] = "Kate Lockwell"
Catalog - Set value of Unit "UnitNameRawData" "Name" for player 1 to HeroNames[Random integer between 1 and 3]
The Raw Data reference will never change, so you may change the name as many times as you like.
I'm gonna throw you this one, but this is really basics of map making. I suggest you read some tutorials and experiement with various test maps.
Creating a new global variable:
Open the Trigger editor
In the left-most area right-click any item, locate "New" and click "New Variable" (or simply hit [Ctrl+B])
Name your newly created variable something meaningful, such as HeroNames (you can always rename items by selecting them and hitting [F2])
Set the variable type to "String" in the dropdown combo box in the right-most area
Check "Array" and set size to the number of names you desire
You may also make the variable local, meaning it can only be read by the current trigger, function or action definition. You create local variables inside e.g. triggers.
Adding data to the variables:
What I wrote in the above example.
An important note: Arrays start at 1 in the Trigger Editor, not 0 as you would expect if you have been coding in high-level programming languages like C or Java.
Would it be possible to give random portraits? You could just create multiple heroes with different names, copy the same hero and give it a different name. If it's a marine you can make it feel really different with the loads of marine portraits they have. Maybe give tychus voice and raynor voice to add to the differences.
@Mesothere: Go
An important note: Arrays start at 1 in the Trigger Editor, not 0 as you would expect if you have been coding in high-level programming languages like C or Java.
This statement is false, Arrays Start at 0 in the Trigger Editor not 1. So if you have a List of 50 names then make your array 49 or something. What I usually do for a number like that is set it to a high number like 104 or something, so I can constantly add things without worring about the variable too much.
True.
Var[1] means "max array is 1", but it starts as 0. It's way handy and logical to use, because in WC3 we had choice to substract 1 to each value when dealing with players or adding one more array.
Even if that was how programmation works, it was a little bit messy and difficult to understand to non-programmer people.
But some times ago, you'll never used all that arrays you don't need, because of memory restrictions x) Thanks now we got really powerful computers to do that...
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hey,
Is there any way to give a hero a random name from a list? I have my hero unit, named "Stranded Marine", and I was wondering if it was possible to allocate it a random name from a set of names, as in Warcraft 3
@Mesothere: Go
If you have only one type of your hero present in the map at any time per player, you can change the name through the Catalog function. However, if you want to keep the name of the hero type (the big text) and the name of the hero in smaller text below, like in Warcraft 3, you have to conjure some stronger magic.
@Kafoso: Go
There's only one hero, but it's shared by many players. I'd like for each instance of this same unit to have a different random name. Is this possible?
You could just make a list of first and last names and then randomly pick from that.
@Mesothere: Go
It is. When you change data in the Data Editor using the trigger function Catalog you change the values for a specific player only. Unless of course you iterate through a series of players.
Make a String array containing the Hero names and then set the name using the Catalog function, like so:
The Raw Data reference will never change, so you may change the name as many times as you like.
@Kafoso: Go
That's a really helpful reply, but one small thing, I know it seems simple but I simply can't figure it out :( How do I make a custom string?
@Mesothere: Go
I'm gonna throw you this one, but this is really basics of map making. I suggest you read some tutorials and experiement with various test maps.
Creating a new global variable:
You may also make the variable local, meaning it can only be read by the current trigger, function or action definition. You create local variables inside e.g. triggers.
Adding data to the variables: What I wrote in the above example.
An important note: Arrays start at 1 in the Trigger Editor, not 0 as you would expect if you have been coding in high-level programming languages like C or Java.
@Kafoso: Go
Thanks a load, works a treat :)
Edit : My mistake.
Thx for it, that works ;)
Would it be possible to give random portraits? You could just create multiple heroes with different names, copy the same hero and give it a different name. If it's a marine you can make it feel really different with the loads of marine portraits they have. Maybe give tychus voice and raynor voice to add to the differences.
This statement is false, Arrays Start at 0 in the Trigger Editor not 1. So if you have a List of 50 names then make your array 49 or something. What I usually do for a number like that is set it to a high number like 104 or something, so I can constantly add things without worring about the variable too much.
@XDretsamtovip: Go
True.
Var[1] means "max array is 1", but it starts as 0. It's way handy and logical to use, because in WC3 we had choice to substract 1 to each value when dealing with players or adding one more array.
Even if that was how programmation works, it was a little bit messy and difficult to understand to non-programmer people.
But some times ago, you'll never used all that arrays you don't need, because of memory restrictions x) Thanks now we got really powerful computers to do that...