Skip to content

rq.chara ​

since 0.2.0 changed 0.4.0 changed 2.35.0

Reads and changes characters: their skills, stats, the skill buy list, and the roster.

The calls work on a roster slot, the iic (the id of an entry in rq.units()), unless they say who: those take a character number or a mod's text id. Base-game numbers include Rance 1, Kaoru 52, Onoha 62 and Rebecca 81.

Skills and the buy list. grant, rank, slots, set_slot, set_flavor, weapon_detail, apply_mod, on_recalc, on_offer, offers, set_offer, set_uses, set_bar, clear_slot and max_uses place the hooks they need the first time (rq.chara.install). Before 2.35.0 they needed it first, and without it read 0 and wrote nothing.

Roster. define registers a template; the character exists, and joins the player's roster, only when recruit runs, so a mod can give it from a quest or an event. recruit also works for base-game characters. A text id such as "mymod:alice" becomes a number from 1000 up, the same number every time, so saves stay valid. The roster has 181 slots (20 to 200). The roster calls install what they need on first use.

HP and heals. get and set read and write hp, hp_max and status; heal is the game's own heal. Where a character is (the party, the reserve) is rq.party's.

lua
-- Create now, provide later
rq.chara.define({ id = "mymod:alice", name = "Alice", class = 1, level = 5, slots = 4,
  init = { atk = 10 }, skills = { { id = 100, n = 8 } } })
if rq.store.get("alice_joined") ~= true then
  local iic = rq.chara.recruit("mymod:alice", { state = 2 })
  if iic then rq.store.set("alice_joined", true) end
end

-- Edit a base-game character, also in old saves: Onoha gets Head Start 2 (skill 246)
rq.chara.edit(62, { init = { eva = 50, spd = 25 }, learn = { { id = 246, n = 2 } } })

Functions ​

NameSummary
rq.chara.installInstalls the hooks the skill and buy-list calls need.
rq.chara.grantGives a character a skill (CS追加).
rq.chara.rankReturns a character's rank in a skill (CS有無/ランク).
rq.chara.slotsLists the rows of a character's skill list that hold a skill.
rq.chara.set_slotWrites the skill number of a skill-list row (CS番号).
rq.chara.set_flavorCopies the battle-log line (S表示文) of a row's current skill to the character.
rq.chara.weapon_detailReturns the weapon kind of the character's equipped weapon (I種類詳細).
rq.chara.apply_modApplies a stat change the way the game's own skills do (C機能適応).
rq.chara.offersLists the rows of the skill buy list that hold a skill.
rq.chara.set_offerReplaces the skill in a buy-list row.
rq.chara.set_usesSets the uses left and the most uses of a skill-list row.
rq.chara.set_barPuts a skill-list row on the hotbar, or takes it off (CS実装中).
rq.chara.clear_slotEmpties a skill-list row (CS初期化).
rq.chara.max_usesReturns the most uses a character has of a skill (CS有無/最大回数).
rq.chara.defineRegisters a character template.
rq.chara.recruitCreates a character in the roster (C生成), or finds the one already there.
rq.chara.findReturns the roster slot of a character (C番号取得).
rq.chara.is_recruitedReturns whether a character is in the roster.
rq.chara.recalcRecalculates a character now (C再計算).
rq.chara.absorbedReturns the five items a Morurun absorbed: item numbers, 0 for an empty slot.
rq.chara.set_absorbedChanges one of the five absorbed items, then recalculates the character.
rq.chara.dismissRemoves a character from the roster (C削除).
rq.chara.numberReturns the character number in a roster slot.
rq.chara.id_ofReturns the text id of a defined character number.
rq.chara.editPatches a character, again at the end of every recalculation, so it covers old saves too.
rq.chara.getReturns everything known about a character.
rq.chara.setWrites character fields by the names rq.chara.get uses.
rq.chara.skill_pointsReturns a character's free skill points.
rq.chara.add_skill_pointsAdds to a character's free skill points.
rq.chara.healHeals one character as the game does: HP to the most, and with skills the skill uses too.
rq.chara.forgetRemoves a skill from a character (CS削除).
rq.chara.forget_pointsThe skill points the rq.chara.on_forget callbacks would give back for erasing a skill, without erasing it.
rq.chara.set_costWrites the purchase record of a skill the character holds.
rq.chara.base_skillsReturns the skills a character starts with, as Morurun's reset would give them back.
rq.chara.skill_points_maxReturns the most skill points a character can have had (C最大スキルポイント取得).
rq.chara.learnableReturns the skill buy list the game would make for a character, without opening the window.
rq.chara.boostsReturns the Boosts and whether the character keeps each one's effect without the skill.
rq.chara.priceReturns what the game charges a character for a skill from one level to another.
rq.chara.learnBuys a skill for a character as the skill window does, without its questions.
rq.chara.skill_roomReturns how many more skills a character can learn, as the skill window counts its free rows.
rq.chara.add_expGives a character EXP, as a fight's result does, and the levels it fills.
rq.chara.level_upRaises a character's level for free, as the game's story and training do.

rq.chara.install ​

lua
rq.chara.install() -> boolean

since 0.2.0 changed 2.35.0

Installs the hooks the skill and buy-list calls need.

