Messages : 2054 Quality Points : 814 Registration Date : 2014-12-12 Age : 28 Location : Tomsk, Russia
Subject: Scripting Maps 2015-07-21, 18:11
(This is a crosspost from the Project Ironfist wiki, see link)
(This post has an associated video tutorial. See Modding with an Iron Fist: Episode 2: Scripting)
Basics of Scripting
Every map in Project Ironfist can have an associated script file. Everything is possible with scripting, from changing player's heroes in ways you can't using only the map editor, to creating intricate quests for players to solve.
Scripting in Project Ironfist uses the Lua programming language, and is inspired by how scripting is done in Heroes V. This tutorial will show you how to get started creating basic map scripts. For general information on how to program in Lua, see the Lua tutorial, http://lua-users.org/wiki/ForTutorial See the Scripting Examples post for ideas on how to build scripts for your map, and the Scripting Documentation on the wiki for a reference on all available scripting features.
Making a Script File
After you create your map, you will need to find its filename. Go the the MAPS folder and find the corresponding file. Your script file must have that filename, plus the ".lua" suffix. For example, a map named "Sorrow's End" which uses features from the expansion will be saved in a file named "SorrowEn.MX2", and thus its corresponding script file must be named "SorrowEn.MX2.lua".
The root directory of our Project Ironfist installation should contain a "SCRIPTS" folder. If not, then create one. All script files should be placed in that folder.
An Example Script
Triggers are key to building scripts in Project Ironfist, as they allow you to attach your code to in-game events. You create new triggers by calling the Trigger function. Here's an example which causes a message box saying "Hello, world!" to appear at the start of the map.
Trigger(MAP_START, "", "say_hello");
fun say_hello() MessageBox("Hello, world!"); end;
The call to Trigger takes three arguments. The first denotes which trigger we are using. We chose the MAP_START trigger, which runs at the start of the map. The second argument is the empty string, as the MAP_START trigger, like most triggers, does not use it. The third argument is the name of the function that should be called when the trigger runs, which here is the say_hello function. Put together, this will cause the say_hello function to be called when the map starts, which will display a message box.
Last edited by Orzie on 2015-09-25, 06:14; edited 1 time in total