Modding:Item

From DoomRL Wiki

Revision as of 01:51, 5 September 2011 by Game Hunter (Talk | contribs)

Jump to: navigation, search

DoomRL has many kinds of items. Weapons, powerups, levers, and other things are all items. Items inherit from the Thing class which handles some basic properties in common with beings.

Contents

Prototype

New items are created from item prototypes. Think of an item prototype as a recipe for creating new items. There can be multiple pistols, but they all came from the same prototype. Prototypes are declared by passing a table with the desired properties to the Items function. The available properties depend on the item type. Engine hooks may also be included in the prototype. Mostly, the prototype's properties just describe items' initial properties (occasionally with different names). Items' properties can also mostly be changed after they are instantiated. Required fields are underlined. Sometimes required fields can safely be omitted, but this will generate a message in the log file. All item prototypes are stored in a global table called items. This table can be indexed by id or nid.

Item Prototype
string name This is the item's name.
string id This is the item's sid. It must be distinct from other string ids. (The numeric id is automatically generated and stored in the nid field of the prototype.) It defaults to the first word of the name in all lowercase.
integer list overlay This describes of color transformation of the item's sprite. It is only used in the graphical version. This will create overlay_red, overlay_blue, overlay_green, and overlay_alpha attributes for the prototype.
Color color This is the item's color. The default is LIGHTGRAY.
integer level This is an item generation parameter. The default is 0.
integer weight This is an item generation parameter.
integer sprite This is the item's sprite. This field is only relevant to the graphical version; use 0 for no sprite.
Item Flag list flags The flags in this list will automatically be included in the item's flag set. The default is an empty list. Some flags may be added automatically. The prototype will automatically be given a flagSet property containing the flags in set format.
ItemSet ID set If included, this item will belong to the given item set. This will modify the item's OnEquip and OnRemove hooks.
string firstmsg If included, this message will be displayed when the an item with this prototype is picked up for the first time. This will modify the item's OnFirstPickup hook.
integer slevel This property is unused.
string color_id For the purpose of custom color bindings, this id will be used for the item. Multiple items (like levers) can have the same color_id to prevent them from being distinguished.
integer res_bullet This is the item's res_bullet. The default is 0.
integer res_melee This is the item's res_melee. The default is 0.
integer res_shrapnel This is the item's res_shrapnel. The default is 0.
integer res_acid This is the item's res_acid. The default is 0.
integer res_fire This is the item's res_fire. The default is 0.
integer res_plasma This is the item's res_plasma. The default is 0.
ItemType type This is the item's itype. It also determines which other properties can be used in the prototype.

Armor or Boots

These are the fields used by ITEMTYPE_ARMOR and ITEMTYPE_BOOTS.

Armor or Boots Prototype
string desc This is the armor's description that is displayed in the inventory screen.
integer armor This is the armor's armor property.
integer durability This is the armor's maxdurability as well as its initial durability. The default is 100. (This should still be 100 for armors with no durability, as no durability is achieved by a flag.)
integer knockmod This is the armor's knockmod. The default is 0.
integer movemod This is the armor's movemod. The default is 0.
string ascii This is the armor's picture. It should be a length one string. The default is "[" for body armor and ";" for boots.

Consumable

These are the fields used by ITEMTYPE_PACK. This includes mods and relics.

Consumable Prototype
string desc This is the pack's description that is displayed in the inventory screen.
function OnUse Packs must provide an OnUse hook.
string ascii This is the pack's picture. It should be a length one string. The default is "+".

Powerups

These are the fields used by ITEMTYPE_POWER.

Powerups Prototype
function OnPickup Powerups must provide an OnPickup hook.
string ascii This is the powerup's picture. It should be a length one string. The default is "^".

Ammo

These are the fields used by ITEMTYPE_AMMO.

Ammo Prototype
string desc This is the ammo's description that is displayed in the inventory screen.
integer ammo This is the ammo's initial ammo property.
integer ammomax This is the ammo's ammomax property.
string ascii This is the ammo's picture. It should be a length one string. The default is "|".

Ammo Pack

These are the fields used by ITEMTYPE_AMMOPACK.

Ammo Pack Prototype
string desc This is the ammo pack's description that is displayed in the inventory screen.
integer ammo This is the ammo pack's initial ammo property.
integer ammomax This is the ammo pack's ammomax property.
string ammoID This is the ammo pack's ammoid property.
string ascii This is the ammo pack's picture. It should be a length one string. The default is "!".

Ranged Weapon

