LuaLibraries.wiki
changeset 1329 bd781e19a52d
parent 1234 60346a2ffb4c
child 1330 d92ed3272533
equal deleted inserted replaced
1328:7c0b4029caa1 1329:bd781e19a52d
     1 #summary Libraries for writing Lua scripts in Hedgewars.
     1 #summary Overview of libraries for writing Lua scripts in Hedgewars
     2 
     2 
     3 = Lua libraries documentation =
     3 = Lua libraries documentation =
     4 
     4 
     5 == Introduction ==
     5 == Introduction ==
     6 
     6 Libraries in scripts in Hedgewars are Lua files that are used by many scripts to add a common function, as an example the `Locale` library that allows scripts to translate text. The variables in these files are not exposed to the script using it but all the functions can be called.
     7 Libraries in scripts in Hedgewars are lua files that are used by many scripts to add a common function, as an example the Locale library that allows scripts to translate text. The variables in these files are not exposed to the script using it but all the functions can be called.
       
     8 
     7 
     9 To use a library you only need to add one row at the top of the script:
     8 To use a library you only need to add one row at the top of the script:
    10 <code language="lua">HedgewarsScriptLoad("Scripts/<Library Name>.lua")</code>
     9 <code language="lua">HedgewarsScriptLoad("Scripts/<Library Name>.lua")</code>
    11 Where `<Library Name>` is replaced by the name.
    10 Where `<Library Name>` is replaced by the name.
    12 
    11 
    13 *Note*: In old scripts, you will find this line instead:
    12 *Note*: In ancient scripts, you might find this line instead:
    14 <code language="lua">loadfile(GetDataPath() .. "Scripts/<Library Name>.lua")()</code>
    13 <code language="lua">loadfile(GetDataPath() .. "Scripts/<Library Name>.lua")()</code>
    15 This does not work with new Hedgewars versions anymore and causes the script to break. You have to replace it with `HedgewarsScriptLoad`. *Calls to `loadfile` are one of the most common reasons why old scripts do not work in recent Hedgewars versions.*
    14 This does not work with new Hedgewars versions anymore and causes the script to break. Use `HedgewarsScriptLoad` instead.
    16 
    15 
    17 == Table of Contents ==
    16 == List of Lua libraries ==
    18 
    17 
    19 <wiki:toc max_depth="2" />
    18 * [LuaLibraryLocale Locale]
    20 == Locale ==
    19 * [LuaLibraryUtils Utils]
    21 
    20 * [LuaLibraryTracker Tracker]
    22 This library allows you to translate string and should be used whenever a script has text. It loads the appropriate locale file and check automatically.
    21 * [LuaLibraryAnimate Animate]
    23 
    22 * [LuaLibraryParams Params]
    24 ==== `loc(text)` ====
    23 * [LuaLibraryTargetPractice TargetPractice]
    25 
    24 * [LuaLibrarySpeedShoppa SpeedShoppa]
    26 Returns the localised string of `text` or, if it is not found, it returns `text`.
    25 * [LuaLibrarySimpleMission SimpleMission]
    27 
       
    28 In order for your text to be taken by the string collection tools (so the string becomes available for translation), you have to follow a few simple syntax rules:
       
    29 
       
    30  * `text` _must_ be entirely a literal string
       
    31  * The text _must_ be enclosed in double quotes
       
    32  * You _must_ use the exact character sequence “`loc("`” to initiate the text, no spaces in between are permitted
       
    33 
       
    34 Valid example:
       
    35 <code language="lua">
       
    36 AddCaption(loc("Hello World"))  -- Displays “Hello World” translated into your language
       
    37 </code>
       
    38 
       
    39 These are all _incorrect_ usages of the `loc` function:
       
    40 <code language="lua">
       
    41 local l
       
    42 l = loc( "Hello World")    -- Contains space
       
    43 l = loc ("Hello World")    -- Contains space
       
    44 l = loc('Hello World')     -- Not double quotes
       
    45 local str = "Hello World"
       
    46 l = loc(str)   -- Not a literal string
       
    47 l = loc(str .. ", how are you?")   -- Only partially a literal string
       
    48 </code>
       
    49 
       
    50 Note these examples do _not_ violate Lua syntax, it is in your responsibility to follow the syntax rules listed above.
       
    51 
       
    52 ==== `loc_noop(text)` (0.9.23) ====
       
    53 Just returns `text`. This function has the same syntax as `loc`. Like for `loc`, the text will be collected to be made available for translation.
       
    54 
       
    55 You can use this function if you want a make a string available for translation but don't want the string to be translated right now. This can come in handy if you need to store strings in variables and want do something like `loc(variable_name)` later.
       
    56 
       
    57 == Utils ==
       
    58 
       
    59 This library includes miscellaneous functions to use, they are all independent of each other and can be used everywhere.
       
    60 
       
    61 ==== `gearIsInBox(gear, x, y, w, h)` ====
       
    62 
       
    63 Returns whether the gear is inside (centre point of the gear) a box with x and y as the top left corner and having the width and height of w and h respectively.
       
    64 
       
    65 
       
    66 ==== `gearIsInCircle(gear, x, y, r, useRadius)` ====
       
    67 
       
    68 Returns whether the gear is inside a circle with x and y being the centre point and r being the radius of the circle. The boolean useRadius determine whether only the centre point of the gear will be used or the radius of the gear will be checked too.
       
    69 
       
    70 
       
    71 
       
    72 == Tracker ==
       
    73 
       
    74 This library is intended to be used if you need to keep track of gears. It can also keep track of teams and clans and as an extra functionality it can also store variables for a gear, team or clan.
       
    75 
       
    76 To set it up you need to add some hooks in different events. The hooks `trackGear` and `trackDeletion` to `onGearAdd` and `onGearDelete` respectively. It is strongly recommended to only track the gears you are interested in as, especially with snow on, the amount of gears can go up high and that will slow down the script. To keep track of teams you need to keep track of `gtHedgehog` and `gtResurrector` (if resurrection might be used) and add `trackTeams` to `onGameStart`.
       
    77 
       
    78 If you want to call a function on a couple of gears you will have to call the “`runOn`” functions. To these you will pass the function you want to be run as a variable to the function. The function must take a gear as a parameter, nothing else, for example:
       
    79 <code language="lua">function killall(gear)
       
    80     SetHealth(gear, 0)
       
    81 end
       
    82 
       
    83 function onGearDelete(gear)
       
    84     if GetGearType(gear) == gtTarget then
       
    85         runOnHogs(killall)
       
    86     end
       
    87 end</code>
       
    88 This will kill all hogs if a target is destroyed.
       
    89 
       
    90 To see a commented example of the tracker in use by a script you can look at
       
    91 [https://hg.hedgewars.org/hedgewars/file/default/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Random Weapons].
       
    92 
       
    93 === Tracking functions ===
       
    94 
       
    95 ==== `trackGear(gear)` ====
       
    96 
       
    97 Will keep track of the gear.
       
    98 
       
    99 
       
   100 ==== `trackDeletion(gear)` ====
       
   101 
       
   102 Will stop keeping track of the gear (gears not tracked will be ignored).
       
   103 
       
   104 
       
   105 ==== `trackTeams()` ====
       
   106 
       
   107 Will start the tracking of teams, clans and hedgehogs (hogs can be tracked without this).
       
   108 
       
   109 
       
   110 === “`runOn`” functions ===
       
   111 
       
   112 ==== `runOnGears(func)` ====
       
   113 
       
   114 Runs the function `func` on all gears.
       
   115 
       
   116 
       
   117 ==== `runOnHogs(func)` ====
       
   118 
       
   119 Runs the function `func` on all hedgehogs.
       
   120 
       
   121 
       
   122 ==== `runOnHogsInTeam(func, team)` ====
       
   123 
       
   124 Runs the function `func` on all hedgehogs in the specified team.
       
   125 
       
   126 
       
   127 ==== runOnHogsInOtherTeams(func, team) ====
       
   128 
       
   129 Runs the function `func` on all hedgehogs but those in the specified team.
       
   130 
       
   131 
       
   132 ==== `runOnHogsInClan(func, clan)` ====
       
   133 
       
   134 Runs the function `func` on all hedgehogs in the specified clan.
       
   135 
       
   136 
       
   137 ==== `runOnHogsInOtherClans(func, clan)` ====
       
   138 
       
   139 Runs the function `func` on all hedgehogs but those in the specified clan.
       
   140 
       
   141 
       
   142 === Variable functions ===
       
   143 
       
   144 _To be continued …_
       
   145 
       
   146 
       
   147 == Animate ==
       
   148 
       
   149 This library provides functions that aid cinematic/cut-scene creation and functions for handling events. 
       
   150 
       
   151 In order to use its full potential, the following lines need to be at the beginning of `onGameTick`.
       
   152 
       
   153 <code language="lua">function onGameTick()
       
   154     AnimUnWait()
       
   155     if ShowAnimation() == false then
       
   156         return
       
   157     end
       
   158     ExecuteAfterAnimations()
       
   159     CheckEvents()
       
   160 end</code>
       
   161 
       
   162 Also, `AnimInit()` needs to be called in `onGameInit()`.
       
   163 Each of these functions will be explained below.
       
   164 
       
   165 Note: The Animate library will direclty overwrite the input mask with `SetInputMask`. If you already use this function in your script, it might lead to conflicts. Use `AnimSetInputMask` to set the input mask in a manner that is compatible with the Animate library.
       
   166 
       
   167 === Cinematic handling ===
       
   168 
       
   169 ==== `ShowAnimation()` ====
       
   170 Performs the current action in the cinematic and returns `true` if finished, otherwise `false`. It needs to be used in `onGameTick`. Cut-scenes need to be added with `AddAnim(steps)`.
       
   171 
       
   172 ==== `AddAnim(steps)` ====
       
   173 Adds `steps` to the array of animations, where `steps` is a table with numbers as keys and elements of the following form. Each step is a table having the following keys: `func`, `args`, `swh`.
       
   174 
       
   175   * `func` is the function to be executed. It can be any function that returns false when it needs to be called again in following game ticks (e.g. `AnimMove`). It can be one of the cinematic functions. 
       
   176 
       
   177   * `args` is a table containing the arguments that need to be passed to the function given
       
   178 
       
   179   * `swh` is an optional boolean value that defaults to `true` and denotes whether the current hedgehog should be switched to the hog given as argument.
       
   180 Example:
       
   181 <code language="lua">cinem = {
       
   182     {func = AnimSay, args = {myHog, "Snails! SNAILS!", SAY_SAY, 3000}},
       
   183     {func = AnimMove, args = {myhog, "Left", 2000, 0}},
       
   184     {func = AddCaption, swh = false, args = {"But he found no more snails..."}}
       
   185     }
       
   186 AddAnim(cinem)</code>
       
   187 
       
   188 ==== `RemoveAnim(steps)` ====
       
   189 Removes `steps` from the animations array.
       
   190 
       
   191 ==== `AddSkipFunction(anim, func, args)` ====
       
   192 Adds `func` to the array of functions used to skip animations, associating it with `anim`. When the animation is skipped (see below), the function is called with `args` as arguments.
       
   193 Example:
       
   194 <code language="lua">AddSkipFunc(cinem, SkipCinem, {})</code>
       
   195 
       
   196 ==== `RemoveSkipFunction(anim)` ====
       
   197 Removes the skip function associated with `anim`.
       
   198 
       
   199 ==== `SetAnimSkip(bool)` ====
       
   200 Sets the state of animation skipping to `bool`. It is useful in case the player is allowed to skip the animation.
       
   201 
       
   202 Example:
       
   203 <code language="lua">function onPrecise()
       
   204     if AnimInProgress() then
       
   205         SetAnimSkip(true)
       
   206     end
       
   207 end</code>
       
   208 
       
   209 ==== `AnimInProgress()` ====
       
   210 Returns `true` if a cinematic is currently taking place, `false` otherwise.
       
   211 
       
   212 ==== `ExecuteAfterAnimations()` ====
       
   213 Calls the functions (added with `AddFunction`) that need to be executed after the cinematic. The best location for this function call is in `onGameTick`.
       
   214 
       
   215 ==== `AddFunction(element)` ====
       
   216 Adds `element` to the functions array that are to be called after the cinematic. `element` is a table with the keys: `func`, `args`.
       
   217 
       
   218 Example:
       
   219 <code language="lua">AddFunction({func = AfterCinem, args = {2}})</code>
       
   220 
       
   221 ==== `RemoveFunction()` ====
       
   222 Removes the first function from the aforementioned list.
       
   223 
       
   224 ==== `AnimInit([startAnimating])` ====
       
   225 Initializes variables used by the other functions. Needs to be called in `onGameInit`.
       
   226 
       
   227 Since 0.9.23, an optional convenience parameter `startAnimating` is available; if set to `true`, the game will start in “animation” mode which enables cinematic mode and disables all controls except precise for skipping. This is useful if you want to indicate that an animation will be played right at the start and the player must not be allowed to use any controls before the animation is over. If you set this parameter to `true`, you also *must* play at least one animation after this, otherwise the game will be stuck.
       
   228 
       
   229 ==== !AnimUnWait() ====
       
   230 Decreases the wait time used by cinematics. It is best called in `onGameTick`.
       
   231 
       
   232 === Cinematic functions ===
       
   233 
       
   234 ==== `AnimSwitchHog(gear)` ====
       
   235 Switches to `gear` and follows it.
       
   236 
       
   237 ==== `AnimWait(gear, time)` ====
       
   238 Increases the wait time by `time`. `gear` is just for compatibility with `ShowAnimation`.
       
   239 
       
   240 ==== `AnimSay(gear, text, manner, time` ====
       
   241 Calls `HogSay` with the first three arguments and increses the wait time by `time`.
       
   242 
       
   243 Example:
       
   244 <code language="lua">cinem = {
       
   245     {func = AnimSay, args = {gear1, "You're so defensive!", SAY_SAY, 2500}},
       
   246     {func = AnimSay, args = {gear2, "No, I'm not!", SAY_SAY, 2000}}
       
   247    }</code>
       
   248 
       
   249 ==== `AnimSound(gear, sound, time)` ====
       
   250 Plays the sound `sound` and increases the wait time by `time`.
       
   251 
       
   252 ==== `AnimTurn(hog, dir)` ====
       
   253 Makes `hog` face in direction `dir`, where `dir` equals either `"Right"` or `"Left"`.
       
   254 
       
   255 ==== `AnimMove(hog, dir, x, y)` ====
       
   256 Makes `hog` move in direction `dir` until either his horizontal coordinate is `x` or his vertical coordinate is `y`.
       
   257 
       
   258 ==== `AnimJump(hog, jumpType)` ====
       
   259 Makes `hog` perform a jump of type `jumpType`, where `jumpType` equals either `"long"`, `"high"` or `"back"`.
       
   260 
       
   261 ==== `AnimSetGearPosition(gear, x, y, fall)` ====
       
   262 Sets the position of `gear` to (`x`, `y`). If the optional argument `fall` does not equal `false` then the gear is given a small falling velocity in order to get around exact positioning.
       
   263 
       
   264 ==== `AnimDisappear(gear, x, y)` ====
       
   265 Teleports the gear to (`x`, `y`), adding some effects at the previous position and sounds. Doesn’t follow the gear.
       
   266 
       
   267 ==== `AnimOutOfNowhere(gear, x, y)` ====
       
   268 Teleports the gear to (`x`, `y`), adding effects and sounds at the final position. Follows gear.
       
   269 
       
   270 ==== `AnimTeleportGear(gear, x, y)` ====
       
   271 Teleports the gear to (`x`, `y`), adding effects and sounds both at the starting position and the final position. Follows gear.
       
   272 
       
   273 ==== `AnimVisualGear(gear, x, y, vgType, state, critical, follow)` ====
       
   274 Calls `AddVisualGear` with arguments second to sixth. If the optional argument `follow` equals `true` then the gear is followed. `gear` is for compatibility only.
       
   275 
       
   276 ==== `AnimCaption(gear, text, time)` ====
       
   277 Adds `text` as caption and increases wait time by `time`.
       
   278 
       
   279 ==== `AnimCustomFunction(gear, func, args)` ====
       
   280 Calls the function `func` with `args` as arguments. This function is useful, for instance, when the cinematic uses the position of a gear at the moment of execution. If `func` needs to be called in following game ticks then it should return false.
       
   281 
       
   282 Example:
       
   283 <code language="lua">function NeedToTurn(hog1, hog2)
       
   284    if GetX(hog1) < GetX(hog2) then
       
   285       HogTurnLeft(hog1, false)
       
   286       HogTurnLeft(hog2, true)
       
   287    else
       
   288       HogTurnLeft(hog2, false)
       
   289       HogTurnLeft(hog1, true)
       
   290    end
       
   291 end
       
   292 
       
   293 cinem = {{func = AnimCustomFunction, args = {hog1, NeedToTurn, {hog1, hg2}}}}</code>
       
   294 
       
   295 ==== `AnimInsertStepNext(step)` ====
       
   296 Inserts `step` after the current step (read: action) in the cinematic array. Useful when an action depends on variables (e.g. positoins). It can be used mostly with `AnimCustomFunction`. Note: In case of multiple consecutive calls, steps need to be added in reverse order.
       
   297 
       
   298 Example:
       
   299 <code language="lua">function BlowHog(deadHog)
       
   300   AnimInsertStepNext({func = DeleteGear, args = {deadHog}, swh = false}) 
       
   301   AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog), GetY(deadHog), vgtBigExplosion, 0, true}, swh = false})
       
   302   AnimInsertStepNext({func = AnimWait, args = {deadHog, 1200}})
       
   303   AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) + 20, GetY(deadHog), vgtExplosion, 0, true}, swh = false})
       
   304   AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}})
       
   305   AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) + 10, GetY(deadHog), vgtExplosion, 0, true}, swh = false})
       
   306   AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}})
       
   307   AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) - 10, GetY(deadHog), vgtExplosion, 0, true}, swh = false})
       
   308   AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}})
       
   309   AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) - 20, GetY(deadHog), vgtExplosion, 0, true}, swh = false})
       
   310 end
       
   311 cinem = {{func = AnimCustomFunction, args = {liveHog, BlowHog, {deadHog}}}}</code>
       
   312 
       
   313 === Event handling ===
       
   314 
       
   315 Events are pairs of functions that are used to check for various conditions. One of them is for verification and, if it returns `true`, the second function is called.
       
   316 
       
   317 ==== `AddEvent(condFunc, condArgs, doFunc, doArgs, evType)` ====
       
   318 Adds the functions `condFunc` and `doFunc` to the events list. They get called with the respective args (`condArgs` and `doArgs`). `condFunc` will get called in every game tick until it returns `true` or is removed. Once it returns `true`, `doFunc` is called and they are or are not removed from the list, depending on `evType` (`0` for removal, `1` for keeping). An `evType` of `1` is useful for repeating actions (e.g. every time a hog gets damaged, do something).
       
   319 
       
   320 Example:
       
   321 <code language="lua">function CheckPos()
       
   322    return GetX(myHog) > 1500
       
   323 end
       
   324 function CheckAmmo()
       
   325    return GetAmmoCount(myHog, amGrenade) == 0
       
   326 end
       
   327 function DoPos()
       
   328    ShowMission("Scooter", "Mover", "Nice Work", 0, 0)
       
   329 end
       
   330 function DoAmmo()
       
   331    AddAmmo(myHog, amGrenade, 5)
       
   332 end
       
   333 AddEvent(CheckPos, {}, DoPos, {}, 0) -- Add event that gets removed on completion
       
   334 AddEvent(CheckAmmo, {}, DoAmmo, {}, 1) -- Add repeating event</code>
       
   335 
       
   336 ==== `AddNewEvent(condFunc, condArgs, doFunc, doArgs, evType)` ====
       
   337 Does the same as `AddEvent`, but first checks if the event is already in the list so that it isn’t added twice.
       
   338 
       
   339 ==== `RemoveEventFunc(cFunc, cArgs)` ====
       
   340 Removes the event or events that have `cFunc` as the condition checking function. If `cArgs` does not equal `nil` then only those events get removed that have `cArgs` as arguments for `cFunc`, too.
       
   341 
       
   342 Example:
       
   343 <code language="lua">AddEvent(condFunc1, condArgs1, doFunc, doArgs)
       
   344 AddEvent(condFunc1, condArgs2, doFunc, doArgs)
       
   345 AddEvent(condFunc1, condArgs2, doFunc, doArgs)
       
   346 AddEvent(condFunc2, condArgs1, doFunc, doArgs)
       
   347 AddEvent(condFunc2, condArgs2, doFunc, doArgs)
       
   348 RemoveEventFunc(condFunc1) --Removes all three events that have condFunc1
       
   349 RemoveEventFunc(condFunc2, condArgs1) --Removes a single event</code>
       
   350 
       
   351 ==== `CheckEvents` ====
       
   352 Verifies all the condition functions in the events list and calls the respective ‘action’ functions if the conditions are met. If the `evType` of a completed event equals `0` then it is removed from the list. This function is best placed in `onGameTick`.
       
   353 
       
   354 ==== `AnimSetInputMask(inputMask)` (0.9.23) ====
       
   355 Call this function instead of `SetInputMask` if you want to set the input mask in a way that does not conflict with the Animate library.
       
   356 
       
   357 Internally, the input mask you provide is simply AND-ed with the input mask used by the Animate library. Otherwise, this function works lik `SetInputMask`.
       
   358 
       
   359 If you call `SetInputMask` directly, note that it might get quickly overwritten by the Animatel library!
       
   360 
       
   361 == Params ==
       
   362 The Params library is a small library introduced in 0.9.21. It provides a function to parse the parameter string `ScriptParam` and it is intended to simplify using this string.
       
   363 
       
   364 This library requires the parameter string to be in a certain format. It must be a comma-seperated list of kev-value pairs in the `key=value` format. Examples:
       
   365 
       
   366 <code>speed=1</code>
       
   367 <code>health=100, ammo=5</code>
       
   368 <code>param1=hello, param2=whatever, param3=5325.4</code>
       
   369 
       
   370 Using this library is by no means neccessary, you could use practically whatever syntax you wish if you write your own code for parsing.
       
   371 
       
   372 ==== `parseParams()` ====
       
   373 Parses `ScriptParam` and writes the result into the global table `params`. The table will follow the `key=value` pattern. Both keys and pairs are stored as string.
       
   374 
       
   375 ===== Example  =====
       
   376 <code language="lua">
       
   377 function onParameters()
       
   378     parseParams()
       
   379     if params["myparam1"] == "hello" then
       
   380         WriteLnToConsole("Hello World!")
       
   381     end
       
   382 end</code>
       
   383 
       
   384 If the key-value pair `myparam1=hello` is present, this script writes “Hello World!” in the console. All these inputs would trigger the event:
       
   385 
       
   386 <code>myparam1=hello</code>
       
   387 <code>myparam2=whatever, myparam1=hello</code>
       
   388 <code>g=4, f=56, m=56, myparam1=hello</code>
       
   389 
       
   390 
       
   391 
       
   392 == !TargetPractice ==
       
   393 Starting with 0.9.21, this library provides a function to create an entire target practice mission which follows some basic properties.
       
   394 
       
   395 Here is a brief description of the generated missions:
       
   396  * The player will get a team with a single hedgehog.
       
   397  * The team gets a single predefined weapon infinitely times.
       
   398  * A fixed sequence of targets will spawn at predefined positions.
       
   399  * When a target has been destroyed, the next target of the target sequence appears
       
   400  * The mission ends successfully when all targets have been destroyed
       
   401  * The mission ends unsuccessfully when the time runs out or the hedgehog dies
       
   402  * When the mission ends, a score is awarded, based on the performance (hit targets, accuracy and remaining time) of the hedgehog. When not all targets are hit, there will be no accuracy and time bonuses.
       
   403 
       
   404 If you want to create a more sophisticated training mission, use your own code instead. The main motivation to write this library was to reduce redundancy in existing target practice missions.
       
   405 
       
   406 === `TargetPracticeMission(params)` ===
       
   407 This function sets up the *entire* training mission and needs one argument: `params`.
       
   408 `params` is a table containing fields which describe the training mission.
       
   409 
       
   410 There are mandatory and optional fields. The optional fields have default values.
       
   411 
       
   412 Mandatory fields:
       
   413 || *Field name* || *Description* ||
       
   414 || `missionTitle` || The name of the mission ||
       
   415 || `map` || The name of the image map to be used ||
       
   416 || `theme` || The name of the theme (can be background theme, too) ||
       
   417 || `time` || The time limit in milliseconds ||
       
   418 || `ammoType` || The [AmmoTypes ammo type] of the weapon to be used ||
       
   419 || `gearType` || The [GearTypes gear type] of the gear which is fired by the weapon (used to count shots) ||
       
   420 || `targets` || The coordinates of where the targets will be spawned. It is a table containing tables containing coordinates of format `{ x=value, y=value }`. The targets will be spawned in the same order as specified the coordinate tables appear. There must be at least 1 target. ||
       
   421 
       
   422 Optional fields:
       
   423 || *Field name* || *Description * ||
       
   424 || `wind` || The initial wind (`-100` to `100`) (default: `0` (no wind)) ||
       
   425 || `solidLand` || Weather the terrain is indestructible (default: `false`) ||
       
   426 || `artillery` || If `true`, the hog can’t move (default: `false`) ||
       
   427 || `hogHat` || Hat of the hedgehog (default: `"NoHat"`) ||
       
   428 || `hogName` || Name of the hedgehog (default: `"Trainee"`) ||
       
   429 || `teamName` || Name of the hedgehog’s team (default: `"Training Team"`) ||
       
   430 || `teamGrave` || Name of the hedgehog’s grave ||
       
   431 || `clanColor` || Color of the (only) clan (default: `0xFF0204`, which is a red tone) ||
       
   432 || `goalText` || A short string explaining the goal of the mission (default: `"Destroy all targets within the time!"`) ||
       
   433 || `shootText`: || A string which says how many times the player shot, “`%d`” is replaced by the number of shots. (default: `"You have shot %d times."`) ||
       
   434 
       
   435 
       
   436 ==== Example ====
       
   437 Below is the complete source code of the mission “Target Practice: Cluster Bomb”:
       
   438 
       
   439 <code language="lua">HedgewarsScriptLoad("/Scripts/TargetPractice.lua")
       
   440 
       
   441 local params = {
       
   442 	ammoType = amClusterBomb,
       
   443 	gearType = gtClusterBomb,
       
   444 	missionTitle = "Cluster Bomb Training",
       
   445 	solidLand = false,
       
   446 	map = "Trash",
       
   447 	theme = "Golf",
       
   448 	hog_x = 756,
       
   449 	hog_y = 370,
       
   450 	hogName = loc("Private Nolak"),
       
   451 	hogHat = "war_desertgrenadier1",
       
   452 	teamName = loc("The Hogies"),
       
   453 	targets = {
       
   454 		{ x = 628, y = 0 },
       
   455 		{ x = 891, y = 0 },
       
   456 		{ x = 1309, y = 0 },
       
   457 		{ x = 1128, y = 0 },
       
   458 		{ x = 410, y = 0 },
       
   459 		{ x = 1564, y = 0 },
       
   460 		{ x = 1248, y = 476 },
       
   461 		{ x = 169, y = 0 },
       
   462 		{ x = 1720, y = 0 },
       
   463 		{ x = 1441, y = 0 },
       
   464 		{ x = 599, y = 0 },
       
   465 		{ x = 1638, y = 0 },
       
   466 	},
       
   467 	time = 180000,
       
   468 	shootText = loc("You have thrown %d cluster bombs."),
       
   469 }
       
   470 
       
   471 TargetPracticeMission(params)</code>
       
   472 
       
   473 == !SpeedShoppa ==
       
   474 Starting with 0.9.22, this library provides a function to create a simple shoppa-style mission.
       
   475 
       
   476 In !SpeedShoppa missions, the player starts with infinite ropes and has to collect all crates as fast as possible and compete for the fastest time.
       
   477 
       
   478 === `SpeedShoppaMission(params)` ===
       
   479 This function sets up the *entire* mission and needs one argument: `params`.
       
   480 The argument “`params`” is a table containing fields which describe the training mission.
       
   481 
       
   482 Mandatory fields:
       
   483 
       
   484 || *Field name* || *Description* ||
       
   485 || `map` || The name of the map to be used ||
       
   486 || `theme` || The name of the theme (does not need to be a standalone theme) ||
       
   487 || `time` || The time limit in milliseconds ||
       
   488 || `crates` || The coordinates of where the crates will be spawned. It is a table containing tables containing coordinates of format `{ x=value, y=value }`. There must be at least 1 crate. ||
       
   489 
       
   490 Optional fields:
       
   491 
       
   492 || *Field name* || *Description* ||
       
   493 || `missionTitle` || The name of the mission (optional but highly recommended) (default: `"Speed Shoppa"`) ||
       
   494 || `hogHat` || Hat of the hedgehog (default: `"NoHat"`) ||
       
   495 || `hogName` || Name of the hedgehog (default: `"Roper"`) ||
       
   496 || `teamName` || Name of the hedgehog’s team (default: `"Shoppers"`) ||
       
   497 || `teamGrave` || Name of the hedgehog’s grave (default: `"Statue"`) ||
       
   498 || `teamFlag` || Name of the team’s flag (default: `"cm_shoppa"`) ||
       
   499 || `clanColor` || Color of the (only) clan (default: `0xFF0204`, which is a red tone) ||
       
   500 || `goalText` || A short string explaining the goal of the mission (default: `"Use your rope to collect all crates as fast as possible."`) ||
       
   501 || `faceLeft` || If `true`, the hog faces to the left initially, if false, it faces to the right. (default: `false` (=right)) ||
       
   502 || `crateType` || Specify the type of crate (this has no gameplay effect), pick one of `"ammo"`, `"utility"`, `"health"`. Default: `"ammo"` ||
       
   503 || `extra_onGameStart` || A function which is called at the end of this script's `onGameStart`. It takes no parameters. You could use this to spawn additional gears like girders or mines ||
       
   504 || `extra_onGameInit` || A function which is called at the end of this script's `onGameInit` ||