Topic api

3D Armor API

Tables

ArmorDef Armor definition table used for registering armor.
ArmorDef.groups Groups table.
ArmorDef.armor_groups Armor groups table.
ArmorDef.damage_groups Damage groups table.

Methods

armor:register_armor (name, def) Registers a new armor item.
armor:register_armor_group (group, base) Registers a new armor group.
armor:run_callbacks (callback, player, index, stack) Runs callbacks.
armor:update_player_visuals (player) Updates visuals.
armor:set_player_armor (player) Sets player's armor attributes.
armor:punch (player, hitter[, time_from_last_punch[, tool_capabilities]]) Action when armor is punched.
armor:damage (player, index, stack, use) Action when armor is damaged.
armor:get_weared_armor_elements (player) Get elements of equipped armor.
armor:equip (player, itemstack) Equips a piece of armor to a player.
armor:unequip (player, armor_element) Unequips a piece of armor from a player.
armor:remove_all (player) Removes all armor worn by player.
armor:get_player_skin (name) Retrieves player's current skin.
armor:update_skin (name) Updates skin.
armor:add_preview (preview) Adds preview for armor inventory.
armor:get_preview (name) Retrieves preview for armor inventory.
armor:get_armor_formspec (name[, listring]) Retrieves armor formspec.
armor:get_element (item_name) Retrieves element.
armor:serialize_inventory_list (list) Serializes armor inventory.
armor:deserialize_inventory_list (list_string) Deserializes armor inventory.
armor:load_armor_inventory (player) Loads armor inventory.
armor:save_armor_inventory (player) Saves armor inventory.
armor:update_inventory (player) Updates inventory.
armor:set_inventory_stack (player, i, stack) Sets inventory stack.
armor:get_valid_player (player, msg) Checks for a player that can use armor.
armor.drop_armor (pos, stack) Drops armor item at given position.
armor.set_skin_mod (mod) Allows skin mod to be set manually.

Armor Callbacks Registration

armor:register_on_update (func) Registers a callback for when player visuals are update.
armor:register_on_equip (func) Registers a callback for when armor is equipped.
armor:register_on_unequip (func) Registers a callback for when armor is unequipped.
armor:register_on_damage (func) Registers a callback for when armor is damaged.
armor:register_on_destroy (func) Registers a callback for when armor is destroyed.


Tables

ArmorDef
Armor definition table used for registering armor.

Fields:

See also:

Usage:

    local def = {
       description = "Wood Helmet",
       inventory_image = "3d_armor_inv_helmet_wood.png",
       groups = {armor_head=1, armor_heal=0, armor_use=2000, flammable=1},
       armor_groups = {fleshy=5},
       damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1},
     }
ArmorDef.groups
Groups table.

General groups defining item behavior.

Some commonly used groups: armor_<type>, armor_heal, armor_use

Fields:

  • armor_type int The armor type. "head", "torso", "hands", "shield", etc. (Note: replace "type" with actual type).
  • armor_heal int Healing value of armor when equipped.
  • armor_use int Amount of uses/damage before armor "breaks".

See also:

Usage:

    groups = {
       armor_head = 1,
       armor_heal = 5,
       armor_use = 2000,
       flammable = 1,
     }
ArmorDef.armor_groups
Armor groups table.

Groups that this item is effective against when taking damage.

Some commonly used groups: fleshy

Usage:

    armor_groups = {
       fleshy = 5,
     }
ArmorDef.damage_groups
Damage groups table.

Groups that this item is effective on when used as a weapon/tool.

Some commonly used groups: cracky, snappy, choppy, crumbly, level

See also:

Usage:

    damage_groups = {
       cracky = 3,
       snappy = 2,
       choppy = 3,
       crumbly = 2,
       level = 1,
     }

Methods

armor:register_armor (name, def)
Registers a new armor item.

Parameters:

  • name string Armor item technical name (ex: "3d_armor:helmet_gold").
  • def ArmorDef Armor definition table.

Usage:

    armor:register_armor("3d_armor:helmet_wood", {
       description = "Wood Helmet",
       inventory_image = "3d_armor_inv_helmet_wood.png",
       groups = {armor_head=1, armor_heal=0, armor_use=2000, flammable=1},
       armor_groups = {fleshy=5},
       damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1},
     })
armor:register_armor_group (group, base)
Registers a new armor group.

Parameters:

  • group string Group ID.
  • base int Base armor value.
armor:run_callbacks (callback, player, index, stack)
Runs callbacks.