These fields are used by ITEMTYPE_RANGED.

Ranged Weapon Prototype
string desc This is the weapon's description that is displayed in the inventory screen.
string damage This should be a string like "2d4"; the weapon's damage_dice and damage_sides will be parsed from this.
DamageType damagetype This is the weapon's damagetype.
string group This is the weapon's group for purposes of kill counting. The used weapon groups are "weapon-melee", "weapon-pistol", "weapon-shotgun", "weapon-chain", "weapon-rocket", "weapon-plasma", and "weapon-bfg". The default is "weapon-other".
string ammoID This is the weapon's ammoID.
integer fire This is the weapon's usetime. The default is 10.
integer acc This is the weapon's acc. The default is 0.
integer ammomax This is the weapon's ammomax and the weapon's initial ammo.
integer radius This is the weapon's blastradius. The default is 0.
integer shots This is the weapon's shots. The default is 0 (which will still give one shot).
integer shotcost This is the weapon's shotcost. The default is 0 (which will still require one ammo).
AltFire altfire This is the weapon's altfire. The default is ALT_NONE.
AltReload altreload This is the weapon's altreload. The default is RELOAD_NONE.
string altfirename This is the name the game uses for the weapon's alternate fire mode. Most of the AltFire constants provide defaults.
string altreloadname This is the name the game uses for the weapon's alternate reload mode. Most of the AltReload constants provide defaults.
Missile ID overcharge This field is currently unused.
Missile ID or Missile Prototype missile This is the weapon's missile. (It will be translated into an nid. To use a shotgun missile, the weapon must have the IF_SHOTGUN flag.) If this property is a table, it will be used to declare a new missile with the same id as the weapon.
string ascii This is the weapon's picture. It should be a length one string. The default is "}".

Natural Ranged Weapon

These fields are used by ITEMTYPE_NRANGED. Natural ranged weapons are usually defined inline in a being definition.

Natural Ranged Weapon Prototype
string damage This should be a string like "2d4"; the weapon's damage_dice and damage_sides will be parsed from this.
DamageType damagetype This is the weapon's damagetype.
string group This is the weapon's group for purposes of kill counting. The used weapon groups are "weapon-melee", "weapon-pistol", "weapon-shotgun", "weapon-chain", "weapon-rocket", "weapon-plasma", and "weapon-bfg". The default is "weapon-other".
integer fire This is the weapon's usetime. The default is 10.
integer acc This is the weapon's acc. The default is 0.
integer radius This is the weapon's blastradius. The default is 0.
integer shots This is the weapon's shots. The default is 0 (which will still give one shot).
string soundID The soundID will be used to look up sounds if there are no sounds defined for the weapon's actual id. By convention, a natural weapon's soundID is the usual wielder's id.
Missile ID or Missile Prototype missile This is the weapon's missile. (It will be translated into an nid. To use a shotgun missile, the weapon must have the IF_SHOTGUN flag.) If this property is a table, it will be used to declare a new missile with the same id as the weapon.
string ascii This is the weapon's picture. It should be a length one string. The default is "?".

Melee Weapon

These fields are used by ITEMTYPE_MELEE.

Melee Weapon Prototype
string desc This is the weapon's description that is displayed in the inventory screen.
string damage This should be a string like "2d4"; the weapon's damage_dice and damage_sides will be parsed from this.
DamageType damagetype This is the weapon's damagetype.
string group This is the weapon's group for purposes of kill counting. The used weapon groups are "weapon-melee", "weapon-pistol", "weapon-shotgun", "weapon-chain", "weapon-rocket", "weapon-plasma", and "weapon-bfg". The default is "weapon-other".
integer fire This is the weapon's usetime. The default is 10.
integer acc This is the weapon's acc. The default is 0.
integer shotcost This is the weapon's shotcost. The default is 0 (which will still require one ammo).
AltFire altfire This is the weapon's altfire. The default is ALT_NONE.
string altfirename This is the name the game uses for the weapon's alternate fire mode. Most of the AltFire constants provide defaults.
Missile ID or Missile Prototype missile This is the missile used if for the throw alternate fire mode.
string ascii This is the weapon's picture. It should be a length one string. The default is "\".

Lever

These fields are used by ITEMTYPE_LEVER. DoomRL levers usually also have a target_area custom property.

