Classes:Weapon
From ZDoom Wiki
| Weapon | |||
|---|---|---|---|
| Actor type | Internal | Game | |
| DoomEd Number | None | Class Name | Weapon |
Classes: Inventory→Weapon
→Beak
→Chainsaw
→ClericWeapon
→DoomWeapon
→FighterWeapon
→Fist
→HereticWeapon
→MageWeapon
→PhoenixRod
→Sigil
→Snout
→StrifeWeapon
Weapon is the base class for all weapons in the game. Weapons are the most complex of all inventory items because due to their nature they require additional animation states.
A player can never carry more than one weapon of each kind.
Do not forget weapon icons! Even though they are not used by the default HUDs for Doom, Heretic and Hexen, ZDoom uses them for Strife's HUD and for the alternate HUD. SBARINFO HUDs can also require them.
Using in DECORATE
In addition to some of the basic Inventory properties Weapons support the following:
- weapon.ammogive amount
- Alias for weapon.ammogive1.
- weapon.ammogive1 amount
- The amount of primary ammo you receive from this weapon.
- weapon.ammogive2 amount
- The amount of secondary ammo you get from picking up the weapon.
- weapon.ammotype type
- Alias for weapon.ammotype1.
- weapon.ammotype1 type
- The type of primary ammo the weapon uses. This must be a valid ammo type.
- weapon.ammotype2 type
- The type of secondary ammo the weapon uses.
- weapon.ammouse amount
- Alias for weapon.ammouse1.
- weapon.ammouse1 amount
- The amount of primary ammo the weapon uses per shot.
- weapon.ammouse2 amount
- The amount of the secondary ammo that the weapon uses per shot. Normally secondary ammo is used by the secondary attack but if the WEAPON.PRIMARY_USES_BOTH flag is set the primary attack will use both types of ammo for each attack.
- weapon.kickback amount
- How far attacks by this weapon push the enemy back. Damage is also a factor in kickback.
- weapon.readysound sound
- The sound the weapon plays in its ready state.
- weapon.selectionorder value
- Defines the place in the weapons list when ammo runs out. Lower numbers have higher priority.
- weapon.sisterweapon weapontype
- Defined weapon is also given when flagged weapon is picked up. Used primarily for Tome Of Power attacks but it can also be used to create weapons with 2 distinct attack modes. Several Strife weapons use this.
- weapon.upsound sound
- The sound played when the select state is called.
- weapon.yadjust amount
- Shifts the HUD sprites vertically when the status bar is off.
Weapons also define new flags (note: The WEAPON. prefix is not necessary. However, to make things easier to read it is recommended to be used):
- WEAPON.NOAUTOFIRE
- Does not fire when selected automatically and the fire button is still pressed. Used to prevent dangerous weapons from firing accidentally.
- WEAPON.READYSNDHALF
- The ready sound is played only with 50% probability.
- WEAPON.DONTBOB
- The weapon sprite does not bob.
- WEAPON.AXEBLOOD
- This weapon spawns the special AxeBlood type when hitting something that bleeds. This only has an effect for hitscan and melee weapons.
- WEAPON.NOALERT
- Does not alert nearby monsters when being fired.
- WEAPON.AMMO_OPTIONAL
- Tells the engine that this weapon doesn't require ammo to work.
- WEAPON.ALT_AMMO_OPTIONAL
- The same for the alternate attack.
- WEAPON.PRIMARY_USES_BOTH
- The primary attack uses both ammo types.
- WEAPON.WIMPY_WEAPON
- A small weapon with limited capabilities. If ammo for something better gets picked up the game will automatically switch weapons.
- WEAPON.POWERED_UP
- This is a powered up weapon. Powered up weapons cannot exist by themselves. They always are linked to a normal weapon via the weapon.sisterweapon property and are only activated by using Heretic's Tome of Power or another artifact based on PowerWeaponLevel2.
- WEAPON.STAFF2_KICKBACK
- Uses the special kickback formula of Heretic's powered up staff. Unlike normal kickback this is a fixed thrust value.
- WEAPON.EXPLOSIVE
- Signifies bots that the weapon fires explosive projectiles.
- WEAPON.MELEEWEAPON
- Signifies bots that the weapon is a melee weapon.
- WEAPON.BFG
- Signifies bots that the weapon causes a lot of damage.
- WEAPON.CHEATNOTWEAPON
- Weapon is not given by the 'give weapons' cheat.
- WEAPON.NO_AUTO_SWITCH
- When the player picks this weapon up, they will never automatically switch to it.
Weapons also require additional states to define the HUD weapon animation:
- Ready
- Defines the weapon's ready sequence. If a weapon is in this sequence it can fire and be deselected.
- Deselect
- Defines a weapons lowering sequence. It must lower the weapon to the bottom of the screen and should not do any other actions.
- Select
- Defines a weapons raising sequence. It must raise the weapon to the normal firing height and should not do any other actions.
- Fire
- AltFire
- Defines the primary and secondary firing sequence.
- Hold
- AltHold
- These define the refiring loop. A_ReFire jumps to these states when it determines that the weapon should continue firing. If these states are not defined they will default to the Fire/AltFire states. However, if a weapon inherits from an existing weapon these states will be defined and might need to be overridden!
- Flash
- AltFlash
- Defines the flash state. Flash animations run parallel to the normal firing animation and are triggered by calling A_GunFlash.
Weapons also allow a second keyword in the frame definition, offset, that is placed right after bright (if present) and just before the ACS special or DECORATE function being called. The keyword requires two parameters, x and y, in parentheses. The sprite's own offset is ignored when you specify offset this way.
- x sets the weapon sprite's horizontal offset across the screen. 0 means the weapon is centered, positive values shift the weapon to the right, and negative values shift the weapon to the left.
- y sets the weapon sprite's vertical offset down the screen. A value of 1 puts the top of the sprite very close to the center of the screen, while higher values cause the weapon to be drawn lower. A value of 0 does not center the weapon; instead, it snaps the bottom of the sprite to the bottom of the screen. Negative values will cause the sprite not to be drawn at all.
The offset keyword may not be used in conjunction with A_WeaponReady.
Note that the offset applies to all future frames until the weapon returns to the Ready state, and that using offset(0, 0) does not manually reset the weapon to its normal offsets. (This would actually indicate no change to offset) Currently there is no way to restore a weapon to default offset other than to return to the Ready state.
Example:
OFFG A 5 bright offset (24, 35) A_GunFlash
See also Creating new weapons.
Examples:
actor Karabiner98K : Weapon 10287
{
attacksound "wolf/karabiner"
decal BulletChip
inventory.pickupsound "misc/w_pkup"
inventory.pickupmessage "You got the Karabiner 98K!"
inventory.icon "KARWA0"
weapon.selectionorder 400
weapon.ammotype Magazine
weapon.ammogive 20
weapon.ammouse 2
states
{
Spawn:
KARW A -1
stop
Ready:
KARA A 1 A_WeaponReady
loop
Deselect:
KARA A 1 A_Lower
loop
Select:
KARA A 1 A_Raise
loop
Fire:
KARA A 4
KARA I 0 A_GunFlash
KARA I 5 A_FireBullets (6, 0, 16, 5, "BulletPuff")
KARA J 4
KARA H 8 A_PlaySound ("karabiner/close")
KARA A 5 A_ReFire
goto Ready
Flash:
KARA I 5 bright A_Light1
KARA J 4 bright A_Light2
KARA J 0 A_Light0
stop
}
}
DECORATE definition
Actor Weapon : Inventory native { Inventory.PickupSound "misc/w_pkup" Weapon.DefaultKickback States { LightDone: SHTG E 0 A_Light0 Stop } }

