Game Development Community

Adding new weapons to starter.fps

by Jesse Breuer · in Torque Game Engine · 05/26/2006 (7:28 am) · 8 replies

I am relatively new to torque.
So far I have done the Intro tutorial at:
http://tdn.garagegames.com/wiki/Beginner/Torque_Intro
and the codesampler tutorials at:
http://www.codesampler.com/torque.htm
I am now trying to work with starter.fps and see what kind changes I can make to that.
I am currently attempting to introduce the rocket launcher from the code sampler tutorials
into the starter.fps. I would like to have it be a pickup that will fire. So far I can
either have it mounted at the beggining and have the firing work, or it can be a pickup
which doesn't fire.
I realize that the directory and class structures are different in the codesampler
tutorials from the way they are in starter.fps, so I assume it has something to do with that.
Here are the things I've done:

starting with starter.fps
1) added flat.mis and flat.ter from the intro tutorial to have a clean slate landscape to
work with.

2)in game.cs commented out the following
so that the crossbow will not be mounted at start:
// Starting equipment
//%player.setInventory(Crossbow,1);
//%player.setInventory(CrossbowAmmo,10);
//%player.mountImage(CrossbowImage,0);

At this point crossbow can be loaded into the game and picked up

3)added rocket_launcher folder to data/shapes
Copied the "rocket_launcher.cs" script to "/server/scripts" directory.
added: exec("./rocket_launcher.cs"); to game.cs in /server/scripts directory commented out
crossbow exec.
added
datablock ItemData(Crossbow){} section from crossbow.cs to rocket_launcher.cs and changed
all instances of "crossbow" to "rocketlauncher" like so:

datablock ItemData(Rocketlauncher)
{
// Mission editor category
category = "Weapon";

// Hook into Item Weapon class hierarchy. The weapon namespace
// provides common weapon handling functions in addition to hooks
// into the inventory system.
className = "Weapon";

// Basic Item properties
shapeFile = "~/data/shapes/rocket_launcher/rocket_launcher.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;

// Dynamic properties defined by the scripts
pickUpName = "a rocketlauncher";
image = RocketLauncherImage;
};

now it is loadable into the game but won't mount onto the character.

4)added
maxInv[Rocketlauncher] = 1;
to player.cs
now it mounts but doesn't shoot

5)added
maxInv[RocketProjectile] = 1;
to player.cs
copied and changed starting inventory above in game.cs
%player.setInventory(Rocketlauncher,1);
%player.setInventory(RocketProjectile,10);
%player.mountImage(RocketLauncherImage,0);

changed inventory to:
maxInv[RocketProjectile] = 10;
added
%player.setImageAmmo( 0, 1 ); to game.cs now it shoots
like so:
%player.setInventory(Rocketlauncher,1);
%player.setInventory(RocketProjectile,10);
%player.mountImage(RocketLauncherImage,0);
%player.setImageAmmo( 0, 1 );
Now it is mounted at launch and shoots.
What I have not been able to do is to have it be both mountable and shootable. Any halp
would be appreciated. thanks in advance,
Jesse

About the author

Recent Threads

  • Max 2 dts question

  • #1
    05/26/2006 (11:13 am)
    Wow, what a messy post. Please use tags in the future, there's a link down the bottom if you don't know the syntax.

    After reading through all that, I dont understand your question.
    Quote:
    What I have not been able to do is to have it be both mountable and shootable.

    Please explain?
    #2
    05/26/2006 (11:28 am)
    It sounds as if you haven't changed the name of the CrossbowImage and CrossbowProjectile references in the code, as well as possibly the namespaces for functions like CrossbowProjectile::onCollision().

    Tim is right, the code and quote tags are quite helpful in getting across your message, but don't take his post the wrong way--it's obvious that you did spend time putting your post together, and not knowing about the markup tags available isn't a problem the first couple of posts!

    It's also very possible that you have one or more script errors in your changed file, which is causing it not to load. Try deleting the rocket_launcher.cs.dso file, restart Torque, and then look in your console (press the ~ key), scroll up in the console window, and see if you have any script related errors in your rocket_launcher.cs file.
    #3
    05/26/2006 (11:37 am)
    As Stephen briefly touched on, I've found it a good habit to get into running the cleanup scripts (batch files) after making changes to your .cs, etc...

    Saves a ton of hastle down the road.
    #4
    05/30/2006 (8:41 am)
    Tim: Thank you for letting me know about the tagging.
    What I meant was that as the code is now, I can either have the weapon mounted to the player character at the start of the game, in which case it fires properly, or I can have it be a pickup that is aquired by the player in the course of the game, in which case it does not fire with a mouse click event as intended. So I was basically asking: "what changes to the code will I need to make to have the weapon fire properly after being picked up by the player character"

    Stephen: thanks for your suggestions, I will give these things a try and post to let you know how it goes.

    Jon: the cleanup scripts are a new concept to me, is there somewhere i can read more about how that works?
    #5
    05/30/2006 (9:25 am)
    Jesse,

    You have not set the key to switch to the weapon you pick up. This is done in starter.fps\client\scripts\default.bind.cs and starter.fps\client\config.cs

    Look up for a line like this:

    moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"Crossbow\");", "");

    Change Crossbow to Rocketlauncher, run the cleanup script and test.

    NOTE: The cleanup scripts are simple batch files that delete all the DSO files. DSO files are the "compiled" scripts.
    #6
    05/30/2006 (11:07 am)
    Jesse, I tested it and I got the same result so don't feel bad for not getting this working on the first try.

    There are several things missing from the reocket_launcher.cs file. One is an ItemData block for the rocket launcher ammo. I copied this section from the crossbow, called it RocketLauncherAmmo and change every reference from crossbow to rocket_launcher. Also, the RocketLaucherImage block is missing the classname, item and ammo fields. Again, I copied it from crossbow and gave it the correct values.

    Then the player.cs is missing "maxInv[RocketLauncherAmmo] = 10;"

    Now I got a working rocket launcher. Try it and let me know how it works.
    #7
    05/30/2006 (12:58 pm)
    Thanks for your help, BigPapa, I'll let you know how it goes. Can you go into a little more detail about the cleanup scripts? Is this something that I can find in the menu structure of the editor window, or is it a command that I enter somewhere?
    #8
    05/30/2006 (1:48 pm)
    DeleteDSOs.bat is just a batch file that can be run by typing the batch name in a DOS window or by double-clicking it in the windows explorer. Its located under c:\torque\sdk14\example. If you have anything older than 1.4 then it's not there but you can just create your own and put the following code in it.

    del /s *.dso

    This deletes all the files with dso extension so that they are recreated when you run starter.fps again.

    Hope that helps.