The 3rd Age

The Elven Alliance

The Elven Alliance

Adding a completely new Elven faction with unique units to the game

Button for The 3rd AgeButton for The Dwarf HoldsButton for The Elven AllianceButton for Helm's Deep Last HopeButton for GothmogtheOrcButton for BFME+Button for The Four AgesButton for HDR HeadquartersButton for Middle Earth CenterButton for Project Perfect Mod

Become an affiliate!

   

Quick Lists

Top Rated Popular New Updated Last Comments Users

Register and log in to move these advertisements down

Weapons & Weaponsets

Tutorial for Battle for Middle-earth BFME, Battle for Middle-earth II BFME 2, Battle for Middle-earth II: Rise of the Witch-king ROTWK

Avatar of Hostile

Hostile

Category: Code
Level: Beginner
Created: Monday March 26, 2007 - 13:17
Updated: Monday March 26, 2007 - 13:20
Views: 11847
Summary: What are Weapons and WeaponSets and how do they work

Rating

Staff says

3.4

Members say

4.3

Average

3.8/5.0

9 votes

Adding A New Unit - Weapons

Written by: Hostile

The purpose of this tutorial is to give you an understanding on how weapons work. This should help you to make your own weapons. This doesn't explain every possible item but gives an overview of what is possible.

We will get started with understanding how the weapon.ini works. Besides a weapon having numerous settings to control attack range and clip size and such, they specifically use NUGGETS. A NUGGET is a section of code that defines how the weapon will behave when it comes to damage.

We'll start by looking at Legolas Bow. The weapon itself is defined. The object that will be the arrow is defined, and the warhead itself is defined. The bow itself does no damage, nor does the arrow. It's the arrowhead that does the damage. The rest is just the delivery mechanism.

              
Code
Weapon LegolasBow
AttackRange = LEGOLAS_BOW_RANGE
WeaponSpeed = 321 ; dist/sec
MinWeaponSpeed = 241
MaxWeaponSpeed = 481 ; dist/sec Upper limit on scaling, when attacking past nominal "max" range
FireFX = FX_RohanArcherBowWeapon
ScaleWeaponSpeed = Yes ; Used for lob weapons, scales speed proportional to range
HitPercentage = 100 ;When this weapon is used it will hit exactly 100% of the time.
ScatterRadius = 5.0 ;When this weapon misses it can randomly miss by as much as this distance.


The code starts with defining the attack range. LEGOLAS_BOW_RANGE is directly referenced from the gamedata.ini. You may just place a number here if you do not feel like listing it in the gamedata file for your new weapon. Weaponspeed is pretty cut and dried. How fast is this arrow going to fly to it's target? Min/Max WeaponSpeed scales the speed ingame so when firing at a target very close, it will slow down so you can see the fx better. The opposite being true for farther targets.

This also takes into account that objects appear faster when closer to the ground than high in the air. Used for "lobbed" weapons.

FireFX is referenced from the fxlist.ini. This allows you to add sounds FX, or particle FX to a weapon when it fires. Looking at the code from the fxlist.ini, is basically just includes a sound.
              
Code
FXList FX_RohanArcherBowWeapon
Sound
Name = ArcherWeapon
End
End


ScaleWeaponSpeed goes hand in hand with the Min/Max WeaponSpeed. This is required to tell the game to use such parameters. HitPercentage is fun because you can assign it to miss with some percentage. Not every archer hits thier mark everytime. You can also tell the game how much can he miss by with the ScatterRadius. You might not hit your exact target but if there are enough targets, you might hit something.

              
Code
AcceptableAimDelta = 20 ; prevent twitchy reaiming in horde on horde
DelayBetweenShots = LEGOLAS_DELAYBETWEENSHOTS ; time between shots, msec
PreAttackDelay = LEGOLAS_PREATTACKDELAY ; 1467 is the prep time for archer.
PreAttackType = PER_POSITION ; Do the delay each time we attack a new target
FiringDuration = LEGOLAS_FIRINGDURATION ; Duration of the archer firing shot is 500ms.


