Game Development Community

Plastic Gem #9: Visual Editing

by Paul Dana · 06/19/2008 (2:43 pm) · 0 comments

Download Code File


i936.photobucket.com/albums/ad202/vincismurf/banner.jpg


Plastic Gem # 9 : Visual Editing

Difficulty: Easy

Gem 9 shows how to create a marker who's number will show some dynamic field value. We create a "PretendSpawn" shape that would be used to spawn some number of enemies and the marker number would show how many would spawn.

www.plasticgames.com/dev/blog_images/gems/zombieGrid_church.jpgThe Zombie Grid

We used this technique to implementdebug rendering for the Zombie Grid we use in our zombie game prototype, as depicted above. The zombie grid is a set of marker shapes placed in a mission that our script code connects into a mesh used for spawning and navigation. Each node shows how many zombies to spawn. The rings show the free spawn area around that nodes and the lines connect the nodes to show the mesh. This gem explains how we did the marker shape with the number, the rings and lines will be covered in a future gem.

www.plasticgames.com/dev/blog_images/gems/zombieSpawn_church.jpgThe Zombie Spawn Nodes

In our case we used more than just the marker number. As you can see above we used the color and size and symbol to show information as well. The yellow marker indicates a "zero" node. That is the default size of a node on the zombie grid. A larger size like you see here means a quicker respawn time - ie bigger nodes means zombies come out faster. The blue color indicates that zombies at those nodes will seek farther on the zombie grid to find a player (the grid is used for spawning and navigation). The diamond shape indicates that zombies will spawn from these locations even if that node is plainly in view of a player. We used all these features at this end show-down at the church and having a method of "visual editing" really helped us out there.

You must follow the instructions in Gem #2, and Gem #5, and Gem #7 before you can use this resource, and if you are doing that you really should likely follow Gem #3 as well..

1) Unzipping the files

After following the instructions in Gem #2, Gem #5, Gem #7 (and optionally Gem #3), unzip the pg09_visualEditing.zip file provided with this resource.

Place the pretendSpawn.cs and pretendSpawnManager.cs files into your ~/server/scripts folder.

2) Executing the Scripts

Edit the file ~/server/scripts/game.cs. Find the function called onServerCreated(). In there you will see lines of code that execute scripts. Here we need to execute the scripts we added. After these lines:
exec("./crossbow.cs");
   exec("./environment.cs");

execute the new scripts like this:

// > pg pretendSpawn
   exec("./pretendSpawn.cs");
   exec("./pretendSpawnManager.cs");
// < pg pretendSpawn

3) Binding the Cheat Function

Now edit your file ~/client/scripts/default.bind.cs. Add the following code to the bottom of the file to create a ctrl-shift T cheat bind to hide/show your spawners.

// cheat code to bind to show/hide your spawners....
GlobalActionMap.bind(keyboard, "ctrl-shift t", cheatToggleSpawners);

function cheatToggleSpawners(%val)
{
  if (%val)
     commandToServer('CheatToggleSpawners');
}

4) Placing some Pretend Spawners

www.plasticgames.com/dev/blog_images/gems/pretendSpawns_1_10.JPG
Place a PretendSpawnBaddy in the mission editor using the same steps described in Gem #1: Placeable Shapes. Note that, since you are in the Mission Editor the spawn will show up and display the number 1, the default numEnemies for a PretendSpawnBaddy.

Now place a PretendSpawnGroup and notice the number for this pretend spawner is 10, the default for that datablock.

5) Testing the Cheat Function

Now hit F11 to exit the Mission Editor and go back to regular play mode. Test our cheat function by pressing ctrl-shift T a few times. You should be able to make all the spawners you placed hide or show with this key press. You can use this to check on your spawners without having to enter the Mission Editor and fuss around.

Press F11 again to enter the Mission Editor and again press ctrll-shift T again and notice that the spawner toggling also works when the Mission Editor is showing. Ensure that the spawners are showing before continuing.

6) The Visual Editing Part

OK now we come to the part that justifies calling this gem "visual editing". We will change the number of enemies spawned for these markers and watch the marker number change by hiding and then showing the markers.

Choose the World Editor Inspector and select the first spawner you placed. The fields for that object appear when you select it. Scroll to the bottom to find the "dynamic fields" section and you should see two dynamic fields there. One of them is called "numEnemies" and should be set to -1. The -1 means to pickup the number to spawn from the datablock.

www.plasticgames.com/dev/blog_images/gems/pretendSpawn_set3.jpg
Change that -1 to the value 3 and hit the apply button. You will not see the number on the marker change yet. The code is written to make the marker update its number when the spawn is shown, so we must hide and show the markers to see the change. Use the ctrl-shift T cheat code to do this.

www.plasticgames.com/dev/blog_images/gems/pretendSpawns_3_10.jpg
Now select the other spawner you placed with the World Editor Inspector. Change the numEnemies field from -1 to 7 and hit the apply button. Use the ctrl-shift T cheat to toggle the spawns on and off.

www.plasticgames.com/dev/blog_images/gems/pretendSpawns_3_7.JPG
You should see the 10 change to a 7. You can always go back to using datablock defaults by setting the value to -1. The reason for using this method is that it allows you to change the default in the datablock and have that actaully have an effect on shapes already saved in the mission file. If we set the value to the default directly, instead of to -1 and using this method, then changing the datablock would have no effect on shapes already saved in the mission file.

As a final test you can save all your changes and quit out of your mission and then play your mission. You will notice that the spawners will be hidden by default, until you use the cheat code to show them.

The Next Gem

That's all for this gem which shows yet another way to use the incredibly useful marker shape. Next gem we will revisit the auto-naming marker and create another one of our more useful inventions: The Conference Gun! No, this is not some cool nerf gun to blow off steam at conferences. It is a weapon to use when doing design reviews with your team. It shoots auto-naming markers! We use this at Plastic Games along with Team Speak when we do a design review of game. If I want to tell Kirk I think we should have a fence from one place to another i can simply indicate the locations by shooting the gun and then saying "I'd like a fence from marker 6 to marker 7 over here". In other words we leverage the multiplayer nature of the game in development as part of our virtual team tool set.