Skip to content

Custom Mechanics (skfunction)

Yevhen Harasymchuk edited this page Jul 29, 2026 · 1 revision

The skfunction mechanic calls a global Skript function directly from a MythicMobs skill configuration. It can pass MythicMobs skill context, the selected target, and custom values declared in the mechanic.

Basic Syntax

Define the mechanic in a MythicMobs skills file:

MySkill:
  Skills:
  - skfunction{name=my_skript_function} @target ~onAttack

name (or its short alias n) is required and must be the exact name of a loaded global Skript function.

Define the function in a .sk file:

function my_skript_function(data: skilldata, target: entity, loc: location) :: boolean:
    set {_caster} to caster of {_data}
    broadcast "The mob %{_caster}% is casting a skill!"
    return true

Automatically Supplied Parameters

The addon recognizes the following parameter types and supplies them automatically:

Skript type Value
skilldata Metadata for the current MythicMobs skill execution.
entity and subtypes The entity selected by an entity targeter such as @self or @target.
location The location selected by a location targeter.

Their order is not fixed. You can omit types that the function does not need:

function only_target(target: entity):
    broadcast "Selected entity: %{_target}%"

You can declare multiple automatically supplied parameters of the same type. Each matching parameter receives the current value. Concrete entity subtypes are validated before the function runs:

function repeated_targets(first: player, second: player, data: skilldata, same_data: skilldata):
    send "Both player arguments refer to the selected player." to {_first}

If the selected entity is not compatible with a declared subtype such as player, the mechanic returns INVALID_CONFIG instead of passing an invalid value to Skript.

The mechanic is forced onto the synchronous server thread before it invokes Skript, so functions may safely interact with normal Bukkit/Skript state.

When an entity-targeted cast invokes the function, a declared location parameter receives no values. Likewise, a location-targeted or no-target cast provides no values for a declared entity parameter. Check whether an argument is set before using it when the same function supports different targeter kinds.

Custom Configuration Parameters

Any additional function parameter is matched to a field inside skfunction{...} by its parameter name. The names must match:

ConfiguredSkill:
  Skills:
  - skfunction{name=configured_skill;message="Hello";amount=3;enabled=true} @self
function configured_skill(message: text, amount: number, enabled: boolean, target: entity):
    if {_enabled} is true:
        broadcast "%{_message}% (amount: %{_amount}%)"

Supported configuration-backed types:

Skript type Example
text message="Hello"
number amount=3.5
boolean enabled=true
colordata color="#345634"

Custom parameters may appear before, after, or between the automatically supplied parameters. Multiple custom parameters may use the same type because each value is matched independently by parameter name.

If a required field is missing, has an unsupported parameter type, or cannot be converted, the mechanic returns INVALID_CONFIG and writes a warning to the server console instead of invoking the function.

Passing Colors

Use colordata to pass an exact RGB color from MythicMobs:

ColorHeldItem:
  Skills:
  - skfunction{name=color_item_piece_in_hand;color="#345634"} @self
function color_item_piece_in_hand(color: colordata, target: entity) :: boolean:
    # {_color} is compatible with Skript expressions that accept a color.
    # Apply {_color} to the leather armor or other colorable item here.
    return true

Accepted colordata formats:

Format Example
Six-digit RGB hexadecimal #345634
Eight-digit ARGB hexadecimal #FF345634
Decimal RGB channels 52,86,52
Bukkit dye-color name RED, LIGHT_BLUE

RGB channels must be between 0 and 255. Dye-color names are case-insensitive.

MythicMobs Placeholders

Custom values are stored as MythicMobs placeholder strings and resolved each time the mechanic is cast. This allows values to depend on the caster, target, skill variables, or another installed placeholder provider:

DynamicColor:
  Skills:
  - skfunction{name=color_item_piece_in_hand;color=<caster.var.armor_color>} @self

The resolved placeholder value must still match the target Skript type. For example, a colordata parameter must resolve to a supported color format.

SkillData Expressions

The following expressions expose information from a skilldata argument:

  • caster of {_data}: Returns the entity that cast the skill.
  • cause of {_data}: Returns the internal trigger cause.
  • trigger of {_data}: Returns the entity that triggered the skill.
  • entitytargets of {_data}: Returns the current entity targets.
  • locationtargets of {_data}: Returns the current location targets.
  • origin of {_data}: Returns the skill origin.
  • power of {_data}: Returns the skill power as a float.

Loading and Return Values

The Skript function must already be loaded when MythicMobs constructs the mechanic. If the console reports Can't find function, load or reload the Skript file first and then reload the relevant MythicMobs configuration.

A function may declare a return value for its own Skript logic, but the current skfunction mechanic does not use that value to determine its MythicMobs result. A successfully invoked function produces SUCCESS; missing functions, incompatible target subtypes, and configuration conversion failures produce INVALID_CONFIG.

Clone this wiki locally