skills misc - MSUTeam/MSU GitHub Wiki

Ranged Tooltip

<skill>.getRangedTooltip( _tooltip = null )
_tooltip is an array

MSU provides a very convenient function for automatically generating range and accuracy information for ranged skills in their tooltips. This way, all you have to do is define the following two fields in the skill's m table:

  • AdditionalAccuracy
  • AdditionalHitChance

If _tooltip is passed, the function will return _tooltip with the ranged information added to the array. Otherwise it will create a new array and return a new tooltip array with just the ranged info below.

The tooltip generated then, automatically, has information such as:

  • "has a range of X tiles on even ground, Y if shooting down hill"
  • "has XX% chance to hit and YY% per tile of distance"

X is this.m.MaxRange
Y can be one of the strings "more", "or", "less" depending on if this.m.MaxRangeBonus is >0, ==0, <0 respectively.
XX is this.m.AdditionalAccuracy
YY is this.m.AdditionalHitChance

MSU also causes Ranged Skills to show up in the Hit Factors tooltip if they have a non-zero AdditionalAccuracy, as long as the MSU Expanded Skill Tooltips setting is enabled.

Example

In your ranged skill, you can generate all the proper info about hit chance and range by doing the following:

function getTooltip()
{
    return this.getRangedTooltip(this.getDefaultTooltip());
}

// or

function getTooltip()
{
    local tooltip = this.getDefaultTooltip();

    // add some more info to tooltip

    // then:
    tooltip.extend(this.getRangedTooltip());

    // then add some more info to tooltip as necessary
    
    return tooltip;
}

AI Behavior

<skill>.m.AIBehaviorID = ""
// The value must be the ID specified in the ai behavior script file

This allows specifiying an AI behavior within the skill file via its ID, which will then be automatically added to the character when this skill is added to that character. To be able to correspond the ID to the script, ::MSU.AI.BehaviorIDToScriptMap is created on game launch. The vanilla IDs are found under scripts/config/ai.nut

Example

// Inside a skill file
function create()
{
    // ...
    this.m.AIBehaviorID = this.Const.AI.Behavior.ID.Rally; // ID of ai_rally
    // ...
}

Get skills by function

<skill_container>.getSkillsByFunction( _function )
// _function is a function that accepts a single argument and must return a boolean

Returns an array containing all the skills in the skill container for which _function returns true when the skill is passed as a parameter to _function.

Example

local ids = [ "some_id", "some_id_2", "some_id_3"];

local skills = this.getContainer().getSkillsByFunction(@(skill) ids.find(skill.getID()) != null);

// `skills` contains all the skills from the container whose id is present in the `ids` array

Type mutators and accessors

MSU overwrites the vanilla skill.isType function to add additional functionality. In particular, this allows passing multiple types to the function separated by the binary operator |.

<skill>.isType( _t, _any = true, _only = false )
// _t is an entry in the ::Const.SkillType table
// _any and _only are booleans

This allows passing multiple types as the _t argument e.g. ::Const.SkillType.Active | ::Const.SkillType.Perk. If _any is true then the function returns true if the skill has at least one of the passed types. If _any is false then the function returns true if the skill has all of the passed types. Then the _only parameter can be used to further narrow down the results. If _only is true then the function returns true if the skill has no types other than the ones passed in _t. Returns false if these conditions are not met.

MSU also adds additional functions to add, set and remove SkillTypes from skills. These functions also support passing multiple types into _t separated by the binary operator |.

<skill>.addType( _t )
// _t is an entry in the ::Const.SkillType table

Adds the type _t to the skill's Type field.

<skill>.setType( _t )
// _t is an entry in the ::Const.SkillType table

Sets the Type field of the skill to _t.

<skill>.removeType( _t )
// _t is an entry in the ::Const.SkillType table

Removes the type _t from the skill's Type. Throws an MSU KeyNotFound exception if the skill does not have that type.

Injuries

MSU adds a system to exclude certain sets of injuries from certain entities easily. MSU comes with the following sets of injuries built-in (only include vanilla injuries):

  • Hand
  • Arm
  • Foot
  • Leg
  • Face
  • Head

Create/Expand a Set of Excluded Injuries

::Const.Injury.ExcludedInjuries.add( _name, _injuries, _include = null )
// _name is a string
// _injuries and _include are arrays

_name will become a key in ::Const.Injury.ExcludedInjuries.
_injuries contains skillIDs of injuries to add.
_include contains keys in ::Const.Injury.ExcludedInjuries. If _include is null then it defaults to an empty array.

Creates an entry in the ::Const.Injury.ExcludedInjuries table with _name as key and { Injuries = _injuries, Include = _include } as value. The slots passed in the _include array must already exist.

If the key _name already exists in ::Const.Injury.ExcludedInjuries then its associated Injuries and Include are expanded to include _injuries and _include.

Example

::Const.Injury.ExcludedInjuries.add(
    “Hand”,
    [
        “injury.fractured_hand”,
        “injury.crushed_finger”
    ]
);

::Const.Injury.ExcludedInjuries.add(
    “Arm”, 
    [
        “injury.fractured_elbow”
    ],
    [
        ::Const.Injury.ExcludedInjuries.Hand
    ]
);

Get a Set of Excluded Injuries

::Const.Injury.ExcludedInjuries.get( _injuries )
// _injuries is a key in ::Const.Injury.ExcludedInjuries

Returns an array containing the skill IDs of all the injuries associated with that slot. The array is expanded using the all the sets of injuries defined in the associated Include of that set.

Example

::Const.Injury.ExcludedInjuries.add(
    “Hand”,
    [
        “injury.fractured_hand”,
        “injury.crushed_finger”
    ]
);

::Const.Injury.ExcludedInjuries.add(
    “Arm”, 
    [
        “injury.fractured_elbow”
    ],
    [
        ::Const.Injury.ExcludedInjuries.Hand
    ]
);

local result = ::Const.Injury.ExcludedInjuries.get(::Const.Injury.ExcludedInjuries.Arm);

In this example result will be equal to ["injury.fractured_elbow", “injury.fractured_hand”, “injury.crushed_finger”].

Add Excluded Injuries to Actor

<actor>.addExcludedInjuries( _injuries )
// _injuries is a key in ::Const.Injury.ExcludedInjuries

Adds all the injuries returned from ::Const.Injury.ExcludedInjuries.get(injuries) to the this.m.ExcludedInjuries array of <actor>. Entries already present in this.m.ExcludedInjuries are not duplicated.

Example

In order to prevent Serpents from gaining Arm related injuries, hook the onInit function of serpent and add the following line of code:

this.addExcludedInjuries(::Const.Injury.ExcludedInjuries.Arm);
⚠️ **GitHub.com Fallback** ⚠️