**********
if (`window -ex zmkr_win`) deleteUI zmkr_win;//eliminates previously made window
window -wh 200 75 -t "Zombiemaker" zmkr_win; //creates the window
columnLayout -adj true;//this holds the following buttons and textboxes
int $randNumber = 0;//this variable will hold the random number made
$txt_box = `textField -editable 1 -width 400 -text $randNumber`; //this creates the textbox using the above variable as the textbox's content
button -l "Random" -c "$randNumber = rand(1, 50); $txt_box = `textField -editable 1 -width 400 -text $randNumber`;"; //this is the first button, with display Random. The command will generate a random number, place it in the variable randNumber and place it on the new textfield
button -l "Create" -c "z_spawn($randNumber)"; //this is the second button and triggers the z_spawn procedure when clicked. Note that randNumber was thrown into the procedure.
showWindow zmkr_win;//this simply shows the window
proc z_spawn(int $a)//this procedure will spawn zombies based on the randNumber variable as $a.
{
int $num_zombies = $a; //$a will then be thrown into the num_zombies variable
string $all_characters[] = `ls -tr "zombie*"`; //This selects all currently existing zombies
if (size($all_characters)) delete $all_characters;//and deletes them
for ($i = 0; $i < $num_zombies; $i++)//this creates zombies based on the variable number
{
string $new_zombie[] = `duplicate -rr -un -n "zombie#" original_zombie_GRP`;//duplicate the zombie
setAttr ($new_zombie[0] + ".v") true;//set its visibility to 1 so that it is not hidden
float $randx = rand(-1120,1120);
float $randz = rand(-1120,1120);//create two variables to hold a pair of randomized spawn coordinates
move $randx 0 $randz $new_zombie[0];//and spawn it randomly across the coordinates
}
};
**********
And here are screenshots of the window in action. The first is a general screenshot of the menu:
A textbox is provided and the user is allowed to insert the amount of zombies they wish to spawn in the box. However, I failed to achieve that so currently, the textbox allows user to input numbers with no effect at all. The buttons, though, work as intended and here are screenshots of it:
This after the Random button was clicked. It work as intended: A random number generated and placed in a textbox. However, it generated a NEW textbox rather than editing the old one. Hence, constantly clicking the button will flood the menu and only the last textbox is legit. Now, here's the Create button:
The Create button works perfectly and the number of zombie generated (28 in this case) is spawned as is the number generated.
This exercise showed me some possibilities of Maya through the use of MEL scripting and the Expression Editor. It is rather interesting and fun as we can generate our own scene, like this zombie apocalypse, simple through the use of codes. The tutorial itself is very thorough, hence this was not a hard exercise, except for making the Zombiemaker window.



No comments:
Post a Comment