These settings control how long it takes to retarget, fire again, and how long it actually takes while firing.

              
Code
ClipSize = 1
AutoReloadsClip = Yes
AutoReloadWhenIdle = 1
ClipReloadTime = Min:LEGOLAS_RELOADTIME_MIN Max:LEGOLAS_RELOADTIME_MAX
ContinuousFireOne = 0
ContinuousFireCoast = LEGOLAS_RELOADTIME_MAX
AntiAirborneVehicle = Yes
AntiAirborneMonster = Yes

ProjectileNugget ; Default Arrow
ProjectileTemplateName = GoodFactionArrow
WarheadTemplateName = LegolasBowWarhead
End
End


Clipsize can be interesting because you could have a repeat fire bow. Shoots threes arrows at once. ClipReloadTime tells us how long does it take for Legolas to knock an arrow. These are defined in gamedata.ini.

              
Code
AntiAirborneVehicle = Yes
AntiAirborneMonster = Yes

ProjectileNugget ; Default Arrow
ProjectileTemplateName = GoodFactionArrow
WarheadTemplateName = LegolasBowWarhead
End


The next two lines of code allow this weapon to be fired at flying vehicles (Mmmm...) and flying monsters. The last section defines what the object is that flies from the bow and what arrowhead will it be carrying. ProjectileTemplateName is the object that is the arrow itself.

The Arrow object is a projectile that carries the arrowhead. It is actually an object located in \data\ini\object\goodfaction\goodfactionsubobjects.ini. Use control "F" and search using GoodFactionArrow. You'll see all kind of variations of the arrow based on faction or upgrades and such.

WarheadTemplateName is the arrowhead itself. This is what causes the damage. Legolas does not have flaming arrows as an upgrade. But if you wanted him to, than you can look to the normal bowmen for the code.

              
Code
ProjectileNugget ; Default arrow
ProjectileTemplateName = GoodFactionArrow
WarheadTemplateName = RohanArcherBowWarhead
ForbiddenUpgradeNames = Upgrade_RohanFireArrows
End
ProjectileNugget ; Fire arrow avialble through fire upgrade
ProjectileTemplateName = GoodFactionFireArrow
WarheadTemplateName = RohanArcherBowFireWarhead
RequiredUpgradeNames = Upgrade_RohanFireArrows
End


The first ProjectileNugget forbids it to be available if there was an upgrade to flaming arrows. The second Nugget it what activates the new warhead type based on the upgrade. You could very well add poison arrows, if you like, that does more damage to infantry but less to structures. Play with it and see.

Let's talk more about the warhead.

              
Code
Weapon LegolasBowWarhead
ProjectileCollidesWith = ALLIES ENEMIES NEUTRAL STRUCTURES WALLS
RadiusDamageAffects = ENEMIES NEUTRALS NOT_SIMILAR
HitStoredTarget = Yes ; Always hits initial target.
DamageNugget ; A basic Nugget that just does damage
Damage = LEGOLAS_BOW_DAMAGE
;DamageScalar = 25000% NONE +MordorMumakil
Radius = 0.0 ; HitStoredTarget means we hurt the person we launched at. And nobody else. So a miss hurts nobody.
DelayTime = 0
DamageType = HERO_RANGED
DamageFXType = GOOD_ARROW_PIERCE
DeathType = NORMAL
End
End


This project can collide with just about all the units on the field. Why you would want to shoot your allies is a good question. HitStoredTarget from my point of view is used for hordes. This mean no matter what the miss ratio, at least the first target is hit.

The DamageNugget defines what kind of damage this arrowhead is capable of delivering. The damage itself is defined in gamedata.ini. The damage type seems redunant. I'm not sure on that one but DamageFXType gives us a chance to define whether the target is hit by a normal arrow, a flaming arrow, or poison arrow. You can define what the FX looks like in fxlist.ini.

DeathType tells the computer what animation it should use when the unit dies from the arrow. There are specific deathtypes used in the game. Alittle research will show you there are quite abit. You may have a arrow that crushes your enemy if you choose. You can also have a damage radius for the arrow. Does this arrow have a granade tied to it? If it does than you can blast more than just the unit you hit.

