User:AVS/Scripting

From VCMI Project Wiki
< User:AVS
Revision as of 19:59, 5 May 2020 by AVS (talk | contribs) (Features)
Jump to: navigation, search

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

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 Установка переменных

Persistence