Writing Weapon Scripts

At this point we have three files. A material (baseball_bat.mtl), a third person geometry file (baseball_bat_tp.cgf) and a first person character file (baseball_bat_fp.chr). It’s not enough to get a weapon into the engine. But to test that it’s working (and we should at this point) we could drag the CGF file into a map as level-geometry. To test the CHR file, use the Character Editor. Make sure everything is on the correct axis (and, for instance loading.) You should not see arms, just the weapon. (And if you enable the display of joints in the Debug Settings, you should see the arm skeleton.

To get CryEngine to treat these as weapons, we need to write a couple of script files. One is a chrParam file, it’s simply an XML file which tells the skeleton where to find animations. They can be a little complicated to set up, but not for something this simple. Melee weapons only need a few animations, that’s all. So this is a rather easy set up, I assure you. The trick is getting the file path right, and I’ve practically done that for you! :) (Hint: Practically means you need to put your animations in the folder we define as #filepath. And the names of the CAF files should sync up.)

baseball_bat_fp.chrParams

Try to ignore the header and footers, the meat of a ChrParams file is it’s AnimationList. (If you don’t believe me, check out basicPlayer.XML) Anyway, we define a filepath, tell CryEngine where to save our database, and declare which animations we’re using. Simple stuff. As long as you remember to put the animations into the folder you just defined.

Oh, one other thing about the chrParam file. The filename should be exactly the same as the *.chr file. This is for automatic loading of the script. (Otherwise you’ll have to set this up every single time. Me, I like saving time.)

The other script is a little more involved. It takes the assets we’ve created, and tells them how to behave as a weapon. Fortunately, if you have followed my tutorial up to this point – the chances are very good I’ve practically done the work for you. (As I’ll be providing the xml script used in this tutorial as reference. It’s a basic example, but it definitely works.)

baseball_bat.xml

It’s basically divided into sections, we’ll cover them one at a time.
First up are the params, these define settings. The important one is pose, the rest are just generally left as-is. Pose tells CryEngine what to derive from, “nw” is the default animation set provided by CryTek.

Geometry tells the Game where to look for the weapon models. These are just filepaths. As long as your geometry is located where you say it is here, things will work.

Each action can be defined, given a custom animation, and sound effects. In fact you can give them multiple animations, and it’ll randomly pick from them. Worth noting though, that target=owner is the third person rig associated with the character (usually his visible shadow.) The other, target=firstperson should be obvious, it calls the arms to action.

Firemodes are just that, types of attacks. We have one, a melee swing. All the parameters are fairly important, and hopefully obvious. Helper is the HelperNode (or joint) we created to tell CryEngine where the action is. Damage is well, how bad it stings. Impulse is the amount of force behind the blow. (0 for testing purposes, you’ll probably want a value of some kind here.) Delay is the amount of time (after the click) before the impact. And duration is the play speed (It’s a scalar.)

You’ll want to make sure these script files get to the right folders. For the chrParam, put it in the same folder as the *.chr file (for automatic loading.) The other xml file should be placed inside the CryEngine folder at Game/Scripts/Entities/Items/XML/Weapons. (You may have to create one or more of these directories.)

0 0 votes
Article Rating
8 Comments
Inline Feedbacks
View all comments
Hellman
Hellman
9 years ago

Hi man… Can you send me another files of this bat (xml,chr,model with hand ecc…) plz :) my email —> okenobi70@gmail.com ….

Shamnadhoh
Shamnadhoh
10 years ago

Nice tutorial. How I can make the enemy “stun” (knock-out without kill) when I hit him with the melee weapon??

Michael
Michael
10 years ago
Reply to  Shamnadhoh

Shamnadhoh,

Well, you’d need to do it via C++.

First you’d make sure the weapon does little or no damage. Then you would need to make a new kind of melee weapon which ragdollizes them instead of (or as well as) applying impulse. Then just have them revert to a standing state after some time.

This is just a guess. It’s how I would approach the task anyway.

trackback
CryEngine 3 Weapon Tutorial | rancidGames
10 years ago

[…] Writing the Game Scripts […]

Walter
Walter
10 years ago

Just wondering where the .xml file should be put; the path seems to be missing from the tutorial.

Michael
Michael
10 years ago
Reply to  Walter

Hm, indeed it is. I will have to fix the post.

It’s Game\Scripts\Entities\Items\XML\Weapons\, btw.

Walter
Walter
10 years ago
Reply to  Michael

Thank you for replying so quickly! I’ve now got a melee weapon entity in game =)

Michael
Michael
10 years ago
Reply to  Walter

Excellent! I’m glad to hear it. And happy to help, of course. :)