This can even be made more fun by adding a DelayTime, the arrow can hit, than a second later it blows up. This allows the unit hit to be able to look down and see the grenade tied to the arrow before it blows up.

If you look to the fire arrows you'll see additional damage nuggets to reflect the new damage types. Such as this:
              
Code
DamageNugget ; A basic Nugget that just does damage
Damage = ROHAN_YEOMAN_FIRE_UPGRADE_DAMAGE_FIRE
Radius = 0.0 ; HitStoredTarget means we hurt the person we launched at. And nobody else. So a miss hurts nobody.
DelayTime = 0
DamageType = FLAME
DamageFXType = GOOD_ARROW_PIERCE
DeathType = BURNED
AcceptDamageAdd = No
End

DamageNugget ; A basic Nugget that just does damage
Damage = 1
Radius = 0.0 ; HitStoredTarget means we hurt the person we launched at. And nobody else. So a miss hurts nobody.
DamageType = FLAME
DamageFXType = FLAME
DeathType = BURNED
DamageScalar = 50000% NONE +MINE ; Make sure we one shot kill mines, without risking wasting some poor hero with a torch
End


Now, not only did you get shot with an arrow, now you're going to get fire damage as well. So you are getting multiple damage here. DamageScalar = 50000% NONE +MINE means that this will cause a mine to blow up with a flame arrow. Bet you didn't know that huh?

Let's get into close combat weapons now. We'll look to the Gondor foot soldier.
              
Code
Weapon GondorSword
LeechRangeWeapon = Yes
AttackRange = 30.0
MeleeWeapon = Yes
DelayBetweenShots = GONDOR_SOLDIER_SWORD_DELAYBETWEENSHOTS ; Bad Things happen if delay between shots is less than Preattack+Firing times. You are ready to fire before you are done firing.
PreAttackDelay = GONDOR_SOLDIER_SWORD_PREATTACKDELAY ; 400 is sword swing delay time before contact with target.
PreAttackType = PER_SHOT ; Do the delay each time we attack a new target
FireFX = FX_GondorSwordHit
FiringDuration = GONDOR_SOLDIER_SWORD_FIRINGDURATION ; Duration of the sword swing

DamageNugget ; A basic Nugget that just does damage
Damage = GONDOR_SOLDIER_SWORD
Radius = 0.0
DelayTime = 0
DamageType = SLASH
DamageFXType = SWORD_SLASH
DeathType = NORMAL
End
End


Close range weapons should be a breeze to understand after the bows. LeechRangeWeapon is something I can't figure out. AttackRange is how far from the enemy you can be when you can start attacking. The DamageNugget is the same as above but notice the damage type, SLASH. There are also PIERCE and such. I'm not sure what advantage one has over the other but here they are.

But here is a list of damage types. It's not a complete list but should get you started.

"FORCE", Formless force, like shockwave
"CRUSH", Blunt and heavy hit
"SLASH", sharp and slicey hit
"PIERCE", pointy and pokey hit
"SIEGE", Siege weapons get their own thing
"FLAME", Burning
"HEALING", Special use healing
"UNRESISTABLE", Special use system damage
"WATER", Falling in water
"PENALTY", Special use system damage
"FALLING", Falling far and hitting ground
"TOPPLING", Trees


That finishes up weapons. But for every offense there is a good defense...

I hope this answers a few questions regarding the weapon code for your new unit. Any further questions about this tutorial can be answered by coming to our forums.

Credits

GothmogtheOrcporting the tutorial to the new site

Comments

Display order: Newest first

Ridder Blauw - Wednesday June 18, 2008 - 23:03

I did not get your tutorial, but I think I was not reading it correctly, so my brother did it for me.

Sulherokhh (Team Chamber Member) - Monday April 30, 2007 - 19:04

Damage type is only important to determine, which armor filter is used. But i have no idea about the LeechRangeWeapon either. Otherwise a very good summery!

Go to top

 

"One site to rule them all, one site to find them,
one site to host them all, and on the network bind them."

 
23:55:42