Difference between revisions of "User:AVS/Scripting"
From VCMI Project Wiki
< User:AVS
(→VCMI) |
(→Low level events API) |
||
(10 intermediate revisions by the same user not shown) | |||
Line 34: | Line 34: | ||
= Lua = | = Lua = | ||
+ | == API Reference == | ||
+ | {{todo}} '''In near future Lua API may change drastically several times. Information here may be outdated''' | ||
+ | === Globals === | ||
+ | * DATA - persistent table | ||
+ | ** DATA.ERM contains ERM state, anything else is free to use. | ||
+ | * GAME - IGameInfoCallback API | ||
+ | * BATTLE - IBattleInfoCallback API | ||
+ | * EVENT_BUS - opaque handle, for use with events API | ||
+ | * SERVICES - root "raw" access to all static game objects | ||
+ | ** SERVICES:artifacts() | ||
+ | ** SERVICES:creatures() | ||
+ | ** SERVICES:factions() | ||
+ | ** SERVICES:heroClasses() | ||
+ | ** SERVICES:heroTypes() | ||
+ | ** SERVICES:spells() | ||
+ | ** SERVICES:skills() | ||
+ | * require(URI) | ||
+ | ** works similar to usual Lua require | ||
+ | ** require("ClassName") - loads additional API and returns it as table (for C++ classes) | ||
+ | ** require("core:relative.path.to.module") - loads module from "SCRIPTS/LIB" | ||
+ | ** {{todo}} require("modName:relative.path.to.module") - loads module from dependent mod | ||
+ | ** {{todo}} require(":relative.path.to.module") - loads module from same mod | ||
+ | * logError(text) - backup error log function | ||
+ | === Low level events API === | ||
+ | |||
+ | <syntaxhighlight lang="Lua"> | ||
+ | |||
+ | -- Each event type must be loaded first | ||
+ | local PlayerGotTurn = require("events.PlayerGotTurn") | ||
+ | |||
+ | -- in this example subscription handles made global, do so if there is no better place | ||
+ | -- !!! do not store them in local variables | ||
+ | sub1 = PlayerGotTurn.subscribeAfter(EVENT_BUS, function(event) | ||
+ | --do smth | ||
+ | end) | ||
+ | |||
+ | sub2 = PlayerGotTurn.subscribeBefore(EVENT_BUS, function(event) | ||
+ | --do smth | ||
+ | end) | ||
+ | |||
+ | </syntaxhighlight> | ||
+ | |||
+ | === Lua standard library === | ||
+ | VCMI uses LuaJIT, which is Lua 5.1 API, see [https://www.lua.org/manual/5.1/manual.html upstream documentation] | ||
+ | |||
+ | Following libraries are supported | ||
+ | * base | ||
+ | * table | ||
+ | * string | ||
+ | * math | ||
+ | * bit | ||
+ | |||
= ERM = | = ERM = | ||
== Features == | == Features == | ||
+ | * no strict limit on function/variable numbers (technical limit 32 bit integer except 0)) | ||
* {{todo}} semi compare | * {{todo}} semi compare | ||
* {{done}} macros | * {{done}} macros | ||
Line 43: | Line 96: | ||
== Triggers == | == Triggers == | ||
− | * {{todo}} '''!?AE''' | + | * {{todo}} '''!?AE''' Equip/Unequip artifact |
− | * {{wip}} '''!?BA''' | + | * {{wip}} '''!?BA''' when any battle occurs |
− | * {{wip}} '''!?BF''' | + | * {{wip}} '''!?BF''' when a battlefield is prepared for a battle |
− | * {{todo}} '''!?BG''' | + | * {{todo}} '''!?BG''' at every action taken by any stack or by the hero |
− | * {{todo}} '''!?BR''' | + | * {{todo}} '''!?BR''' at every turn of a battle |
− | * | + | * ''!?CM (client only) click the mouse button.'' |
− | * {{todo}} '''!?CO''' | + | * {{todo}} '''!?CO''' Commander triggers |
− | * {{todo}} '''!?DL''' | + | * {{todo}} '''!?DL''' Custom dialogs |
− | * {{done}} '''!?FU''' | + | * {{done}} '''!?FU''' function |
− | * {{todo}} '''!?GE''' | + | * {{todo}} '''!?GE''' "global" event |
− | * {{todo}} '''!?GM''' | + | * {{todo}} '''!?GM''' Saving/Loading |
− | * {{todo}} '''!?HE''' | + | * {{todo}} '''!?HE''' when the hero # is attacked by an enemy hero or visited by an allied hero |
− | * {{todo}} '''!?HL''' | + | * {{todo}} '''!?HL''' hero gains a level |
− | * {{todo}} '''!?HM''' | + | * {{todo}} '''!?HM''' every step a hero # takes |
− | * | + | * ''!?IP Multiplayer support. '' |
− | * {{todo}} '''!?LE''' (!$LE) | + | * {{todo}} '''!?LE''' (!$LE) An Event on the map |
− | * {{wip}} '''!?MF''' | + | * {{wip}} '''!?MF''' stack taking physical damage(before an action) |
− | * {{todo}} '''!?MG''' | + | * {{todo}} '''!?MG''' casting on the adventure map |
− | * ''!?MM | + | * ''!?MM scroll text during a battle '' |
− | * {{todo}} '''!?MR''' | + | * {{todo}} '''!?MR''' Magic resistance |
− | * {{todo}} '''!?MW''' | + | * {{todo}} '''!?MW''' Wandering Monsters |
− | * {{wip}} '''!?OB''' (!$OB) | + | * {{wip}} '''!?OB''' (!$OB) visiting objects |
− | * {{done}} '''!?PI''' | + | * {{done}} '''!?PI''' Post Instruction. |
− | * {{todo}} '''!?SN''' | + | * {{todo}} '''!?SN''' Sound and ERA extensions |
− | * ''!?TH | + | * ''!?TH town hall'' |
− | * {{todo}} '''!?TL''' | + | * {{todo}} '''!?TL''' Real-Time Timer |
− | * {{todo}} '''!?TM''' | + | * {{todo}} '''!?TM''' timed events |
== Receivers == | == Receivers == | ||
=== VCMI === | === VCMI === | ||
− | * !!MC:S@varName@ - declare new "normal" variable (technically v-var with string key) | + | * '''!!MC:S@varName@''' - declare new "normal" variable (technically v-var with string key) |
− | |||
* {{todo}} Identifier resolver | * {{todo}} Identifier resolver | ||
* {{wip}} Bonus system | * {{wip}} Bonus system | ||
− | |||
=== ERA === | === ERA === |
Latest revision as of 21:55, 11 May 2020
Contents
Configuration
{
//general purpose script, Lua or ERM, runs on server
"myScript":
{
"source":"path/to/script/with/ext",
"implements":"ANYTHING"
},
//custom battle spell effect, Lua only, runs on both client and server
//script ID will be used as effect 'type' (with mod prefix)
"mySpellEffect":
{
"source":"path/to/script/with/ext",
"implements":"BATTLE_EFFECT"
},
//TODO: object|building type
//custom map object or building, Lua only, runs on both client and server
//script ID will be used as 'handler' (with mod prefix)
"myObjectType":
{
"source":"path/to/script/with/ext",
"implements":"MAP_OBJECT"
},
//TODO: server query
//TODO: client query
}
Lua
API Reference
[Todo] In near future Lua API may change drastically several times. Information here may be outdated
Globals
- DATA - persistent table
- DATA.ERM contains ERM state, anything else is free to use.
- GAME - IGameInfoCallback API
- BATTLE - IBattleInfoCallback API
- EVENT_BUS - opaque handle, for use with events API
- SERVICES - root "raw" access to all static game objects
- SERVICES:artifacts()
- SERVICES:creatures()
- SERVICES:factions()
- SERVICES:heroClasses()
- SERVICES:heroTypes()
- SERVICES:spells()
- SERVICES:skills()
- require(URI)
- works similar to usual Lua require
- require("ClassName") - loads additional API and returns it as table (for C++ classes)
- require("core:relative.path.to.module") - loads module from "SCRIPTS/LIB"
- [Todo] require("modName:relative.path.to.module") - loads module from dependent mod
- [Todo] require(":relative.path.to.module") - loads module from same mod
- logError(text) - backup error log function
Low level events API
-- Each event type must be loaded first
local PlayerGotTurn = require("events.PlayerGotTurn")
-- in this example subscription handles made global, do so if there is no better place
-- !!! do not store them in local variables
sub1 = PlayerGotTurn.subscribeAfter(EVENT_BUS, function(event)
--do smth
end)
sub2 = PlayerGotTurn.subscribeBefore(EVENT_BUS, function(event)
--do smth
end)
Lua standard library
VCMI uses LuaJIT, which is Lua 5.1 API, see upstream documentation
Following libraries are supported
- base
- table
- string
- math
- bit
ERM
Features
- no strict limit on function/variable numbers (technical limit 32 bit integer except 0))
- [Todo] semi compare
- [Done] macros
Bugs
- [Todo] Broken XOR support (clashes with `X` option)
Triggers
- [Todo] !?AE Equip/Unequip artifact
- [WiP] !?BA when any battle occurs
- [WiP] !?BF when a battlefield is prepared for a battle
- [Todo] !?BG at every action taken by any stack or by the hero
- [Todo] !?BR at every turn of a battle
- !?CM (client only) click the mouse button.
- [Todo] !?CO Commander triggers
- [Todo] !?DL Custom dialogs
- [Done] !?FU function
- [Todo] !?GE "global" event
- [Todo] !?GM Saving/Loading
- [Todo] !?HE when the hero # is attacked by an enemy hero or visited by an allied hero
- [Todo] !?HL hero gains a level
- [Todo] !?HM every step a hero # takes
- !?IP Multiplayer support.
- [Todo] !?LE (!$LE) An Event on the map
- [WiP] !?MF stack taking physical damage(before an action)
- [Todo] !?MG casting on the adventure map
- !?MM scroll text during a battle
- [Todo] !?MR Magic resistance
- [Todo] !?MW Wandering Monsters
- [WiP] !?OB (!$OB) visiting objects
- [Done] !?PI Post Instruction.
- [Todo] !?SN Sound and ERA extensions
- !?TH town hall
- [Todo] !?TL Real-Time Timer
- [Todo] !?TM timed events
Receivers
VCMI
- !!MC:S@varName@ - declare new "normal" variable (technically v-var with string key)
- [Todo] Identifier resolver
- [WiP] Bonus system
ERA
- [Done] !!if !!el !!en
- [Todo] !!br !!co
- [Todo] !!SN:X
WoG
- [Todo] !!AR Артефакт (ресурс) в определенной позиции
- [Todo] !!BA Битва
- !!BA:A$ return 1 for battle evaluation
- [Todo] !!BF Препятствия на поле боя
- [Todo] !!BG Действий монстров в бою
- [Todo] !!BH Действия героя в бою
- [Todo] !!BM Монстр в битве
- [WiP] !!BU Универсальные параметры битвы
- [Todo] !!CA Замок
- [Todo] !!CD Разрушения замков
- [Todo] !!CE События в замке
- [Todo] !!CM Клика мышью
- [Todo] !!DL Нестандартный диалог (только ТЕ или выше)
- [Todo] !!CO Командиры
- [WiP] !!DO Многократный вызов функции
- [Todo] !!EA Бонусы опыта существ
- [Todo] !!EX Опыт стека
- [Done] !!FU Однократный вызов функции
- [Todo] !!GE Глобальное событие
- [WiP] !!HE Герой
- [Todo] !!HL Новый уровень героя
- [Todo] !!HO Взаимодействия героев
- [Todo] !!HT Подсказки по правому клику
- [WiP] !!IF Диалоги и флагов
- [Todo] !!IP Сетевой сервис битвы
- [Todo] !!LE Локальное события
- [WiP] !!MA Общие параметры монстров
- [Done] !!MC Макросы
- [WiP] !!MF Получение физ. урона в бою
- [Todo] !!MM Текст в битве
- [WiP] !!MO Монстр в определенной позиции
- [Todo] !!MP Контроль MP3
- [Todo] !!MR Сопротивления магии
- [Todo] !!MW Бродячих монстров
- [WiP] !!OB Объект в определенной позиции
- [Todo] !!OW Параметры игрока
- [Todo] !!PM Пирамиды или новые объекты
- [Todo] !!PO Информация квадрата карты
- [Todo] (???) !!QW Журнала
- [Todo] !!SN Проигрываемые звуков
- [Todo] !!SS Настройка заклинаний (только ТЕ или выше)
- [Todo] !!TL Контроль времени хода (только ТЕ или выше)
- [Todo] !!TM Временный таймер
- [Todo] !!TR Квадрата карты (почва, проходимость, т.п.)
- [Todo] !!UN Универсальная команда
- !#VC Контроль переменных
- [WiP] !!VR Установка переменных