Lever Prototype
string desc This is the full description of the lever used if the player has BF_LEVERSENSE2.
string good This is the qualitative description of the lever used if the player has BF_LEVERSENSE1. By convention, this should be "beneficial", "neutral", or "dangerous".
integer fullchance The level generation code will set the lever's target_area to the full map fullchance percent of the time. The default is 0. (To be fair, the level generation code won't generate custom levers.)
string warning This message will be displayed by the level generation code if the fullchance roll succeeds.
null color_id This field is required for levers. By convention, it is set to "lever".
null soundID If the particular lever doesn't have sound bindings, the game will use the sound ID to look for sound bindings. By default, this is "lever".
string ascii This is the lever's picture. It should be a length one string. The default is "&".

Teleporter

These fields are used by ITEMTYPE_TELE. The built-in teleport item has a custom target property. This can be set to any coord to control the destination.

Teleporter Prototype
function OnEnter This hook is required for teleporters.
string ascii This is the teleporter's picture. It should be a length one string. The default is "*".

Engine Hooks

These hooks can give greater flexibility for how items work. For some item types, a hook provides the primary function. Sometimes, the engine will add to explicitly defined hooks, but this shouldn't interfere with a modder's use of the hooks. However, modders should be careful when changing hooks.

Item Hooks
void OnCreate(Item self)
void OnPickup(Item self, Being getter)
void OnFirstPickup(Item self, Being getter)
boolean OnPickupCheck(Item self, Being getter)
boolean OnUse(Item self, Being user)
boolean OnUseCheck(Item self, Being user)
boolean OnReload(Item self, Being reloader)
boolean OnAltFire(Item self, Being firer)
void OnAltReload(Item self, Being reloader)
void OnEquip(Item self, Being equipper)
void OnEquipTick(Item self, Being wearer)
boolean OnEquipCheck(Item self, Being equipper)
void OnRemove(Item self, Being wearer)
void OnKill(Item self, Being dier, Being wearer)
boolean OnHitBeing(Item self, Being attacker, Being target)
void OnEnter(Item self, Being enterer)
boolean OnFire(Item self, Being firer)
void OnFired(Item self, Being firer)

OnCreate(Item self)
This hook is called when the item is created. For ammo, beware: the game creates and destroys ammo items liberally as a normal part of ammo management.

OnPickup(Item self, Being getter)
When an item is picked up, this hook is called with the being that is picking the item up. This is most commonly used to implement powerups.

OnFirstPickup(Item self, Being getter)
When an item with a given id is picked up for the first time, the function is called. This only works for items that go into the inventory.

OnPickupCheck(Item self, Being getter) → boolean
When a being tries to pick up an item, this function is called with the being that is trying to pick it up. If the return value is true, then the being is allowed to pick the item up, otherwise the being can't. For the player, both cases include the item in the player's previously found items. (This can affect OnFirstPickup.)

OnUse(Item self, Being user) → boolean
This hook is called when levers are used and when packs are used with the being that it using the item. For packs, if the return value is true, the item is consumed, otherwise it is left in the inventory. For levers, the return value is ignored and it is safe not to have a return value.

OnUseCheck(Item self, Being user) → boolean
This hook is called called before OnUse for levers and packs. If the return value is false, then the being can't use the item, otherwise it can. For levers, this can control whether the lever statistic is increased.

OnReload(Item self, Being reloader) → boolean
If it is declared, this hook is called when a weapon is reloaded. If the return value is false, then the normal reload procedure is aborted. This can be used to prevent reloading or to implement a custom reloading mechanism (like for the Acid Spitter). If true is returned, the weapon is reloaded normally afterwards.

OnAltFire(Item self, Being firer) → boolean
This hook works exactly like the OnFire hook, except it is called when the weapon's alternate fire mode is used for weapons with ALT_SCRIPT altfire.

OnAltReload(Item self, Being reloader)
If the weapon's altreload is RELOAD_SCRIPT, then this hook is called with when the weapon's alternate reload mode is used.

OnEquip(Item self, Being equipper)
This hook is called when the item is equipped in any equipment slot. Due to a bug, equipper is the active being. This is always correct during normal play, but modders must be careful when manually equipping items with this hook.

OnEquipTick(Item self, Being wearer)
While this item is equipped in any slot (including the prepared slot), this function is called on each of the being's actions. (Despite the name, it probably won't be called on every tick; it depends on the being's speed.)

OnEquipCheck(Item self, Being equipper) → boolean
This function is called (before OnEquip) when the player tries to equip an item. If the return value is true, then the player is allowed to equip the item; otherwise the player isn't allowed to equip the item.