It hooks the end of C再計算 (the recalculation, after the game's own spear rewrite) and of T購入スキル登録 (the buy list), and the combat sites rq.combat uses. Calling it again, or after rq.combat.install, does nothing more.

Not needed since 2.35.0: each call that needs it places it the first time, and raises this call's error there when it cannot. Calling it still does no harm.

Raises an error when the AIN is not loaded or a hook cannot be placed (the reason is in the log).

ReturnsTypeDescription
okbooleanAlways true; a failure raises an error.

Changed in 2.35.0: Not needed: the calls that need it make it.

rq.chara.grant ​

lua
rq.chara.grant(iic, skillId, n) -> integer

since 0.2.0 changed 2.45.0

Gives a character a skill (CS追加).

A new row is marked as given in the purchase record (its cost is -1), so rq.chara.on_forget can tell it from a bought skill. A row that already holds a record keeps it.

Raises an error for a slot with no character or a skill number outside 1 to 1000.

ParameterTypeDescription
iicintegerThe character's roster slot.
skillIdintegerThe skill number.
nintegerThe rank for a knowledge skill (type 30), or the uses for an active skill (type 10).
ReturnsTypeDescription
slotintegerThe skill-list row it went to.

Changed in 2.45.0: Marks the row as given in the purchase record.

rq.chara.rank ​

lua
rq.chara.rank(iic, skillId) -> integer

since 0.2.0

Returns a character's rank in a skill (CS有無/ランク).

ParameterTypeDescription
iicintegerThe character's roster slot.
skillIdintegerThe skill number.
ReturnsTypeDescription
rankinteger1 to 4 (no star through three stars); 0 when the character does not have the skill or there is no character.

rq.chara.slots ​

lua
rq.chara.slots(iic) -> rq.CharaSlot[]

since 0.2.0 changed 2.45.0 changed 2.54.0

Lists the rows of a character's skill list that hold a skill.

The game's screens show 6 hotbar positions, so a slots value above 6 adds rows but no positions.

ParameterTypeDescription
iicintegerThe character's roster slot.
ReturnsTypeDescription
slotsrq.CharaSlot []The rows in order; empty when there is no character.

Changed in 2.45.0: Each row has the purchase record (cost) and the level (n).

Changed in 2.54.0: The rows past 20 that rq.knownskills.install adds.

rq.chara.set_slot ​

lua
rq.chara.set_slot(iic, slot, skillId)

since 0.2.0 changed 2.57.0

Writes the skill number of a skill-list row (CS番号).

Only the number changes; the uses and the battle-log line stay. See rq.chara.set_flavor.

Raises an error for a slot with no character, a row outside 1 to the list's last row (20, more with rq.knownskills) or a skill number outside 0 to 1000.

ParameterTypeDescription
iicintegerThe character's roster slot.
slotintegerThe skill-list row.
skillIdintegerThe skill number; 0 empties the number.

Changed in 2.57.0: A row out of the list is an error; before, a negative row closed the game with a fatal VM error.

rq.chara.set_flavor ​

lua
rq.chara.set_flavor(iic, slot)

since 0.2.0 changed 2.57.0

Copies the battle-log line (S表示文) of a row's current skill to the character.

The game's own slot swaps skip this, so call it after rq.chara.set_slot.

Raises an error for a slot with no character or a row outside 1 to the list's last row (20, more with rq.knownskills).

ParameterTypeDescription
iicintegerThe character's roster slot.
slotintegerThe skill-list row.

Changed in 2.57.0: A row out of the list is an error; before, a negative row closed the game with a fatal VM error.

rq.chara.weapon_detail ​

lua
rq.chara.weapon_detail(iic) -> integer

since 0.2.0

Returns the weapon kind of the character's equipped weapon (I種類詳細).

ParameterTypeDescription
iicintegerThe character's roster slot.
ReturnsTypeDescription
kindintegerSword 2, spear or naginata 7, glove 9; 0 when there is no character.

rq.chara.apply_mod ​

lua
rq.chara.apply_mod(iic, kind, amount, scale)

since 0.2.0

Applies a stat change the way the game's own skills do (C機能適応).

Call it from rq.chara.on_recalc, so it is applied on every recalculation.

ParameterTypeDescription
iicintegerThe character's roster slot.
kindintegerThe stat, as the game numbers it: accuracy 8, magic 14.
amountintegerHow much to add.
scale (optional)integerThe percent of amount applied. Default 100.

rq.chara.offers ​

lua
rq.chara.offers() -> rq.OfferRow[]

since 0.2.0 changed 2.18.0

Lists the rows of the skill buy list that hold a skill.

They are the game's 取得可能スキル: rows 1 to 60, or 1 to 144 with rq.skilllist on.

ReturnsTypeDescription
rowsrq.OfferRow []The rows in order; empty when there is no buy list.

Changed in 2.18.0: With rq.skilllist, the game's own arrays (made longer) instead of the engine's copy.

rq.chara.set_offer ​

lua
rq.chara.set_offer(index, skillId, points)

since 0.2.0

Replaces the skill in a buy-list row.

It writes the game's list. The row's level text stays as it is.

Raises an error for an index outside the list, or for points when the game has no price list.

ParameterTypeDescription
indexintegerThe row's index, as rq.chara.offers gives it.
skillIdintegerThe skill number.
points (optional)integerThe new price in skill points. Default: the price stays.

rq.chara.set_uses ​

lua
rq.chara.set_uses(iic, slot, uses, max)

since 0.2.0 changed 2.57.0

Sets the uses left and the most uses of a skill-list row.

The most uses is written first; the game caps it at 99.

Raises an error for a slot with no character or a row outside 1 to the list's last row (20, more with rq.knownskills).

ParameterTypeDescription
iicintegerThe character's roster slot.
slotintegerThe skill-list row.
usesintegerUses left.
maxintegerMost uses.

Changed in 2.57.0: A row out of the list is an error; before, a negative row closed the game with a fatal VM error.

rq.chara.set_bar ​

lua
rq.chara.set_bar(iic, slot, pos)

since 0.2.0 changed 2.57.0

Puts a skill-list row on the hotbar, or takes it off (CS実装中).

Raises an error for a slot with no character or a row outside 1 to the list's last row (20, more with rq.knownskills).

ParameterTypeDescription
iicintegerThe character's roster slot.
slotintegerThe skill-list row.
posintegerThe hotbar position, 1 to 6; 0 takes it off.

Changed in 2.57.0: A row out of the list is an error; before, a negative row closed the game with a fatal VM error.

rq.chara.clear_slot ​

lua
rq.chara.clear_slot(iic, slot)

since 0.2.0 changed 2.57.0

Empties a skill-list row (CS初期化).

Raises an error for a slot with no character or a row outside 1 to the list's last row (20, more with rq.knownskills).

ParameterTypeDescription
iicintegerThe character's roster slot.
slotintegerThe skill-list row.

Changed in 2.57.0: A row out of the list is an error; before, a negative row closed the game with a fatal VM error.

rq.chara.max_uses ​

lua
rq.chara.max_uses(iic, skillId) -> integer

since 0.2.0

Returns the most uses a character has of a skill (CS有無/最大回数).

This is what the game's price (スキルポン) reads when it raises the cost of another use.

ParameterTypeDescription
iicintegerThe character's roster slot.
skillIdintegerThe skill number.
ReturnsTypeDescription
maxintegerThe most uses; 0 when the character does not have the skill or there is no character.

rq.chara.define ​

lua
rq.chara.define(def) -> integer

since 0.4.0

Registers a character template.

Nothing joins the roster until rq.chara.recruit. Defining the same id again replaces the template. Up to 96 templates.

Raises an error for a missing or too long id, an id whose number another id already has, or a 97th template.

ParameterTypeDescription
defrq.CharaDefThe template.
ReturnsTypeDescription
nointegerThe character number the id maps to, 1000 or more.

See also: rq.chara.recruit

rq.chara.recruit ​

lua
rq.chara.recruit(who, opts) -> integer|nil, string?

since 0.4.0 changed 0.6.0

Creates a character in the roster (C生成), or finds the one already there.

Works for a defined id and for a base-game number. opts applies also to a character already in the roster. The Party tab's list is refreshed.

Raises an error for a number of 1000 or more that no template has.

ParameterTypeDescription
whostring|integerA text id or a character number.
opts (optional)rq.RecruitOptsWhere the new character goes.
ReturnsTypeDescription
iicinteger|nilThe roster slot, or nil when the game refused.
errstring?Why the game refused, such as a full roster.

Changed in 0.6.0: Refreshes the Party tab's list.

rq.chara.find ​

lua
rq.chara.find(who) -> integer|nil

since 0.4.0

Returns the roster slot of a character (C番号取得).

ParameterTypeDescription
whostring|integerA text id or a character number.
ReturnsTypeDescription
iicinteger|nilThe roster slot, or nil when the character is not in the roster.

rq.chara.is_recruited ​

lua
rq.chara.is_recruited(who) -> boolean

since 0.4.0

Returns whether a character is in the roster.

ParameterTypeDescription
whostring|integerA text id or a character number.
ReturnsTypeDescription
recruitedbooleantrue when the character is in the roster.

rq.chara.recalc ​

lua
rq.chara.recalc(iic, heal)

since 0.5.0

Recalculates a character now (C再計算).

Pending rq.chara.edit patches and init changes show at once.

Raises an error for a slot with no character.

ParameterTypeDescription
iicintegerThe character's roster slot.
heal (optional)booleantrue also refills HP and uses (C補給). Default false.

rq.chara.absorbed ​

lua
rq.chara.absorbed(iic) -> integer[]

since 2.23.0

Returns the five items a Morurun absorbed: item numbers, 0 for an empty slot.

The game fills these slots when a Morurun takes in a special item (C体内特殊アイテムの取得処理): kind 21 only, never 304 to 307, 309 or 310; the first empty slot; with all five full, a higher rank replaces the first slot that holds a rank-1 item, and a rank-1 item is not taken. Every character has the slots; in play only Morurun fill them.

Raises an error for a slot with no character.

lua
for slot, no in ipairs(rq.chara.absorbed(iic)) do
  if no ~= 0 then rq.log(slot, rq.ids.name("item", no)) end
end
ParameterTypeDescription
iicintegerThe character's roster slot.
ReturnsTypeDescription
itemsinteger[]Five item numbers, in slot order; 0 is empty.

See also: rq.chara.set_absorbed

rq.chara.set_absorbed ​

lua
rq.chara.set_absorbed(iic, slot, no)

since 2.23.0

Changes one of the five absorbed items, then recalculates the character.

Only the slot changes: taking an instance from the vault, giving the old item back, drawing the status page again (rq.statuspage.refresh) and a sound are the mod's. The recalculation also refills HP and uses outside a quest. It does not check that the character is a Morurun.

Raises an error for a slot with no character, a slot outside 1 to 5, an item that is not a special item (kind 21) or one the game never absorbs (304 to 307, 309, 310).

lua
rq.chara.set_absorbed(iic, 1, 0)   -- empty slot 1
rq.chara.set_absorbed(iic, 2, 274) -- put item 274 in slot 2
ParameterTypeDescription
iicintegerThe character's roster slot.
slotinteger1 to 5.
nointegerThe item number, or 0 to empty the slot.

See also: rq.chara.absorbed

rq.chara.dismiss ​

lua
rq.chara.dismiss(iic)

since 0.4.0 changed 0.6.0

Removes a character from the roster (C削除).

The character leaves the party first. The Party tab's list is refreshed.

Raises an error for an empty slot or a slot under 20.

ParameterTypeDescription
iicintegerThe character's roster slot.

Changed in 0.6.0: Refreshes the Party tab's list.

rq.chara.number ​

lua
rq.chara.number(iic) -> integer|nil

since 0.4.0

Returns the character number in a roster slot.

ParameterTypeDescription
iicintegerThe roster slot.
ReturnsTypeDescription
nointeger|nilThe character number, or nil when the slot is empty.

rq.chara.id_of ​

lua
rq.chara.id_of(no) -> string|nil

since 0.4.0

Returns the text id of a defined character number.

ParameterTypeDescription
nointegerThe character number.
ReturnsTypeDescription
idstring|nilThe text id, or nil when no mod defined that number.

rq.chara.edit ​

lua
rq.chara.edit(who, patch)

since 0.4.0 changed 1.2.1

Patches a character, again at the end of every recalculation, so it covers old saves too.

Each mod keeps one patch per character; calling again replaces it. Every edited character is recalculated once right after a save loads. A patch made later, with the save already loaded, waits for the character's next recalculation; rq.chara.recalc applies it now. weapon, armor, item and special apply only when the character is created. Up to 192 patches.

lua
rq.chara.edit("mymod:alice", { init = { spd = 10 }, weakness_known = true })
ParameterTypeDescription
whostring|integerA text id or a character number (not a roster slot).
patchrq.CharaEditThe fields to set.

Changed in 1.2.1: Edited characters are recalculated once after a save loads.

rq.chara.get ​

lua
rq.chara.get(iic) -> rq.CharaState|nil

since 0.4.0 changed 0.5.0

Returns everything known about a character.

ParameterTypeDescription
iicintegerThe character's roster slot.
ReturnsTypeDescription
staterq.CharaState |nilA copy of the character's fields, or nil when there is no character.

Changed in 0.5.0: Added the battle-state fields.

rq.chara.set ​

lua
rq.chara.set(iic, fields)

since 0.4.0

Writes character fields by the names rq.chara.get uses.

slots, name, short and face_name work too, and face and portrait take an image path inside the mod's folder. A change to a derived stat (hp_max, atk, ...) lasts only until the next recalculation: use init_*, or rq.chara.edit to keep it.

Raises an error for a slot with no character or an unknown field.

lua
rq.chara.set(iic, { hp = 1, weakness_known = true })
ParameterTypeDescription
iicintegerThe character's roster slot.
fieldstableField names and new values.

rq.chara.skill_points ​

lua
rq.chara.skill_points(iic) -> integer

since 0.4.0

Returns a character's free skill points.

ParameterTypeDescription
iicintegerThe character's roster slot.
ReturnsTypeDescription
pointsintegerThe free skill points; 0 when there is no character.

rq.chara.add_skill_points ​

lua
rq.chara.add_skill_points(iic, delta) -> integer

since 0.4.0

Adds to a character's free skill points.

Raises an error for a slot with no character.

ParameterTypeDescription
iicintegerThe character's roster slot.
deltaintegerPoints to add; negative takes away.
ReturnsTypeDescription
totalintegerThe new total, never below 0.

rq.chara.heal ​

lua
rq.chara.heal(iic, opts) -> boolean

since 2.35.0

Heals one character as the game does: HP to the most, and with skills the skill uses too.

A downed character is left as it is, as in the game's party heals; set its status to 0 with rq.chara.set first to raise it.

Raises an error for a slot with no character, or for all (that is rq.party.heal's).

lua
if rq.chara.heal(iic, { skills = true }) then rq.log("healed") end
ParameterTypeDescription
iicintegerThe roster slot.
opts (optional){skills?: boolean, half?: boolean}skills fills the skill uses; half heals up to half the most HP.
ReturnsTypeDescription
healedbooleanfalse for a downed character.

See also: rq.party.heal

rq.chara.forget ​

lua
rq.chara.forget(iic, skill, opts) -> boolean, integer?, integer?

since 0.4.0 changed 2.45.0 changed 2.51.0

Removes a skill from a character (CS削除).

rq.chara.on_forget callbacks run, with caller "lua" and mod the calling mod's id. With player = true the erasure is the player's own, as the skill window's ERASE: a mod that erases for the player (a build it loads, a skill the player picked in its menu) sets it, and the callbacks see player, so a mod that gives points back for ERASE (Skill Removal Payback) gives them back here too. Without it the removal is the mod's own, as onoha-qol's head start, and such a mod gives nothing. The third value is the points the callbacks gave back, already added to the character.

Raises an error for a slot with no character, or for iic, skill or opts of the wrong type.

lua
-- Erase a skill the player picked in the mod's menu, as ERASE would.
local removed, cost, back = rq.chara.forget(iic, skill, { player = true })
if removed then rq.log(("erased; it cost %d, %d back"):format(cost, back)) end
ParameterTypeDescription
iicintegerThe character's roster slot.
skillintegerThe skill number.
opts (optional){player?: boolean}player: the player chose this erasure (default false).
ReturnsTypeDescription
removedbooleanfalse when the character did not have the skill (the only value then).
costinteger?The purchase record, as rq.ForgetCtx.cost.
backinteger?The skill points the rq.chara.on_forget callbacks gave back (since 2.51.0).

Changed in 2.45.0: cost is the purchase record.

Changed in 2.51.0: opts.player, and the points given back.

See also: rq.chara.forget_points

rq.chara.forget_points ​

lua
rq.chara.forget_points(iic, skill, opts) -> integer

since 2.52.0

The skill points the rq.chara.on_forget callbacks would give back for erasing a skill, without erasing it.

Each callback runs with the ctx the erasure would have, preview true, caller "lua" and mod the calling mod; nothing is erased and no points are given. For a plan, n, cost and kept describe the row as it would be then: a skill the character does not have yet, or one a plan raises first. cost is the purchase record then (rq.ForgetCtx.cost), which a planner works out from what the steps pay. Use it to show the price of a change that erases skills, as Loadouts shows the price of a load less what comes back. A callback that does not look at preview gives the same answer as for an erasure.

Raises an error for a slot with no character, a skill number the game does not have, or opts of the wrong type.

lua
-- What erasing Healing 3 would give back if the player chose it.
local back = rq.chara.forget_points(iic, 223, { player = true })

-- And once it is bought to 3 uses for 9 points (a row the character does not have yet).
local later = rq.chara.forget_points(iic, 223, { player = true, n = 3, cost = 9 })
ParameterTypeDescription
iicintegerThe character's roster slot.
skillintegerThe skill number.
opts (optional){player?: boolean, n?: integer, cost?: integer, kept?: boolean}player as in rq.chara.forget (default false). n: the level then, from 1 (default: the row's now). cost: the purchase record then, from -1 (default: the row's now, or 0). kept: whether it would be a Boost whose effect stays (default: as now, or for a Boost at n 4 in the third world, true).
ReturnsTypeDescription
backintegerThe points the callbacks would give back; 0 when the character does not have the skill and no n is given.

See also: rq.chara.forget

rq.chara.set_cost ​

lua
rq.chara.set_cost(iic, skill, cost) -> boolean

since 2.53.0

Writes the purchase record of a skill the character holds.

The record is what rq.chara.on_forget's cost and rq.chara.slots' cost read, and what a mod that gives points back for an erasure (Skill Removal Payback) gives back. The loader writes it at each purchase. A mod whose skill takes the place of others writes the points paid for those into the new skill's row, so erasing it later gives back everything paid for the set; Better Elemental Knowledge does this when its skill folds the single ones into one row. -1 marks a skill a mod gave, 0 a skill with nothing recorded.

Raises an error for a slot with no character, a skill number the game does not have, or a cost that is not a whole number from -1.

lua
-- The new skill's row also counts the points paid for the two it replaced.
local rows = {}
for _, s in ipairs(rq.chara.slots(iic)) do rows[s.skill] = s end
local paid = rows[NEW].cost
for _, old in ipairs({ OLD_A, OLD_B }) do
  if rows[old] and rows[old].cost > 0 then paid = paid + rows[old].cost end
  rq.chara.forget(iic, old)
end
rq.chara.set_cost(iic, NEW, paid)
ParameterTypeDescription
iicintegerThe character's roster slot.
skillintegerThe skill number.
costintegerThe record: the skill points paid, -1 for given, 0 for none.
ReturnsTypeDescription
writtenbooleanfalse when the character does not have the skill.

See also: rq.ForgetCtx.cost

rq.chara.base_skills ​

lua
rq.chara.base_skills(iic) -> rq.SkillLevel[]

since 2.45.0

Returns the skills a character starts with, as Morurun's reset would give them back.

The game rebuilds a character's skills for that reset (Cスキルドレイン) from the character's own data (C生成/キャラデータ): Skill Slots, the class's skills, the character's own, the Morurun marks, then the ones flags add (the familiar, a few story skills). This call runs that same code on the character and puts everything back before it returns, so the character does not change and rq.chara.on_forget does not run. A mod's character gives its definition's skills. Skills a mod gives through edit are not part of it.

What a character has above this set was bought, or given by a story event or a mod; the purchase record (rq.ForgetCtx.cost) tells which, for what was bought from loader 2.45.0 on.

Raises an error for a slot with no character.

lua
for _, s in ipairs(rq.chara.base_skills(iic)) do
  rq.log(("starts with skill %d at %d"):format(s.id, s.n))
end
ParameterTypeDescription
iicintegerThe character's roster slot.
ReturnsTypeDescription
skillsrq.SkillLevel []The starting skills, in their rows' order.

See also: rq.chara.price

rq.chara.skill_points_max ​

lua
rq.chara.skill_points_max(iic) -> integer

since 2.45.0

Returns the most skill points a character can have had (C最大スキルポイント取得).

It is the game's count: level - 1, 2 for each Morurun reset up to 5, one for each castle bonus up to 3, and the bonuses of a few skills and flags. Minus the free points (rq.chara.skill_points), it is what the character has spent, unless a mod gave points. The game's function also clears a counter (FA[33]); this call leaves it as it was.

Raises an error for a slot with no character.

lua
local spent = rq.chara.skill_points_max(iic) - rq.chara.skill_points(iic)
ParameterTypeDescription
iicintegerThe character's roster slot.
ReturnsTypeDescription
pointsintegerThe most points.

rq.chara.learnable ​

lua
rq.chara.learnable(iic, opts) -> rq.LearnableRow[]?, integer, rq.CharaSlot[]?

since 2.45.0 changed 2.48.0 changed 2.66.0

Returns the skill buy list the game would make for a character, without opening the window.

The game fills its list (T購入スキル登録) and the loader reads it, then puts the list back as it was. rq.chara.on_offer callbacks run, so mods' offers are in it. A skill at its most uses (99) or rank (4) is not listed.

A row the list shows but does not sell has the game's reason (why) and what its conditions name: the skills and levels (needs) and the character level (level). The game names a skill by its name only; the loader reads it back to a number, the list's and the character's skills first.

opts.after is a list of steps, each a skill and a level (0 erases it), set in order on the character before the list is made and undone after: the list as it would be after those purchases or erasures, as Healing 3 for sale once Healing 2 is at 3, or Healing 2 off sale once Healing 1 is erased. A step sets the level as it is, with no price and none of the game's checks; then the game recalculates the character, as the skill window does after each purchase, so what a recalculation does follows: a Boost at rank 4 is kept (rq.chara.boosts), Melee Attack becomes Thrust Attack, a mod's on_recalc swaps its rows (with preview true). The recalculation follows each step of a ranked skill and each erasure; steps of uses, which change no form, have one recalculation after them, before the list. A step for a skill whose form the character holds sets that row (rq.chara.SkillStep). When a step needs a new row and none is left, the call returns nil and the step's index.

The second value is the free skill rows after the steps, as rq.chara.skill_room counts them; the third, the character's rows after them, as rq.chara.slots gives them: where a recalculation put a form, and each row's level.

Raises an error for a slot with no character, an after that is not a list, or a step that is not { skill = number, n = level from 0 }.

and level. a step reaches the row of a form; the rows as a third value.

lua
for _, row in ipairs(rq.chara.learnable(iic)) do
  if row.points > 0 then rq.log(("skill %d: %d points"):format(row.skill, row.points)) end
end
-- Healing 3's price once Healing 2 is at 3 and Healing 1 erased
local rows = rq.chara.learnable(iic, { after = { { skill = 221, n = 0 }, { skill = 222, n = 3 } } })
for _, row in ipairs(rows or {}) do
  if row.skill == 223 then rq.log("Healing 3: " .. row.points .. " points") end
end
ParameterTypeDescription
iicintegerThe character's roster slot.
opts (optional){ after?: rq.SkillStep [] }after: the steps to set before the list is made.
ReturnsTypeDescription
rowsrq.LearnableRow []?The list, in the game's order; nil when a step found no free row.
roomintegerThe free skill rows after the steps; with nil rows, the index of the step that found none.
slotsrq.CharaSlot []?The character's rows after the steps (since 2.66.0); nil with nil rows.

Changed in 2.48.0: opts.after, the free rows as a second value, and each row's step, needs

Changed in 2.66.0: The game's recalculation after each step (before, only a Boost's mark was set);

See also: rq.chara.price

rq.chara.boosts ​

lua
rq.chara.boosts(iic) -> rq.BoostRow[], boolean

since 2.48.0

Returns the Boosts and whether the character keeps each one's effect without the skill.

In the third world only (rq.world.current), the game's recalculation marks a Boost raised to rank 4 (FA[38] to FA[45]), and the character keeps its effect after the skill is erased: +800 HP, +300 Attack or Magic, or +50 to a rate. The second version of Stamina, Attack and Magic Boost (455, 456, 457) is sold only once the first is at rank 4 or kept, and is kept on top of it. The game's reset of the skills (Cスキルドレイン: Morurun's reset, Skill Again) clears the marks, and so does a recalculation in another world.

Raises an error for a slot with no character.

lua
local boosts, keeps = rq.chara.boosts(iic)
for _, b in ipairs(boosts) do
  if b.kept then rq.log(("skill %d's effect stays"):format(b.skill)) end
end
ParameterTypeDescription
iicintegerThe character's roster slot.
ReturnsTypeDescription
boostsrq.BoostRow []The eleven Boosts, firsts before seconds.
keepsbooleanWhether this world keeps a Boost's effect (the third world).

See also: rq.chara.on_forget

rq.chara.price ​

lua
rq.chara.price(iic, skill, from, to) -> integer?, string?, string?

since 2.45.0 changed 2.66.0

Returns what the game charges a character for a skill from one level to another.

Each step is priced as the buy list prices it at that step: the skill is set to the step on the character, the game recalculates it and fills its list, and the step's price is read; the character and the list are put back before the call returns. So the game's rules hold: one more point at 3, 5 and 7 most uses, the prices that change with the skill (Rance's 147), and a mod's rq.chara.on_offer. A level is most uses for a use skill (type 10), the rank for a ranked one (20, 30). Skill 384 goes 3 uses a step, as the game sells it. When the list sells a form of the skill (rq.skill.form_of) and not the skill, that form is priced, on the row of the form the character holds.

It returns nil and why when a step is not for sale: "not sold" (the character's list does not have it, or the skill cannot be bought), "condition" with the game's text (a level it lacks), "max" (past 99 uses or rank 4), "room" (no free skill row to price a new skill in).

Raises an error for a slot with no character, a skill number not in the game's table, or a level below 0.

lua
-- what a starting skill would cost from nothing
local points = rq.chara.price(iic, 100, 0, 3) or 1
ParameterTypeDescription
iicintegerThe character's roster slot.
skillintegerThe skill number.
fromintegerThe level to start from; 0 for a skill the character does not have.
tointegerThe level to reach; nothing to pay when it is not above from.
ReturnsTypeDescription
pointsinteger?The points, or nil when a step is not for sale.
whystring?"not sold", "condition", "max" or "room".
textstring?The game's reason, for "condition".

Changed in 2.66.0: The game's recalculation at each step; a skill's forms.

See also: rq.chara.learnable

rq.chara.learn ​

lua
rq.chara.learn(iic, skill, opts) -> boolean, integer|string, integer|string?

since 2.45.0 changed 2.66.0

Buys a skill for a character as the skill window does, without its questions.

Each step goes through the game's own buy (キャラスキル_新規追加) or upgrade (キャラスキル_更新) at the list's price, with the game's "Learn ...?" answered Yes, then the character is recalculated (and refilled outside a quest), as the window does after each purchase. The purchase record grows and rq.chara.on_learn runs for each step. When the character holds a form of the skill (rq.skill.form_of), that row is raised, as the form the list sells. Before buying anything it checks the whole price, the free points and a free skill row, and refuses with the reason:

  • "points", with how many points are missing
  • "room": no free skill row for a new skill
  • "not sold", "condition" (with the game's text) or "max", as rq.chara.price
  • "refused": the game refused a step; the steps before it stay bought

Raises an error for a slot with no character, a skill number not in the game's table, opts that is not a table, a to below 0, or a call from inside another learn.

lua
local ok, why, detail = rq.chara.learn(iic, 100, { to = 5 })
if not ok and why == "points" then rq.log(detail .. " more points needed") end
ParameterTypeDescription
iicintegerThe character's roster slot.
skillintegerThe skill number.
opts (optional){to?: integer, pay?: boolean}to: the level to reach (default one step more). pay: false gives the steps for free and marks a new row as given in the record (default true).
ReturnsTypeDescription
okbooleantrue when the skill reached to.
spent_or_whyinteger|stringThe points paid when ok; otherwise the reason.
detailinteger|string?The missing points for "points", the game's text for "condition".

Changed in 2.66.0: The recalculation after each purchase (before, once after the last); a skill's forms.

See also: rq.chara.price

rq.chara.skill_room ​

lua
rq.chara.skill_room(iic) -> integer

since 2.45.0 changed 2.54.0

Returns how many more skills a character can learn, as the skill window counts its free rows.

It is the game's check before a new skill (キャラスキル_空き確認) as a number: 17 rows (rq.knownskills.most() with rq.knownskills), less the rows the game keeps free for the character's story skills (キャラ_スキル枠キープ数), less the skills the character has. A new skill from rq.chara.learn needs one; one more use or rank needs none. rq.chara.grant does not check it.

Raises an error for a slot with no character.

lua
if rq.chara.skill_room(iic) < 2 then rq.ui.notice("Erase a skill first.") end
ParameterTypeDescription
iicintegerThe character's roster slot.
ReturnsTypeDescription
rowsintegerThe free rows, 0 or more.

Changed in 2.54.0: Counts to rq.knownskills.most() once rq.knownskills.install made the rows longer.

See also: rq.chara.learn

rq.chara.add_exp ​

lua
rq.chara.add_exp(iic, n) -> integer

since 2.33.0

Gives a character EXP, as a fight's result does, and the levels it fills.

The EXP is added, then the character goes up one level each time the bar is full, with the game's own level-up (キャラ_レベルアップ): the stats grow, skill points come, the bar's EXP is used, and what is left carries over to the next level. EXP over the last level's bar is cut to that bar. A character at the highest level (level_max in rq.chara.get; none for a character with uncapped) gets nothing, as in the game, and so does Athena 2.0 (character 27), whom the game keeps at level 1. A character at 0 HP gets the EXP but no level, since the game's level-up wants HP: the bar stays full (EXP over it is cut) and the level comes with the next EXP once the character has HP. rq.chara.on_level_up runs for each level, with free false.

Raises an error for a slot with no character, for an amount that is not a whole number of 0 or more, and at the top level of a mod.

lua
local iic = rq.party.get()[1]
local gained = rq.chara.add_exp(iic, 500)
rq.log("levels gained: " .. gained)
ParameterTypeDescription
iicintegerThe character's roster slot.
nintegerThe EXP to add, 0 or more.
ReturnsTypeDescription
gainedintegerThe levels gained; 0 at the cap.

See also: rq.chara.level_up

rq.chara.level_up ​

lua
rq.chara.level_up(iic, n) -> integer

since 2.33.0

Raises a character's level for free, as the game's story and training do.

Uses the game's free level-up (レベルアップ処理): the stats grow and the EXP goes back to 0 for the new level. It stops at level_max, also for a character with uncapped, as the game's own does, and Athena 2.0 (character 27) stays at level 1. rq.chara.on_level_up runs for each level, with free true.

Raises an error for a slot with no character, for a count that is not a whole number of 1 or more, and at the top level of a mod.

lua
rq.chara.level_up(iic, 5)  -- five levels, or fewer at the cap
ParameterTypeDescription
iicintegerThe character's roster slot.
n (optional)integerThe levels to add, 1 or more. Default 1.
ReturnsTypeDescription
gainedintegerThe levels gained; fewer than n at the cap.

See also: rq.chara.add_exp

Events ​

NameSummary
rq.chara.on_recalcCalls fn after the game recalculates a character (C再計算).
rq.chara.on_offerCalls fn after the game filled a character's skill buy list, to add rows.
rq.chara.on_createCalls fn after any character is created (C生成), base game or mod.
rq.chara.on_forgetCalls fn before a skill row is emptied, to give skill points back.
rq.chara.on_learnCalls fn after each skill purchase, once per step.
rq.chara.on_skill_resetCalls fn after the game resets a character's skills, to give back what a mod gave.
rq.chara.on_has_skillCalls fn when the game checks whether a character has one skill, to answer "no".
rq.chara.on_level_upCalls fn after a character goes up a level, whatever gave it.

rq.chara.on_recalc ​

lua
rq.chara.on_recalc(fn) -> fun()

since 0.2.0 changed 0.14.0 changed 0.23.0 changed 2.35.0 changed 2.66.0

Calls fn after the game recalculates a character (C再計算).

Up to 16 callbacks in all.

The loader also recalculates inside its tries (rq.chara.learnable's after, rq.chara.price), on a character it puts back after: preview is true there. Whatever fn changes on the character is undone with it; a callback that writes elsewhere (rq.store, a log) can skip a preview.

lua
rq.chara.on_recalc(function(iic, preview)
  if rq.chara.weapon_detail(iic) == 7 then rq.chara.apply_mod(iic, 8, 10) end  -- spear: accuracy
end)
ParameterTypeDescription
fnfun(iic: integer, preview: boolean)Gets the character's roster slot, and whether it runs inside a try.
ReturnsTypeDescription
removefun()Removes this callback.

Changed in 0.14.0: Every mod's callback runs (before, the last one won).

Changed in 0.23.0: Returns a remover.

Changed in 2.35.0: Places its hook itself; before, it needed rq.chara.install.

Changed in 2.66.0: The second argument, preview.

rq.chara.on_offer ​

lua
rq.chara.on_offer(fn) -> fun()

since 0.2.0 changed 0.13.0 changed 0.23.0 changed 2.66.0

Calls fn after the game filled a character's skill buy list, to add rows.

fn returns nil, one rq.Offer, or a list of them. Each row goes through the game's own level check (スキルレベル制限表示). Up to 16 callbacks in all. Since 2.35.0 it places its hook itself. A list made inside one of the loader's tries has ctx.preview true.

lua
rq.chara.on_offer(function(ctx)
  if ctx.class == 4 then return { skill = 246, cost = 2, level = 10, points = 3 } end
end)
ParameterTypeDescription
fnfun(ctx: rq.OfferCtx ): rq.Offer | rq.Offer []|nilReturns the rows to add.
ReturnsTypeDescription
removefun()Removes this callback.

Changed in 0.13.0: Every mod's callback runs (before, the last one won); a list adds several rows; added points.

Changed in 0.23.0: Returns a remover.

Changed in 2.66.0: ctx.preview.

rq.chara.on_create ​

lua
rq.chara.on_create(fn) -> fun()

since 0.4.0 changed 0.23.0

Calls fn after any character is created (C生成), base game or mod.

The engine then recalculates and heals the character. Up to 16 callbacks in all.

ParameterTypeDescription
fnfun(ctx: rq.CreateCtx )Gets the new character.
ReturnsTypeDescription
removefun()Removes this callback.

Changed in 0.23.0: Returns a remover.

rq.chara.on_forget ​

lua
rq.chara.on_forget(fn) -> fun()

since 0.4.0 changed 0.23.0 changed 2.45.0 changed 2.48.0 changed 2.51.0 changed 2.52.0

Calls fn before a skill row is emptied, to give skill points back.

The points every callback returns are added up and given to the character. When preview is true, rq.chara.forget_points is asking what the callback would give: count, and change nothing else. player tells the erasures the player chose (the skill window's ERASE, and a mod's rq.chara.forget with player = true) from the game's other removals (its recalculation, the story, the reset) and a mod's own; caller names the AIN function, or "lua". kept tells a Boost whose effect the character keeps once it is erased (rq.chara.boosts), so its points were not lost. Up to 16 callbacks in all.

lua
-- Half the points back for each erasure the player chose.
rq.chara.on_forget(function(ctx)
  if ctx.player and ctx.cost > 0 then return ctx.cost // 2 end
end)
ParameterTypeDescription
fnfun(ctx: rq.ForgetCtx ): integer|nilReturns the points to give back.
ReturnsTypeDescription
removefun()Removes this callback.

Changed in 0.23.0: Returns a remover.

Changed in 2.45.0: cost is the purchase record.

Changed in 2.48.0: kept.

Changed in 2.51.0: player and mod.

Changed in 2.52.0: n and preview; rq.chara.forget_points calls the callbacks with preview.

rq.chara.on_learn ​

lua
rq.chara.on_learn(fn) -> fun()

since 2.45.0

Calls fn after each skill purchase, once per step.

It runs for the skill window's buy and upgrade, and for each step of rq.chara.learn, after the loader wrote the purchase record. The tutorial's purchases count too.

lua
rq.chara.on_learn(function(ctx)
  rq.log(("%d paid %d for skill %d"):format(ctx.iic, ctx.points, ctx.skill))
end)
ParameterTypeDescription
fnfun(ctx: rq.LearnCtx )Gets the purchase. Its return value is not used.
ReturnsTypeDescription
removefun()Removes this callback.

See also: rq.chara.on_forget

rq.chara.on_skill_reset ​

lua
rq.chara.on_skill_reset(fn) -> fun()

since 2.46.0

Calls fn after the game resets a character's skills, to give back what a mod gave.

The game resets them (Cスキルドレイン) for Morurun's reset and when Skill Again (item 306) is equipped: the skills become the starting set (rq.chara.base_skills) and the free points the game's own count, so the skills and points a mod gave are gone. fn can give the points back with rq.chara.add_skill_points; skills from edit's learn come back by themselves at the next recalculation.

A callback's error is logged once per mod.

lua
rq.chara.on_skill_reset(function(ctx)
  if ctx.no == 27 then rq.chara.add_skill_points(ctx.iic, rq.savedata.get("given", 0)) end
end)
ParameterTypeDescription
fnfun(ctx: rq.SkillResetCtx )Gets the character. Its return value is not used.
ReturnsTypeDescription
removefun()Removes this callback.

See also: rq.chara.base_skills

rq.chara.on_has_skill ​

lua
rq.chara.on_has_skill(skill, fn) -> fun()

since 2.55.0

Calls fn when the game checks whether a character has one skill, to answer "no".

The game's checks for a skill go through one function, CS番号取得: the stats (C再計算), battles, scenes and event conditions, and the party checks (CS有無/スタメン). fn returns false to answer that the character does not have the skill, for this one check, or nil to keep the game's answer. The skill row stays: the skill window, the status page and rq.chara.slots still show it. A check from one place only (ctx.caller) keeps the skill everywhere else: a character can keep a skill that scenes look for and lose what it does to the stats. After a change in the answer for stats, call rq.chara.recalc.

The callbacks run only for checks of skill (an rq.ain.hook with only), so a check of another skill costs Lua nothing; the game checks skills many times a frame in a battle, so keep fn short. chara, row and caller are worked out when a callback first reads them.

A callback's error, or a return other than false or nil, is logged once per mod and changes nothing.

Raises an error when skill is not a whole number from 1 to 1000, or fn is not a function.

lua
-- Immature (373) takes nothing off Kouhime's stats (character 20); scenes still see it.
rq.chara.on_has_skill(373, function(ctx)
  if ctx.chara == 20 and ctx.caller == "C再計算" then return false end
end)
ParameterTypeDescription
skillintegerThe skill number, 1 to 1000.
fnfun(ctx: rq.HasSkillCtx ): false|nilReturns false for "no", or nil.
ReturnsTypeDescription
removefun()Removes this callback.

See also: rq.chara.slots

rq.chara.on_level_up ​

lua
rq.chara.on_level_up(fn) -> fun()

since 2.33.0

Calls fn after a character goes up a level, whatever gave it.

It runs for the game's level-ups (a fight's result, the story, training, the reserve's share) and for rq.chara.add_exp and level_up, once per level. The game shows its own level-up on the result screen; this only tells a mod. An error is logged once for each new error text.

lua
rq.chara.on_level_up(function(ctx)
  if ctx.level % 10 == 0 then rq.chara.add_skill_points(ctx.iic, 1) end
end)
ParameterTypeDescription
fnfun(ctx: rq.LevelUpCtx )Runs after each level.
ReturnsTypeDescription
removefun()Removes this callback.