Expand description
The services of the standard plugin anvil-script (anvil_script.h).
anvil-script.effects (Effects, ADR 0008): effects of the
plugin’s own in EU4’s script language. A mod writes chisel_set_terrain = mountain in an event option, a decision or a scripted effect; the game
parses it as one of its own effects and, when it runs it, calls the
plugin’s handler with the value and the scope. Only an early plugin
(phase = "early") with affects_gameplay = true registers, and only in
its Plugin::load, before the game parses its first
effect. Keys are <owner>_<name>: the plugin’s id with - as _, lower
case. The handlers run where the game runs its own effects and tooltips
(the main thread, inside a command or the day), where
World answers WrongPhase. In multiplayer every
client runs its own copy of the effect, so execute must be
deterministic. While Anvil suspends the plugin, its effects do nothing.
anvil-script.day_end (DayEnd, ADR 0009): a callback at the Day
end, once a day after the game has finished the day (with its month and
year), on the main thread, when no worker thread of the day runs, before
the game compares checksums. Only a plugin with affects_gameplay = true
subscribes, and only before the first Day end of the process: in its
Plugin::load. The handler runs inside the game’s day command, where
World answers WrongPhase too, must be deterministic for multiplayer,
and is not called while Anvil suspends the plugin.
Depend on anvil-script in plugin.toml ([[dependencies]] id = "anvil-script", version = "^1.16" for the effects, "^1.18" for the Day
end) and look the services up with Effects::get and DayEnd::get.
use anvil::script::{Call, Effects};
let effects = Effects::get(host).expect("anvil-script.effects");
effects.register_with_tooltip(
host,
"hello_script_log",
|call: &Call<'_>| {
if let Some(host) = anvil::Host::current() {
host.log(anvil::LogLevel::Info, format_args!("{} in {:?}", call.value, call.province));
}
},
|call: &Call<'_>| Some(format!("Writes \"{}\" to anvil.log", call.value)),
)?;Structs§
- Call
- One execution or description of one effect: valid only during the call.
- Day
- The day that just ended: the date the game computed it for, which
anvil-game.dayreports after the frame. - DayEnd
- The
anvil-script.day_endservice. - Effects
- The
anvil-script.effectsservice.
Constants§
- EFFECTS_
SERVICE - The effects service’s name.
- EFFECTS_
VERSION - The effects service’s major version.
- SERVICE
- The Day end service’s name.
- VERSION
- The Day end service’s major version.