Sharp Aion2 Lua SDK
API reference

defenseLua table

List skills and manage Auto Defense from Lua.

The defense table lists skills, manages Auto Defense rules, and delivers events to a loaded module. Use the Auto Defense menu to review saved rules. Actions are 1 evade, 2 parry, and 3 block. Phases are 0 start, 1 casting, 2 charging, and 3 channeling.

Skill catalog

defense.skills(first, count, search, job, language)

Parameters: first is a one-based match position (default 1); count is 1–100 (default 50); optional search is up to 128 bytes and matches names or IDs; job is -1 for monsters, 0 for all, or a supported player class number 1–8. Omit language to use the menu preference. Language indexes are 0 English, 1 Simplified Chinese, 2 Korean, 3 Russian, 4 Brazilian Portuguese, 5 German, 6 Spanish, 7 French, 8 Japanese, and 9 Traditional Chinese.

Returns: An array of {id, name, monster} records and the total match count, or nil, error for invalid arguments or an unavailable catalog. monster is true when the installed game's Skill table identifies the entry as an NPC skill.

local skills, total = defense.skills(1, 20, "", 0, 0)
if not skills then
    log.warn(total)
else
    for _, skill in ipairs(skills) do
        log.info(skill.id .. " " .. skill.name)
    end
end

Rules

defense.rules()

Parameters: None. Returns: Configured rule records with skill, action, phase, delay_ms, cooldown_ms, and enabled, or nil, error.

defense.set_rule(skill, action, phase, delayMs, cooldownMs, enabled)

Parameters: skill is a known skill ID, action is 1–3, and phase is 0–3. Optional delayMs defaults to 0 and accepts 0–2000; cooldownMs defaults to 1000 and accepts 100–60000; enabled defaults to true.

Returns: true when added or updated, false if the request did not complete, or nil, error for invalid input or another failure.

defense.remove_rule(skill, phase)

Parameters: Known skill ID and phase 0–3. Returns: true when removed, false if no rule was removed, or nil, error.

local skillId = 12345 -- Replace with an ID from defense.skills().
local ok, err = defense.set_rule(skillId, 3, 0, 0, 1000, true)
if ok == nil then
    log.warn(err)
elseif not ok then
    log.warn("Rule was not updated")
end

Settings

defense.settings()

Parameters: None. Returns: {enabled, evade_key, parry_key, block_key, other_targets}, or nil, error.

defense.set_settings(enabled, evadeKey, parryKey, blockKey, otherTargets)

Parameters: enabled and otherTargets are booleans; each key is a number from 0 to 255. Returns: true, false, or nil, error.

defense.save(name)

Parameters: Rule-set name of 1–50 bytes. Returns: true, false, or nil, error.

local settings, err = defense.settings()
if settings then
    log.info(settings.enabled and "Defense enabled" or "Defense disabled")
else
    log.warn(err)
end

Events

defense.monster_casts()

Call this from a module's on_tick. It requests receive capture and returns an array of active casting notices from uniquely matched live monsters, or nil, error when the actor snapshot is unavailable. The first call can return an empty array while capture starts.

Each notice has skill_id, caster_key, target_key, start_ms, duration_ms, remaining_ms, and caster_position. direction_degrees is present when the packet yaw is valid. target_position and target_position_source are present when the packet supplies a position or the target is still a live actor. Positions have {x, y, z} fields. The caster position and actor based target position are sampled when the function is called; start_ms and duration_ms come from the casting notice.

area_candidates contains the matching catalog's effect slots. Each has slot, filter_id, shape, needs_target, notice_target_location, notice_previous_time_raw, and the original values. A supported shape with a usable anchor and direction also has candidate_center, radius_raw, inner_radius_raw, width_raw, angle_degrees_raw, and yaw_degrees. The catalog must match the loaded client; an empty array can mean the area catalog is unavailable. Shape values, effect timing, and impact anchors are estimates, so draw these as hints rather than exact danger boundaries. A canceled cast may remain until its reported duration expires.

function on_tick()
    local casts = defense.monster_casts()
    if not casts then return end

    for _, cast in ipairs(casts) do
        for _, area in ipairs(cast.area_candidates) do
            local center = area.candidate_center
            if center and area.shape == "Circle" and area.radius_raw > 0 then
                gfx.ground_circle(center.x, center.y, center.z,
                    area.radius_raw, 0xFF00A5FF)
            elseif center and area.shape == "Arc" and area.angle_degrees_raw > 0 then
                gfx.ground_cone(center.x, center.y, center.z,
                    area.radius_raw, area.yaw_degrees,
                    area.angle_degrees_raw, 0xFF00A5FF)
            end
        end
    end
end

defense.watch(skill, phase)

Parameters: Known skill ID and phase 0–3. Returns: true when subscribed, or nil, error.

defense.unwatch(skill, phase)

Parameters: Skill ID and phase to stop watching. Returns: true when removed, or nil, error.

defense.test(skill, phase)

Parameters: Skill ID and phase of a configured rule. Returns: true, false, or nil, error for the test request.

A loaded module with defense.watch receives on_defense(event). The event has skill, phase, action, fired, and test. Subscriptions end when the module unloads.

function on_start()
    local ok, err = defense.watch(12345, 0)
    if not ok then log.warn(err) end
end

function on_defense(event)
    log.info(string.format("Skill %d, phase %d, action %d",
        event.skill, event.phase, event.action))
end

On this page