Math

From FetishQuest Wiki
Revision as of 00:04, 18 February 2025 by JasX (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The math system in FQ is pretty powerful, and is gradually receiving additional functions which allows you to use it for custom scripts. If a field states that it's a formula, then it uses the math system. The system is based on math.js and all features are supported in FQ, plus a few extras. For an instance, if a field supports a formula, then typing 3+2 into the field would evaluate to 5. Not very useful, but it becomes useful when you use math vars.

Math Vars

Math vars are variables you can reference. The available vars depend on the game event that caused the formula to be evaluated (if any). For an instance, you could use 5/g_team_1 as a formula to divide 5 by the nr of players on team 1.

Game vars (always available):

Var Explanation
g_rain Amount of rain, between 0 and 1.
g_sod Nr of seconds into the current day.
g_team_n Nr of players on team n (like g_team_0 etc)
g_time Time in seconds since the game started (in-game time, any action will affect time)

Dungeon vars (Always available):

Dungeon vars all use the formula: d_<dungeonLabel>_<dVarLabel>

For an instance: the dungeon yuug_portswood_cave has the dungeon var exit_found. You'd reference it by d_yuug_portswood_cave_exit_found.

You can also use %d to automatically target the current dungeon, like %d_exit_found instead of d_yuug_portswood_cave_exit_found.

Factions

Factions all use the formula: f_<factionLabel> such as fac_rattani for the rattani faction value. See the faction help in the editor for more info.

Quests

Currently quest vars only store information about when they were completed (game time): q_<questLabel>__time

RP

Var Explation
rp_targs Nr of RP targs in active roleplay.
rp_<rpLabel>_<rpVar> Fetch an RP var from any RP. Note: To use this, the RP must be set as rpVars Persistent.

You can also use %rp for short to target the currently active roleplay. Such as %rp_var instead of rp_borm_tavern_mayah_var

Players

If a sender is in the event, their mathvars (see Player.js function appendMathVars for a full list) are added with the prefix se_ - If there's a target, they're added with the prefix ta_

Here's a list of mathvars for the players, though don't expect this to be up to date, check the code!

se_ or ta_ is prepended to the var
Var Explanation
SvPhysical Physical avoidance.
SvArcane Arcane avoidance.
SvCorruption Corruption avoidance.
BonPhysical Physical proficiency.
BonArcane Arcane proficiency.
BonCorruption Corruption proficiency.
Lv Player level.
HP Player HP.
Off Player offensive momentum.
Def Player defensive momentum.
Uti Player utility momentum.
tReroll Rerolls used this turn.
Mom Total momentum.
Arousal Arousal.
Team Team.
Size Size.
TeamPlayers Nr players on team (including player).
MaxHP Max HP.
MaxArousal Max arousal.
Money Money in copper.
apSpentThisTurn Momentum spent this turn.
actionUsedThisTurn Nr actions used this turn.
stdCombo Legacy.
aTypes Nr action types used this turn (physical/arcane/corruption), 0-3
ButtSize
BreastSize
PenisSize
Turns Turns taken this battle.
SecondWindUsed Nr second winds used this battle.
SecondWindActive Second wind is active.
SecondWindMax Max second winds for the player.
Talkative
Sadistic
Dominant
Hetero
Emotive
Intelligence
Casting 1 if charging an ability.
UntappedBlock Amount of block that fell off last turn.
Block Amount of block for the player.
Tag_<tag> All tags active on the player. Value is always 1.
damagingReceivedSinceLast Nr damaging attacks received since their last turn start.
damageReceivedSinceLast Damage received since their last turn start.
damagingDoneSinceLast Nr damaging actions used since their last turn start.
damageDoneSinceLast Points of damage done since their last turn start.
healingActionsDoneSinceLast Nr healing actions done since their last turn start.
healingPointsDoneSinceLast Healing points done since their last turn start.
healingActionsReceivedSinceLast Nr healing actions received since their last turn start.
healingPointsReceivedSinceLast Nr healing points received since their last turn start.
ripostedSinceLast Attacks by the player that were riposted since last turn start.
ripostingSinceLast Attacks by another player that this player riposted since last turn start.
missedSinceLast Attacks missed by the player since last turn start.
missingSinceLast Attacks against the player that missed since their last turn start.
NumMajor Num major effects on the player.
Major Bitwise combination of major effects.
LARange Range of the last action used, Action.Range value.
LAType Type of last action used (corruption,arcane,phys). Action.Types value.
NumTaunts Nr players the player is taunting.
targetedSinceLast Nr times the player was targeted by direct actions since their last turn start.
damagingReceivedSinceLast<type> Same as above, but filtered to a specific Action.Type
damageReceivedSinceLast<type>
damagingDoneSinceLast<type>
damageDoneSinceLast<type>
Action_<label> Set for each active action that the player holds. All values are 1.
CDActions Nr actions on cooldown.
<armorSlot> Nr items equipped to this slot.
Wrapper_<label> Nr stacks for each wrapper applied to player provided it has a label.
IF PLAYER IS TARGET IN EVENT
se_TaDamagingReceivedSinceLast Damaging abilities received since player's last turn by the event sender.
se_TaDamageReceivedSinceLast Damage the sender has done to us since player's last turn.
se_TaHealingActionsReceivedSinceLast Same but for healing
se_TaHealingPointsReceivedSinceLast Same but for healing
Crit_se Player's crit chance on sender
GrappledByS 1 if player is grappled by sender.
AwareOfS 1 if player is aware of sender
Wrapper_<label>_se Nr stacks of a wrapper, but only by sender in event.
IF PLAYER IS SENDER IN EVENT
Crit_ta Player crit chance on target.
ta_SeDamagingReceivedSinceLast Damaging abilities received by target since player's last turn.
ta_SeDamageReceivedSinceLast Damage points received by target since player's last turn.
ta_SeHealingActionsReceivedSinceLast Same but for healing
ta_SeHealingPointsReceivedSinceLast Same but for healing.
GrappledByT Player is grappled by target
Wrapper_<label>_ta Nr stacks of a wrapper, but only by target in event.

Action

Requires action to be present in the event.

Var Explanation
ac_Off Offensive momentum cost.
ac_Def Defensive momentum cost.
ac_Uti Utility momentum cost.
ac_CT Cast-time.
ac_CD Cooldown.

Advanced Formulas

Use @@ to get player vars

RP & Dungeon vars are allowed to be mapped to individual players. These are generally better used for texts, but can be used with math too. To fetch these, you can use the syntax @@<mathVar>_<operation> where mathVar should be a mathVar that's individually mapped (see targets of the setRpVar GameAction). And operation is one of the following:

In these examples, assume we have a roleplay labeled "favoriteColorLocal" that sets an rpVar for individual players. Let's assume the following RP vars: { "favoriteColor" : { "playerA":"red", "playerB":"green" }, "timesTickled" : { "playerA":5, "playerB":0, "playerC":5 } }
Operation Example Output Explanation
_TargetN @@rp_favoriteColorLocal_favoriteColor_Target0 "red" Fetches the favoriteColor value for the first target in the event. Ex "red" if player 1 was target1.
_Set[<separator>] @@rp_favoriteColorLocal_favoriteColor_Set[ and ] "red and green" A: Fetches the favoriteColor values for all targets in the event and returns a string with the colors separated by " and "
_SetSum @@rp_favoriteColorLocal_favoriteColor_SetSum 10 Fetches the sum of all player entries for that mathVar.
_SetNum @@rp_favoriteColorLocal_favoriteColor_SetNum 2 Fetches the number of players who have a non-falsy values set.
_Set_<key>[<separator>][<tAppend>] @@rp_favoriteColorLocal_favoriteColor_Set_T[ and ]

@@rp_favoriteColorLocal_favoriteColor_Set_T[, ][: ]

"playerA and playerB"

"playerA: red, playerB: green"

Fetches information about the player itself, and optionally about their values, separated by separator. If you use two separators, the second will separate the key and value.

Key is a text tag. Such as if you were to use %Trace in a text, you'd enter Trace here. For an instance @@rp_label_var_Set_Trace[, ] would get all species of players with values set to non-falsy values, separated by a comma.

Note: If you want to stringify numerical outputs, such as 10 -> ten, use @@!

Functions

FQ extends Math.js with a couple of functions, allowing you to use the math system as a scripting language:

Function Example Description
debug(data) debug("Test") Creates a console.trace
shuffle(array) shuffle([1,2,3]) -> [3,1,2] etc Shuffles an array
setDvar(dungeonLabel, varName, val, targ, operation="SET") setDvar("myDungeon", "leverPulled", 1) Creates a GameAction of the setDvar type pointed at dungeonLabel.varName with val, and executes it.

targ can be a value from Calculator. Targets or set to a falsy value (such as an empty string) to not create user-specific vars. You're allowed to set val to an array. Note that if you want to set a dvar to a string, you must prepend the value with "$$", such as concat("$$",myValue)

setRpVar(varName, val, targ, operation="SET") setRpVar("favoriteColor", "$$red", "Target0") Creates a GameAction of the setRpVar type pointed at the current active RP varName with val, and executes it. Note that value is always converted to a number unless you start it with $$ to mark it as a string or it's an array.

targ can be a value from Calculator.Targets or set to a falsy value (such as an empty string) to not create user-specific vars. *You're allowed to set val to an array, but it only supports the SET operation.

getDvar(dungeonLabel, varName) getDvar("myDungeon","leverPulled") Fastest way of getting a dvar, and supports array return types.

* Arrays can only use the SET operation. You can only access array values through a formula. Ex if you do setDvar("myDungeon","myVar",[1,2,3]) you can fetch it with d_myDungeon_myVar[1]. Note that math.js arrays start from 1.

Calculator.Targets (may be out of date):

  • Targets : Event sender
  • Sender : Event sender event sender
  • TargetN : Specific target of the event such as Target0
  • RpTargetN : Specific RP target by N
  • RpTargets : All RP targets.
  • Set : All players who has a non-falsy value set in the specified rpVar
  • TeamN : N is a number such as Team0 for all players.