sf2.ai
Tactics control how an opponent chooses what to do. Register a tactic (a native template with your own scoring, or a Lua on_decide function) and give its name to a fighter definition. Get sf2 with local sf2 = require("sf2").
sf2.ai.register
Section titled “sf2.ai.register”Define an opponent tactic: a native template with your own scoring tables, or a Lua decision function.
Signature: sf2.ai.register(definition)
Parameters
| Parameter | Type | Required |
|---|---|---|
definition |
TacticDefinition |
Required |
Fields of TacticDefinition
| Field | Type | Required | Meaning |
|---|---|---|---|
id |
string |
Required | — |
on_decide |
fun(memory:table,event:AiDecision): AiAction|"wait"|nil |
Optional | — |
type |
"tabular"|"random" |
Optional | — |
template |
string |
Optional | — |
memory |
TacticMemory |
Optional | — |
counter_attack |
TacticValue |
Optional | — |
dodge |
TacticValue |
Optional | — |
block |
TacticValue |
Optional | — |
safe_attack |
TacticValue |
Optional | — |
table_attack |
TacticValue |
Optional | — |
cautious_movement |
TacticValue |
Optional | — |
dodge_missiles |
TacticValue |
Optional | — |
dodge_magic |
TacticValue |
Optional | — |
animation_weights |
TacticWeight[] |
Optional | — |
quick_attacks |
TacticWeight[] |
Optional | — |
evades |
TacticWeight[] |
Optional | — |
expected_wait |
TacticWeight[] |
Optional | — |
Returns: A tactic handle.
When: Loading, before warriors that use it.
local training_ai = sf2.ai.register { id = "training_ai", type = "tabular", template = "Standard", memory = { strikes = 2, round_factor = 0.25 },}template names an existing tactic to inherit. Without one, the quick-attack and evade lists start empty and the opponent may have nothing to do. A weighted section you supply (animation_weights, quick_attacks, evades, expected_wait) replaces the inherited one, so an unsuitable list can leave the opponent unable to act. value entries are scores, not probabilities: start from a working template, change weights gradually and test in a fight. See AI.
sf2.ai.name
Section titled “sf2.ai.name”Get a tactic’s qualified ID as a string for use in a fighter or opponent.
Signature: sf2.ai.name(tactic)
Parameters
| Parameter | Type | Required |
|---|---|---|
tactic |
TacticHandle |
Required |
Returns: The qualified ID string.
When: Loading.
local tactic_name = sf2.ai.name(training_ai)-- Use tactic = tactic_name in a fighter or opponent table.Pass a handle from sf2.ai.register; strings are not accepted.