Game Development Community

Plastic Gem #10: The Conference Gun

by Paul Dana · 06/20/2008 (9:20 am) · 1 comments

Download Code File


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


Plastic Gem # 10 : Conference Gun

Difficulty: Easy

www.plasticgames.com/dev/blog_images/gems/pointerGun.jpg
Hi again from Plastic Games. Gem 10 shows 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 autonaming 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 toolset.

You must follow the instructions in Gem #2, and Gem #5, Gem #7 , and Gem #8 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, Gem #8 (and optionally Gem #3), unzip the pg10_conferenceGun.zip file provided with this resource.

Place the PointerGun.cs file 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 pointerGun
   exec("./PointerGun.cs");
// < pg pointerGun

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 give yourself a pointer gun...
GlobalActionMap.bind(keyboard, "ctrl-alt 9", mountPointerGun);

function mountPointerGun(%val)
{

   if(%val)
      commandToServer('use',"PointerGun");
}

4) Adding Gun to Inventory

Now find the code where your player datablock is defined. If you are usisng an unmodified demo that will be ~/server/scripts/player.cs. Find the datablock that looks like this:

datablock PlayerData(PlayerBody)
{

...add, after the line:

maxInv[Crossbow] = 1;

maxInv[PointerGun] = 1;
   maxInv[PointerGunAmmo] = 1000;

5) How does it work?

Most of the pointerGun.cs file is just a copy of the crossbow stuff. The meat of the gem is the projectile collision function:

function PointerGunProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
   //move position so we can see the marker un obstructed   
   %newVec = VectorAdd(%pos, %normal);  
    
   %marker =    new StaticShape(){
      datablock = SampleDigitMarker; 
      position = %newVec;
      scale = "0.5 0.5 0.5";
   };

   MissionCleanup.add(%marker);
}

As you can see this code simply creates a static shape with a SampleDigitMarker as the datablock at the point of impact.

6) Trying it out!

Now load a mission and press ctrl-alt 9. A crossbow style weapon should appear and when you shoot it, it should leave behind markers!

The Next Gem

That's all for this gem, and frankly that's enough coding for a while. The next gems will be art! Our very fine artist, Kirk Alberts, has prepared a free texture set as well as some examples of use. Until next week...

#1
06/23/2008 (12:44 pm)
This would be so useful if only I had a team. :)