Game Development Community

Help about pick up weapon and shoot with they

by Manuel M · in Torque 3D Professional · 07/13/2011 (10:01 am) · 7 replies

Hello,
I'm learning how to work with Torque 3D, I have short time for this and my progress is very very slow. Well, now I'm lost about the weapon system and I have some questions about this.

I created a weapon from the datablock editor and I want my player to pick up the weapon, this is where I'm lost, also I don't understand (for now) how to shooting with the weapon, I don't know if I need added some code into the player script or what...

Can you explain me a bit how to works these systems? Is not necessary a tutorial or guide, I only want some reference about this, I just want to know how to work it for to practice for myself.
I have created a empty project, I don't use the full template because I want to understand all well, and for my, the best way to do this is to create a project from zero.

Thank you!

#1
07/13/2011 (10:20 am)
You'll need the inventory.cs, item.cs, and weapon.cs script files from the full template. These contain methods that when used together give a basic pick-up, use, and store (add/remove) in inventory functionality.

A player datablock will need the maxInv[ITEMNAME] property set in order for it to be able to pick an item/weapon up. A value of one should be used to allow for something that a player should only have one of, such as a weapon. Larger values for things like keys, ammo, etc. If this property is not set, then the play will not pickup the item.

Since you're using the Empty Template you'll also need an onFire() method for your weapon to use, and likely need projectile::onCollision() & projectile::onExplode() callbacks as well.

If you were using the Full Template I already had this setup so that all a weapon needs is the relevant datablock, so refer back to the scripts in the Full Template for examples.
#2
07/13/2011 (10:24 am)
I can understand not using the full template as a base, but refusing to use it as a reference is like buying a reference book and refusing to read the inside pages.

The full template has real world examples of a ammo using weapons, if you combine that with steves fake melee resource you also have a non ammo using weapon too, both of which are player collectable weapons. You will probably need to see steves half life weapon switching resource to see how to switch between weapons.

That should be enough to complete almost everything you need to know about weapon stuff :)
#3
07/13/2011 (10:40 am)
I would take a look at the Full Template or the FPS Example that comes with T3D to get a better idea on what you'll need for weapons. If you look in the FPS Example, you'll notice in the ./game/art/datablocks/weapons folder a list of TorqueScripts that define just about everything needed to implement three different weapons (a grenade launcher, Gideon's rocket launcher and the new soldier gun). Any of these files will be a good starting point for learning how to define and setup your own weapon.

Next, take a look in ./game/server/scripts and find weapon.cs, item.cs and inventory.cs. Each of these files handles different aspects of the weapon system. weapon.cs takes care of things like picking up and mounting the weapon and firing it, item.cs takes care of respawning and throwing items and inventory.cs implements a basic inventory system so that players can track ammo, which weapons they're currently carrying, etc.

Hopefully that's enough to get you started. :)

Edit: Too slow!
#4
07/13/2011 (10:43 am)
Thanks for the quick answer!
Michael, with "maxInv[ITEMNAME]" do you refer to the "dynamic fields"?

Quote:I can understand not using the full template as a base, but refusing to use it as a reference is like buying a reference book and refusing to read the inside pages.
Well, that's true, but I have always learned in this way and always works for my. I only need a good API reference and some examples, and the full template is a big example for me, so I will study it!

Maybe the empty template is not necessary for some of my projects, but I want to understand how to work all the engine, and the full template is a bit confused for my, because use many script and I need to link one script with another script for seen how to works it, etc.
Well, I think Torque 3D is the most difficult game engine that I never used, and I like that lol. It will take time to learn to use it, but I will, time to time...

Thank you again!
#5
07/13/2011 (11:26 am)
Yes, the maxInv[ItemName] properties are dynamic properties.

As well as the projectile callbacks (founds in projectile.cs) you'll also want to take a look at radiusDamage.cs for how to apply explosion damage, as opposed to direct damage, and impulse effects.

Forgot to mention this but inside of default.binds.cs (client scripts) you'll find the keybinds for weapon switching:
  • The number keys examples works like hotkeys with one weapon per number.
  • The mouse wheel, or the Q key (shift+Q for reverse), is set for weapon cycling when used with code found in weapon.cs. The weapon cycling will only work if you setup the array index with the WeaponOrder() command which is also found in weapon.cs.
#6
07/13/2011 (11:40 am)
I setup generic WeaponImage namespace onFire() methods inside of weapon.cs. This is sufficient for most weapon types, but can be easily overridden if you have a weapon that requires a more custom firing mechanic.

If they're still in there (may be found in the FPS Example), I gave the alt-fire mode of the Rocketlauncher (multishot), and the alt-fire mode of the Grenadelauncher (triggered grenade) custom onFire() methods as examples of how to override the generic function. These will be found as individual (according to weapon name) scripts in the "scripts/server" directory -- the T3D practice of separating the scripts from datablocks tends to confuse some people.
#7
07/13/2011 (4:09 pm)
Interesting, thank you again.
I think that I will to create a weapon from full template, a custom weapon and I will study all functionality, the necessary scripts, etc., and then, I will to create a weapon in empty template.

About the "default.binds.cs", someone told me in some time that one key for one function, I can't asign one key for several functions, right? but, if I make a function and this function can call more that one function, I can solved it, right? for example, on pseudo code:

function (%functionType)
{
	if (%functionType == 1)
	{
		function1();
	}
	else
	{
		function2();
	}
}

And from default.binds.cs call this function with some key and send to it the value for execute either function, it's possible?

Thank you very much!