OnRemove(Item self, Being wearer)
This hook is called when a being unequips the item, or when the item is otherwise removed from the being's equipment. This includes armor being destroyed by damage. Like OnEquip, this is called with the active being which can cause problems especially if this hook is called for armor destruction.

OnKill(Item self, Being dier, Being wearer)
When a being dies, this hook is called on all of the active being's equipment. This includes the prepared slot. (Weapons can check what slot they are in inside of this hook.)

OnHitBeing(Item self, Being attacker, Being target) → boolean
For weapons with no blastradius, this hook is called whenever a being is hit with the weapon. This hook is called before applying damage. If the return value is true, damage is applied as usual. Otherwise, the damage phase is skipped.

OnEnter(Item self, Being enterer)
This function is called whenever a being enters a cell that has the item lying on the floor. For the player, this supresses the usual "There is an item lying here" message. This is used in DoomRL to implement teleports.

OnFire(Item self, Being firer) → boolean
This hook is called when a weapon is fired. This only works for normal firing, not alternative firing (see OnAltFire). This hook is called before a target is selected. If the return value is true, then the rest of the normal firing operation is aborted. If the return value is false, then it continues as usual.

OnFired(Item self, Being firer)
This hook is called after a weapon is fired. This is after the entire usual firing procedure including damage, etc. Currently, this only works for the player.

Properties

Items also have all the Thing properties in addition to those listed below. For items, the meaning of the resistance fields vary depending on the item type. For armor and boots, the resistances are applied only to attacks to the corresponding target. For other equipment, the resistance applies to all attacks. For non-equipment, the resistances aren't used. Also, some properties are only valid for armor, and some are only valid for weapons. For these purposes, armor are items with itype ITEMTYPE_ARMOR and ITEMTYPE_BOOTS and weapons are items with itype ITEMTYPE_AMMO, ITEMTYPE_MELEE, ITEMTYPE_NRANGED, ITEMTYPE_RANGED, and ITEMTYPE_AMMOPACK. Properties of the incorrect type are always indexable, but they may share a memory address with properties of the opposite type, so modders should only use this feature very carefully. The type of such properties is noted. Also, the meaning of many fields is slightly different depending on the itype; these differences are also described.

Item
ItemType itype This determines the basic features of the item. ITEMTYPE_NONE has no features; it can't be picked up or used. ITEMTYPE_RANGED can be picked up and wielded as a ranged weapon. ITEMTYPE_NRANGED is like ITEMTYPE_RANGED, but it isn't designed to exist on the map. ITEMTYPE_ARMOR can be picked up and equipped as armor. ITEMTYPE_MELEE can be picked up and wielded as a melee weapon. ITEMTYPE_AMMO is always a new ammo type that can be picked up and stacked. ITEMTYPE_PACK items can be picked up and used. ITEMTYPE_POWER items are consumed when they are picked up. ITEMTYPE_BOOTS can be picked up and worn as boots. ITEMTYPE_TELE have no special features, but by convention they interact with OnEnter. ITEMTYPE_LEVER have special description routines, and they can be used while on the floor. ITEMTYPE_AMMOPACK can be picked up and wielded in the prepared slot. They provide reloading benefits. While it is possible to change an item's itype, this should almost never be done. If it is done, care must be taken to account for overlapping weapon and armor properties.
Byte armor For armor and boots, this is the amount of protection provided at full durability. Weapons in the main slot may also provide a (universal) protection bonus with this field.
Word durability For armor and boots, this is the current amount of durability of the item. This property is armor-specific.
Word maxdurability For armor and boots, this is the maximum amount of durability. Most effects won't raise the durability above maxdurability. This property is armor-specific.
Integer movemod For armor and boots, this percentage movement speed modifier is applied while the item is equipped. This property is armor-specific.
Integer knockback For armor and boots, this percentage knockback modifier is applied while the item is equipped. This property is armor-specific.
Item ID ammoid This must always be a number id. For ranged weapons, this is the item id of the kind of ammo the weapon uses. For ammo packs, this is the kind of ammo provided by the pack. This property is weapon-specific.
Word ammo For ranged weapons, this is the amount of currently-loaded ammo. For ammo packs and ammo stacks, this is the amount of ammo inside. This property is weapon-specific.
Word ammomax For ranged weapons, this is the size of the magazine. For ammo stacks, this is the maximum stack size (unaffected by BF_BACKPACK). For ammo packs, this is the initial amount of ammo. This property is weapon-specific.
Word acc For ranged and melee weapons, this is an accuracy modifier applied to attacks with the weapon. This property is weapon-specific.
Word damage_sides For weapons, this is the number of dice rolled for damage (e.g. the X of XdY). This property is weapon-specific.
Word damage_dice For weapons, this is the number of sides on each die rolled for damage (e.g. the Y of XdY). This property is weapon-specific.
Integer damage_add For weapons, this is a flat bonus added to all damage rolls. This property is weapon-specific.
Missile ID missile This must always be a number id. For ranged weapons, this is the missile used by the weapon. For melee weapons, this is the missile used by the throw alternate fire mode (if any). This property is weapon-specific.
Byte blastradius This is the radius of the explosion caused by a ranged weapon. This should be 0 for weapons with no explosion. This property is weapon-specific.
Byte shots This is the number of shots fired by a rapid-fire ranged weapon. This should be 0 (not 1) for single-shot weapons. This property is weapon-specific.
Byte shotcost This is the amount of ammo consumed by each shot with a ranged weapon. This should be 0 (not 1) for weapons that take only one ammo per shot. This property is weapon-specific.
Byte reloadtime This is the number of 0.1s intervals it takes (without modifiers) to reload a ranged weapon. This property is weapon-specific.
Byte usetime This is the number of 0.1s intervals it takes (without modifiers) to fire/use a weapon. This property is weapon-specific.
DamageType damagetype This is the type of the damage caused by a weapon. This property is weapon-specific.
AltFire altfire This is the alternate fire mode of a weapon. For ALT_SCRIPT, the details depend on the OnAltFire hook. This property is weapon-specific.
AltReload altreload This is the alternate reload mode of a ranged weapon. For RELOAD_SCRIPT, the details depend on the OnAltReload hook. This property is weapon-specific.
string desc This is the string used to describe the item in the inventory list. For the description in the inventory sidebar, use .proto.desc. This property is read-only.
Item Prototype proto This is the item's prototype.

