LuaGuide.wiki
author vittorio.giovara@gmail.com
Sun, 14 Nov 2010 22:29:50 +0000
changeset 33 397cb8bbddde
parent 32 5f66adfa478c
child 35 532bb2509f0b
permissions -rw-r--r--
Edited wiki page BuildingOnMac through web user interface.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
19a3182cac9d Created wiki page through web user interface.
henrik.rostedt
parents:
diff changeset
     1
#summary Guide to writing Lua scripts in Hedgewars.
19a3182cac9d Created wiki page through web user interface.
henrik.rostedt
parents:
diff changeset
     2
31
e713a5d2a7f9 Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 30
diff changeset
     3
= Under Construction =
e713a5d2a7f9 Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 30
diff changeset
     4
30
43e5101de029 Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 29
diff changeset
     5
This is both an introduction to Lua scripting in Hedgewars and a guide for more advanced control over the game and gears.
43e5101de029 Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 29
diff changeset
     6
43e5101de029 Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 29
diff changeset
     7
== What is a Lua script ==
29
19a3182cac9d Created wiki page through web user interface.
henrik.rostedt
parents:
diff changeset
     8
30
43e5101de029 Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 29
diff changeset
     9
A Lua script is used to make the game behave different by giving the Hedgewars engine different command. The script gets called by the engine on different events and the script tells the engine what to do.
43e5101de029 Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 29
diff changeset
    10
32
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    11
Missions and Training are the parts of Hedgewars that are scripted. Try them out and get a feel of what scripted maps is.
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    12
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    13
== The basic structure ==
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    14
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    15
Dependent on what type of script you want to write the requirements are a bit different, but before we go into that we must first create the .lua file.
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    16
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    17
If you want to make a Mission for multi player you create a map and create a new file map.lua in the map's folder.
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    18
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    19
If you want to make a Training or Campaign (coming) then you create a new .lua file in the appropriate folder under Missions in the Data folder.
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    20
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    21
The .lua file should be structured like this:
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    22
{{{
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    23
function onGameInit()
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    24
end
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    25
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    26
function onAmmoStoreInit()
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    27
end
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    28
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    29
function onGameStart()
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    30
end
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    31
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    32
function onGameTick()
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    33
end
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    34
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    35
function onGearAdd(gear)
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    36
end
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    37
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    38
function onGearDelete(gear)
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    39
end
5f66adfa478c Edited wiki page LuaGuide through web user interface.
henrik.rostedt
parents: 31
diff changeset
    40
}}}