Defines the cw.attribute library, the registry of character attribute definitions.

An attribute is created with cw.attribute:New, given a name, maximum, description and so on, and registered; cw.attribute:FindByID finds one by index, unique ID or name. The attribute values of players are handled by cw.attributes.

Summary

Methods

Finds an attribute by index, unique ID or part of its name.
GetAll()shared
Returns the registered attributes keyed by unique ID.
Returns the registered attributes keyed by their numeric index.
New(name)shared
Creates a new, unregistered attribute object.
Registers an attribute and returns its unique ID.

Methods

cw.attribute:FindByID(identifier)

shared gamemodes/catwork/gamemode/core/libraries/sh_attribute.lua:99

Finds an attribute by index, unique ID or part of its name.

Exact index and unique ID matches win. Otherwise the attribute with the shortest name that contains identifier (case-insensitive, as plain text) is returned.

Parameters

  • identifier Any Numeric index, unique ID or part of the name

Returns

  • Attribute The attribute, or nil if none matches

Returns the registered attributes keyed by unique ID.

Returns

  • Map<Attribute> Attributes keyed by unique ID

Returns the registered attributes keyed by their numeric index.

Returns

Creates a new, unregistered attribute object.

Set its fields (name, maximum, uniqueID, description, category, image...) and pass it to cw.attribute:Register.

local ATTRIBUTE = cw.attribute:New()
  ATTRIBUTE.name = '#Attribute_Cloth'
  ATTRIBUTE.maximum = 100
  ATTRIBUTE.uniqueID = 'cloth'
ATB_CLOTH = cw.attribute:Register(ATTRIBUTE)

Parameters

  • name String optional, defaults to 'Unknown' Display name of the attribute

Returns

  • Attribute The new attribute object

cw.attribute:Register(attribute)

shared gamemodes/catwork/gamemode/core/libraries/sh_attribute.lua:69

Registers an attribute and returns its unique ID.

The unique ID defaults to the lowercased name with whitespace replaced by underscores, and the category defaults to #Attributes. The index is a short CRC of the name. A progress cache is created for every value from -maximum to maximum, so maximum must be set. On the server the attribute's image (if any) is added to the client download list as a PNG material.

Parameters

Returns

  • String The attribute's unique ID

Defined in