LuaAPI/types

From The Battle for Wesnoth Wiki

Race

This represents a possible unit race. It has the following attributes:

  • race.descriptiontranslatable string

The description of the race, for showing to players.

  • race.nametranslatable string
  • race.plural_nametranslatable string

The name of the race, for showing to players.

  • race.num_traitsnumber

The number of random traits given to units of this race.

  • race.ignore_global_traitsboolean

Whether this race can receive the global traits.

  • race.undead_variationstring

The variation to transform this race to if killed by a plague attack.

  • race.traitstrait list

The traits available to this race. Includes global traits if available. You can access specific traits by their ID, and the full trait definition is included.

  • race.male_name_genname generator
  • race.female_name_genname generator

The name generators for this race. These are callable userdatas that return a random name each time, equivalent to the one created by wesnoth.name_generator.

  • race.__cfgconfig

The entire race definition as raw WML.

Unit Type

This represents a type of unit in the game, rather than a specific instance of a unit. It has the following attributes:

  • unit_type.nametranslatable string

The name of the unit type, for displaying to the player.

  • unit_type.idstring

The unit's ID.

  • unit_type.racestring

The ID of the unit's race. To get the actual race object, use this to look it up in wesnoth.races.

  • unit_type.alignmentalignment

The unit's alignment.

  • unit_type.imageimage string
  • unit_type.iconimage string
  • unit_type.profileimage string
  • unit_type.small_profileimage string

Various images used to represent the unit.

  • unit_type.max_hitpointsnumber
  • unit_type.max_movesnumber
  • unit_type.max_experiencenumber
  • unit_type.costnumber
  • unit_type.levelnumber
  • unit_type.recall_costnumber

Various stats of the unit type.

  • unit_type.advances_tolist of strings

A list of unit type IDs that this unit can advance to.

  • unit_type.advances_fromlist of strings

A list of unit type IDs that can advance to this unit.

  • unit_type.traitstable

A table of the traits that this unit type can get. The key is the trait ID and the value is the trait's full definition as a config.

  • unit_type.abilitieslist of strings

A list of abilities that this unit type possesses. This is only the abilities' IDs, not their full definition.

  • unit_type.attacksattack list

A list of weapons that this unit type possesses. This list can be indexed as an array, but you can also look up an attack by its ID (name field). Each attack is a weapon userdata.

  • unit_type.variationsvariation list

Returns a list of unit type userdata representing possible variations of this unit, including gender variations. You can look up specific variations by their ID. Male and female variations have the ID male or female.

  • unit_type.__cfgconfig

Returns the full unit type definition as raw WML. This can be used if you need something that's not directly supported.

Weapon

This represents a single attack on a unit or unit type; it can also exist as an orphaned attack not attached to either a unit or unit type. It has the following attributes:

  • weapon.read_onlyboolean

Indicates whether you can write to the attributes of this attack. It will be true when getting an attack from a unit type userdata.

  • weapon.descriptiontranslatable string

The attack's name, for displaying to the player.

  • weapon.namestring

The attack's ID.

  • weapon.typestring

The attack's damage type.

  • weapon.iconimage string

The attack's icon.

  • weapon.damagenumber
  • weapon.rangestring
  • weapon.numbernumber
  • weapon.movement_usednumber
  • (Version 1.17.13 and later only) weapon.attacks_usednumber

Basic stats of the attack.

  • weapon.attack_weightnumber
  • weapon.defense_weightnumber

The attack's weighting values.

  • weapon.accuracynumber
  • weapon.parrynumber

The defense modifications of the attack.

The attack's distance requirement between attacker and defender.

  • weapon.specialslist of configs

The special abilities of this attack.

  • weapon:matches(filter) → boolean

Tests if this attack matches the given StandardWeaponFilter.

  • weapon.__cfgconfig

The entire attack as raw WML

See Also

  • translatable strings - a string that will be translated by the engine.
  • vconfig - a WML object that automatically substitutes variables on the fly.
  • unit - represents a reference to Wesnoth unit on the map, on the recall list, or private to Lua.
  • side - represents a single side (player) in the game.
  • widget - represents a GUI2 widget.
  • map - represents the game map.
  • hex - represents a single hex on the map.
This page was last edited on 19 September 2024, at 00:58.