API

The Thing API can also be used with items.

Item Interface
Item item.new(Item ID id)
boolean Item:add_mod(string modletter)
boolean Item:can_mod(string modletter)
integer Item:get_mod(string modletter)
void Item:clear_mods()
boolean Item:is_damaged()
boolean Item:fix(integer amount)
table Item:get_mods()
boolean Item:can_overcharge()
boolean Item:check_mod_array(string nextmod, integer techbonus)

item.new(Item ID id) → Item
This returns a newly allocated item create from the specified prototype. This item doesn't exist in the game yet; it must be dropped on the level, added to an inventory, or equipped.

Item:add_mod(string modletter) → boolean
Adds a mod to the item's mod list and sets the IF_MODIFIED flag. This does not apply any affects of the mod, it is only a primitive operation for accessing the mod list. modletter should be a single uppercase letter representing the mod. This will check modding restrictions (as can_mod) and return true on success, false on failure.

Item:can_mod(string modletter) → boolean
Determines if the given mod can be added to the item. modletter should be a single uppercase letter representing the mod. This will always use the player's techbonus. It also accounts for limits on the number of mods of a given type and various modability item flags.

Item:get_mod(string modletter) → integer
Counts the number of the given mod that have already been added to the item. modletter should be a single uppercase letter representing the mod.

Item:clear_mods()
Clears the counts of all mods for the item. The does not undo the affects of the mods nor does it change any flags (including IF_MODIFIED).

Item:is_damaged() → boolean
This determines if the item's durability is less than its maxdurability. For items with IF_NOREPAIR, this function always returns false. (So, in effect this function determines if the item needs to be repaired.)

Item:fix(integer amount) → boolean
This will increase the item's durability by amount, respecting maxdurability. It returns true is the item is no longer is_damaged. amount is optional; by default the item is completely repaired.

Item:get_mods() → table
This will return a table that maps single character mod letters to the corresponding amount of mods that have been applied to the item. Mod letters that have not been applied are not included as keys.

Item:can_overcharge() → boolean
This will determine if the item can be overcharged. To be overcharged, an item can't already by overcharged (IF_DESTROY), and must be fully loaded. The ui part of overcharging is included. On success, IF_DESTROY and IF_NOUNLOAD are set, but other affects must be applied by the caller.

Item:check_mod_array(string nextmod, integer techbonus) → boolean
This will check if the mod indicated by nextmod (the single uppercase character representing the mod) could form an assembly (given the provided techbonus). If so, the assembly is created on the item (if the player confirms the ui message) with all associated side effects. Returns true only if the assembly is actually created.
Personal tools