Parameters:

  • callback function Function to execute.
  • player ObjectRef First parameter passed to callback.
  • index int Second parameter passed to callback.
  • stack ItemStack Callback owner.
armor:update_player_visuals (player)
Updates visuals.

Parameters:

armor:set_player_armor (player)
Sets player's armor attributes.

Parameters:

armor:punch (player, hitter[, time_from_last_punch[, tool_capabilities]])
Action when armor is punched.

Parameters:

armor:damage (player, index, stack, use)
Action when armor is damaged.

Parameters:

  • player ObjectRef
  • index int Inventory index where armor is equipped.
  • stack ItemStack Armor item receiving damaged.
  • use int Amount of wear to add to armor item.
armor:get_weared_armor_elements (player)
Get elements of equipped armor.

Parameters:

Returns:

    table List of equipped armors.
armor:equip (player, itemstack)
Equips a piece of armor to a player.

Parameters:

  • player ObjectRef Player to whom item is equipped.
  • itemstack ItemStack Armor item to be equipped.

Returns:

    ItemStack Leftover item stack.
armor:unequip (player, armor_element)
Unequips a piece of armor from a player.

Parameters:

  • player ObjectRef Player from whom item is removed.
  • armor_element string Armor type identifier associated with the item to be removed ("head", "torso", "hands", "shield", "legs", "feet", etc.).
armor:remove_all (player)
Removes all armor worn by player.

Parameters:

armor:get_player_skin (name)
Retrieves player's current skin.

Parameters:

Returns:

    string Skin filename.
armor:update_skin (name)
Updates skin.

Parameters:

armor:add_preview (preview)
Adds preview for armor inventory.

Parameters:

  • preview string Preview image filename.
armor:get_preview (name)
Retrieves preview for armor inventory.

Parameters:

Returns:

    string Preview image filename.
armor:get_armor_formspec (name[, listring])
Retrieves armor formspec.

Parameters:

  • name string Player name.
  • listring bool Use listring formspec element (default: false). (optional)

Returns:

    string Formspec formatted string.
armor:get_element (item_name)
Retrieves element.

Parameters:

Returns:

    Armor element.
armor:serialize_inventory_list (list)
Serializes armor inventory.

Parameters:

  • list table Inventory contents.

Returns:

    string
armor:deserialize_inventory_list (list_string)
Deserializes armor inventory.

Parameters:

  • list_string string Serialized inventory contents.

Returns:

    table
armor:load_armor_inventory (player)
Loads armor inventory.

Parameters:

Returns:

    bool
armor:save_armor_inventory (player)
Saves armor inventory.

Inventory is stored in PlayerMetaRef string "3d_armor_inventory".

Parameters:

armor:update_inventory (player)
Updates inventory.

DEPRECATED: Legacy inventory support.

Parameters:

  • player
armor:set_inventory_stack (player, i, stack)
Sets inventory stack.

Parameters:

armor:get_valid_player (player, msg)
Checks for a player that can use armor.

Parameters:

Returns:

    list Player name & armor inventory.

Usage:

    local name, inv = armor:get_valid_player(player, "[equip]")
armor.drop_armor (pos, stack)
Drops armor item at given position.

Parameters:

armor.set_skin_mod (mod)
Allows skin mod to be set manually.

Useful for skin mod forks that do not use the same name.

Parameters:

  • mod string Name of skin mod. Recognized names are "simple_skins", "u_skins", & "wardrobe".

Armor Callbacks Registration

armor:register_on_update (func)
Registers a callback for when player visuals are update.

Parameters:

  • func function Function to be executed.

See also:

Usage:

    armor:register_on_update(function(player, index, stack)
       -- code to execute
     end)
armor:register_on_equip (func)
Registers a callback for when armor is equipped.

Parameters:

  • func function Function to be executed.

Usage:

    armor:register_on_equip(function(player, index, stack)
       -- code to execute
     end)
armor:register_on_unequip (func)
Registers a callback for when armor is unequipped.

Parameters:

  • func function Function to be executed.

Usage:

    armor:register_on_unequip(function(player, index, stack)
       -- code to execute
     end)
armor:register_on_damage (func)
Registers a callback for when armor is damaged.

Parameters:

  • func function Function to be executed.

See also:

Usage:

    armor:register_on_damage(function(player, index, stack)
       -- code to execute
     end)
armor:register_on_destroy (func)
Registers a callback for when armor is destroyed.

Parameters:

  • func function Function to be executed.

See also:

Usage:

    armor:register_on_destroy(function(player, index, stack)
       -- code to execute
     end)
generated by LDoc 1.4.6-antum-dev Last updated 2024-06-25 04:37:27