LuaLibraries.wiki
changeset 742 1ece82f7b547
parent 684 5488179eb2d2
child 798 30c5f1ebd552
equal deleted inserted replaced
741:8fa25c5a4967 742:1ece82f7b547
     1 #summary Libraries for writing Lua scripts in Hedgewars.
     1 #summary Libraries for writing Lua scripts in Hedgewars.
     2 
     2 
     3 = Introduction =
     3 = Lua libraries documentation =
       
     4 
       
     5 == Introduction ==
     4 
     6 
     5 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.
     6 
     8 
     7 To use a library you only need to add one row at the top of the script:
     9 To use a library you only need to add one row at the top of the script:
     8 <code language="lua">HedgewarsScriptLoad("Scripts/<Library Name>.lua")</code>
    10 <code language="lua">HedgewarsScriptLoad("Scripts/<Library Name>.lua")</code>
    10 
    12 
    11 *Note*: In old scripts, you will find this line instead:
    13 *Note*: In old scripts, you will find this line instead:
    12 <code language="lua">loadfile(GetDataPath() .. "Scripts/<Library Name>.lua")()</code>
    14 <code language="lua">loadfile(GetDataPath() .. "Scripts/<Library Name>.lua")()</code>
    13 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.*
    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 
    16 
    15 = Table of Contents =
    17 == Table of Contents ==
    16 
    18 
    17 <wiki:toc max_depth="2" />
    19 <wiki:toc max_depth="2" />
    18 = Locale =
    20 == Locale ==
    19 
    21 
    20 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.
    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 
    23 
    22 === `loc(text)` ===
    24 ==== `loc(text)` ====
    23 
    25 
    24 Returns the localised string of `text` or, if it is not found, it returns `text`.
    26 Returns the localised string of `text` or, if it is not found, it returns `text`.
    25 
    27 
    26 
    28 
    27 
    29 
    28 = Utils =
    30 == Utils ==
    29 
    31 
    30 This library includes miscellaneous functions to use, they are all independent of each other and can be used everywhere.
    32 This library includes miscellaneous functions to use, they are all independent of each other and can be used everywhere.
    31 
    33 
    32 === `gearIsInBox(gear, x, y, w, h)` ===
    34 ==== `gearIsInBox(gear, x, y, w, h)` ====
    33 
    35 
    34 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.
    36 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.
    35 
    37 
    36 
    38 
    37 === `gearIsInCircle(gear, x, y, r, useRadius)` ===
    39 ==== `gearIsInCircle(gear, x, y, r, useRadius)` ====
    38 
    40 
    39 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.
    41 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.
    40 
    42 
    41 
    43 
    42 
    44 
    43 = Tracker =
    45 == Tracker ==
    44 
    46 
    45 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.
    47 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.
    46 
    48 
    47 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`.
    49 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`.
    48 
    50 
    59 This will kill all hogs if a target is destroyed.
    61 This will kill all hogs if a target is destroyed.
    60 
    62 
    61 To see a commented example of the tracker in use by a script you can look at
    63 To see a commented example of the tracker in use by a script you can look at
    62 [http://hg.hedgewars.org/hedgewars/file/default/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Random Weapons].
    64 [http://hg.hedgewars.org/hedgewars/file/default/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Random Weapons].
    63 
    65 
    64 == Tracking functions ==
    66 === Tracking functions ===
    65 
    67 
    66 === `trackGear(gear)` ===
    68 ==== `trackGear(gear)` ====
    67 
    69 
    68 Will keep track of the gear.
    70 Will keep track of the gear.
    69 
    71 
    70 
    72 
    71 === `trackDeletion(gear)` ===
    73 ==== `trackDeletion(gear)` ====
    72 
    74 
    73 Will stop keeping track of the gear (gears not tracked will be ignored).
    75 Will stop keeping track of the gear (gears not tracked will be ignored).
    74 
    76 
    75 
    77 
    76 === `trackTeams()` ===
    78 ==== `trackTeams()` ====
    77 
    79 
    78 Will start the tracking of teams, clans and hedgehogs (hogs can be tracked without this).
    80 Will start the tracking of teams, clans and hedgehogs (hogs can be tracked without this).
    79 
    81 
    80 
    82 
    81 == “`runOn`” functions ==
    83 === “`runOn`” functions ===
    82 
    84 
    83 === `runOnGears(func)` ===
    85 ==== `runOnGears(func)` ====
    84 
    86 
    85 Runs the function `func` on all gears.
    87 Runs the function `func` on all gears.
    86 
    88 
    87 
    89 
    88 === `runOnHogs(func)` ===
    90 ==== `runOnHogs(func)` ====
    89 
    91 
    90 Runs the function `func` on all hedgehogs.
    92 Runs the function `func` on all hedgehogs.
    91 
    93 
    92 
    94 
    93 === `runOnHogsInTeam(func, team)` ===
    95 ==== `runOnHogsInTeam(func, team)` ====
    94 
    96 
    95 Runs the function `func` on all hedgehogs in the specified team.
    97 Runs the function `func` on all hedgehogs in the specified team.
    96 
    98 
    97 
    99 
    98 === runOnHogsInOtherTeams(func, team) ===
   100 ==== runOnHogsInOtherTeams(func, team) ====
    99 
   101 
   100 Runs the function `func` on all hedgehogs but those in the specified team.
   102 Runs the function `func` on all hedgehogs but those in the specified team.
   101 
   103 
   102 
   104 
   103 === `runOnHogsInClan(func, clan)` ===
   105 ==== `runOnHogsInClan(func, clan)` ====
   104 
   106 
   105 Runs the function `func` on all hedgehogs in the specified clan.
   107 Runs the function `func` on all hedgehogs in the specified clan.
   106 
   108 
   107 
   109 
   108 === `runOnHogsInOtherClans(func, clan)` ===
   110 ==== `runOnHogsInOtherClans(func, clan)` ====
   109 
   111 
   110 Runs the function `func` on all hedgehogs but those in the specified clan.
   112 Runs the function `func` on all hedgehogs but those in the specified clan.
   111 
   113 
   112 
   114 
   113 == Variable functions ==
   115 === Variable functions ===
   114 
   116 
   115 _To be continued …_
   117 _To be continued …_
   116 
   118 
   117 
   119 
   118 = Animate =
   120 == Animate ==
   119 
   121 
   120 This library provides functions that aid cinematic/cut-scene creation and functions for handling events. 
   122 This library provides functions that aid cinematic/cut-scene creation and functions for handling events. 
   121 
   123 
   122 In order to use its full potential, the following lines need to be at the beginning of `onGameTick`.
   124 In order to use its full potential, the following lines need to be at the beginning of `onGameTick`.
   123 
   125 
   131 end</code>
   133 end</code>
   132 
   134 
   133 Also, `AnimInit()` needs to be called in `onGameInit()`.
   135 Also, `AnimInit()` needs to be called in `onGameInit()`.
   134 Each of these functions will be explained below.
   136 Each of these functions will be explained below.
   135 
   137 
   136 == Cinematic Handling ==
   138 === Cinematic handling ===
   137 
   139 
   138 === `ShowAnimation()` ===
   140 ==== `ShowAnimation()` ====
   139 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)`.
   141 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)`.
   140 
   142 
   141 === `AddAnim(steps)` ===
   143 ==== `AddAnim(steps)` ====
   142 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`.
   144 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`.
   143 
   145 
   144   * `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. 
   146   * `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. 
   145 
   147 
   146   * `args` is a table containing the arguments that need to be passed to the function given
   148   * `args` is a table containing the arguments that need to be passed to the function given
   152     {func = AnimMove, args = {myhog, "Left", 2000, 0}},
   154     {func = AnimMove, args = {myhog, "Left", 2000, 0}},
   153     {func = AddCaption, swh = false, args = {"But he found no more snails..."}}
   155     {func = AddCaption, swh = false, args = {"But he found no more snails..."}}
   154     }
   156     }
   155 AddAnim(cinem)</code>
   157 AddAnim(cinem)</code>
   156 
   158 
   157 === `RemoveAnim(steps)` ===
   159 ==== `RemoveAnim(steps)` ====
   158 Removes `steps` from the animations array.
   160 Removes `steps` from the animations array.
   159 
   161 
   160 === `AddSkipFunction(anim, func, args)` ===
   162 === `AddSkipFunction(anim, func, args)` ===
   161 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.
   163 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.
   162 Example:
   164 Example:
   163 <code language="lua">AddSkipFunc(cinem, SkipCinem, {})</code>
   165 <code language="lua">AddSkipFunc(cinem, SkipCinem, {})</code>
   164 
   166 
   165 === `RemoveSkipFunction(anim)` ===
   167 ==== `RemoveSkipFunction(anim)` ====
   166 Removes the skip function associated with `anim`.
   168 Removes the skip function associated with `anim`.
   167 
   169 
   168 === `SetAnimSkip(bool)` ===
   170 ==== `SetAnimSkip(bool)` ====
   169 Sets the state of animation skipping to `bool`. It is useful in case the player is allowed to skip the animation.
   171 Sets the state of animation skipping to `bool`. It is useful in case the player is allowed to skip the animation.
   170 
   172 
   171 Example:
   173 Example:
   172 <code language="lua">function onPrecise()
   174 <code language="lua">function onPrecise()
   173     if AnimInProgress() then
   175     if AnimInProgress() then
   174         SetAnimSkip(true)
   176         SetAnimSkip(true)
   175     end
   177     end
   176 end</code>
   178 end</code>
   177 
   179 
   178 === `AnimInProgress()` ===
   180 ==== `AnimInProgress()` ====
   179 Returns `true` if a cinematic is currently taking place, `false` otherwise.
   181 Returns `true` if a cinematic is currently taking place, `false` otherwise.
   180 
   182 
   181 === `ExecuteAfterAnimations()` ===
   183 ==== `ExecuteAfterAnimations()` ====
   182 Calls the functions (added with `AddFunction`) that need to be executed after the cinematic. The best location for this function call is in `onGameTick`.
   184 Calls the functions (added with `AddFunction`) that need to be executed after the cinematic. The best location for this function call is in `onGameTick`.
   183 
   185 
   184 === `AddFunction(element)` ===
   186 ==== `AddFunction(element)` ====
   185 Adds `element` to the functions array that are to be called after the cinematic. `element` is a table with the keys: `func`, `args`.
   187 Adds `element` to the functions array that are to be called after the cinematic. `element` is a table with the keys: `func`, `args`.
   186 
   188 
   187 Example:
   189 Example:
   188 <code language="lua">AddFunction({func = AfterCinem, args = {2}})</code>
   190 <code language="lua">AddFunction({func = AfterCinem, args = {2}})</code>
   189 
   191 
   190 === `RemoveFunction()` ===
   192 ==== `RemoveFunction()` ====
   191 Removes the first function from the aforementioned list.
   193 Removes the first function from the aforementioned list.
   192 
   194 
   193 === `AnimInit()` ===
   195 ==== `AnimInit()` ====
   194 Initializes variables used by the other functions. Needs to be called in `onGameInit`.
   196 Initializes variables used by the other functions. Needs to be called in `onGameInit`.
   195 
   197 
   196 === !AnimUnWait() ===
   198 ==== !AnimUnWait() ====
   197 Decreases the wait time used by cinematics. It is best called in `onGameTick`.
   199 Decreases the wait time used by cinematics. It is best called in `onGameTick`.
   198 
   200 
   199 == Cinematic Functions ==
   201 === Cinematic functions ===
   200 
   202 
   201 === `AnimSwitchHog(gear)` ===
   203 ==== `AnimSwitchHog(gear)` ====
   202 Switches to `gear` and follows it.
   204 Switches to `gear` and follows it.
   203 
   205 
   204 === `AnimWait(gear, time)` ===
   206 ==== `AnimWait(gear, time)` ====
   205 Increases the wait time by `time`. `gear` is just for compatibility with `ShowAnimation`.
   207 Increases the wait time by `time`. `gear` is just for compatibility with `ShowAnimation`.
   206 
   208 
   207 === `AnimSay(gear, text, manner, time` ===
   209 ==== `AnimSay(gear, text, manner, time` ====
   208 Calls `HogSay` with the first three arguments and increses the wait time by `time`.
   210 Calls `HogSay` with the first three arguments and increses the wait time by `time`.
   209 
   211 
   210 Example:
   212 Example:
   211 <code language="lua">cinem = {
   213 <code language="lua">cinem = {
   212     {func = AnimSay, args = {gear1, "You're so defensive!", SAY_SAY, 2500}},
   214     {func = AnimSay, args = {gear1, "You're so defensive!", SAY_SAY, 2500}},
   213     {func = AnimSay, args = {gear2, "No, I'm not!", SAY_SAY, 2000}}
   215     {func = AnimSay, args = {gear2, "No, I'm not!", SAY_SAY, 2000}}
   214    }</code>
   216    }</code>
   215 
   217 
   216 === `AnimSound(gear, sound, time)` ===
   218 ==== `AnimSound(gear, sound, time)` ====
   217 Plays the sound `sound` and increases the wait time by `time`.
   219 Plays the sound `sound` and increases the wait time by `time`.
   218 
   220 
   219 === `AnimTurn(hog, dir)` ===
   221 ==== `AnimTurn(hog, dir)` ====
   220 Makes `hog` face in direction `dir`, where `dir` equals either `"Right"` or `"Left"`.
   222 Makes `hog` face in direction `dir`, where `dir` equals either `"Right"` or `"Left"`.
   221 
   223 
   222 === `AnimMove(hog, dir, x, y)` ===
   224 ==== `AnimMove(hog, dir, x, y)` ====
   223 Makes `hog` move in direction `dir` until either his horizontal coordinate is `x` or his vertical coordinate is `y`.
   225 Makes `hog` move in direction `dir` until either his horizontal coordinate is `x` or his vertical coordinate is `y`.
   224 
   226 
   225 === `AnimJump(hog, jumpType)` ===
   227 ==== `AnimJump(hog, jumpType)` ====
   226 Makes `hog` perform a jump of type `jumpType`, where `jumpType` equals either `"long"`, `"high"` or `"back"`.
   228 Makes `hog` perform a jump of type `jumpType`, where `jumpType` equals either `"long"`, `"high"` or `"back"`.
   227 
   229 
   228 === `AnimSetGearPosition(gear, x, y, fall)` ===
   230 ==== `AnimSetGearPosition(gear, x, y, fall)` ====
   229 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.
   231 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.
   230 
   232 
   231 === `AnimDisappear(gear, x, y)` ===
   233 ==== `AnimDisappear(gear, x, y)` ====
   232 Teleports the gear to (`x`, `y`), adding some effects at the previous position and sounds. Doesn’t follow the gear.
   234 Teleports the gear to (`x`, `y`), adding some effects at the previous position and sounds. Doesn’t follow the gear.
   233 
   235 
   234 === `AnimOutOfNowhere(gear, x, y)` ===
   236 ==== `AnimOutOfNowhere(gear, x, y)` ====
   235 Teleports the gear to (`x`, `y`), adding effects and sounds at the final position. Follows gear.
   237 Teleports the gear to (`x`, `y`), adding effects and sounds at the final position. Follows gear.
   236 
   238 
   237 === `AnimTeleportGear(gear, x, y)` ===
   239 ==== `AnimTeleportGear(gear, x, y)` ====
   238 Teleports the gear to (`x`, `y`), adding effects and sounds both at the starting position and the final position. Follows gear.
   240 Teleports the gear to (`x`, `y`), adding effects and sounds both at the starting position and the final position. Follows gear.
   239 
   241 
   240 === `AnimVisualGear(gear, x, y, vgType, state, critical, follow)` ===
   242 ==== `AnimVisualGear(gear, x, y, vgType, state, critical, follow)` ====
   241 Calls `AddVisualGear` with arguments second to sixth. If the optional argument `follow` equals `true` then the gear is followed. `gear` is for compatibility only.
   243 Calls `AddVisualGear` with arguments second to sixth. If the optional argument `follow` equals `true` then the gear is followed. `gear` is for compatibility only.
   242 
   244 
   243 === `AnimCaption(gear, text, time)` ===
   245 ==== `AnimCaption(gear, text, time)` ====
   244 Adds `text` as caption and increases wait time by `time`.
   246 Adds `text` as caption and increases wait time by `time`.
   245 
   247 
   246 === `AnimCustomFunction(gear, func, args)` ===
   248 ==== `AnimCustomFunction(gear, func, args)` ====
   247 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.
   249 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.
   248 
   250 
   249 Example:
   251 Example:
   250 <code language="lua">function NeedToTurn(hog1, hog2)
   252 <code language="lua">function NeedToTurn(hog1, hog2)
   251    if GetX(hog1) < GetX(hog2) then
   253    if GetX(hog1) < GetX(hog2) then
   257    end
   259    end
   258 end
   260 end
   259 
   261 
   260 cinem = {{func = AnimCustomFunction, args = {hog1, NeedToTurn, {hog1, hg2}}}}</code>
   262 cinem = {{func = AnimCustomFunction, args = {hog1, NeedToTurn, {hog1, hg2}}}}</code>
   261 
   263 
   262 === `AnimInsertStepNext(step)` ===
   264 ==== `AnimInsertStepNext(step)` ====
   263 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.
   265 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.
   264 
   266 
   265 Example:
   267 Example:
   266 <code language="lua">function BlowHog(deadHog)
   268 <code language="lua">function BlowHog(deadHog)
   267   AnimInsertStepNext({func = DeleteGear, args = {deadHog}, swh = false}) 
   269   AnimInsertStepNext({func = DeleteGear, args = {deadHog}, swh = false}) 
   275   AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}})
   277   AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}})
   276   AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) - 20, GetY(deadHog), vgtExplosion, 0, true}, swh = false})
   278   AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) - 20, GetY(deadHog), vgtExplosion, 0, true}, swh = false})
   277 end
   279 end
   278 cinem = {{func = AnimCustomFunction, args = {liveHog, BlowHog, {deadHog}}}}</code>
   280 cinem = {{func = AnimCustomFunction, args = {liveHog, BlowHog, {deadHog}}}}</code>
   279 
   281 
   280 == Event Handling ==
   282 === Event handling ===
   281 
   283 
   282 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.
   284 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.
   283 
   285 
   284 === `AddEvent(condFunc, condArgs, doFunc, doArgs, evType)` ===
   286 ==== `AddEvent(condFunc, condArgs, doFunc, doArgs, evType)` ====
   285 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).
   287 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).
   286 
   288 
   287 Example:
   289 Example:
   288 <code language="lua">function CheckPos()
   290 <code language="lua">function CheckPos()
   289    return GetX(myHog) > 1500
   291    return GetX(myHog) > 1500
   298    AddAmmo(myHog, amGrenade, 5)
   300    AddAmmo(myHog, amGrenade, 5)
   299 end
   301 end
   300 AddEvent(CheckPos, {}, DoPos, {}, 0) -- Add event that gets removed on completion
   302 AddEvent(CheckPos, {}, DoPos, {}, 0) -- Add event that gets removed on completion
   301 AddEvent(CheckAmmo, {}, DoAmmo, {}, 1) -- Add repeating event</code>
   303 AddEvent(CheckAmmo, {}, DoAmmo, {}, 1) -- Add repeating event</code>
   302 
   304 
   303 === `AddNewEvent(condFunc, condArgs, doFunc, doArgs, evType)` ===
   305 ==== `AddNewEvent(condFunc, condArgs, doFunc, doArgs, evType)` ====
   304 Does the same as `AddEvent`, but first checks if the event is already in the list so that it isn’t added twice.
   306 Does the same as `AddEvent`, but first checks if the event is already in the list so that it isn’t added twice.
   305 
   307 
   306 === `RemoveEventFunc(cFunc, cArgs)` ===
   308 ==== `RemoveEventFunc(cFunc, cArgs)` ====
   307 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.
   309 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.
   308 
   310 
   309 Example:
   311 Example:
   310 <code language="lua">AddEvent(condFunc1, condArgs1, doFunc, doArgs)
   312 <code language="lua">AddEvent(condFunc1, condArgs1, doFunc, doArgs)
   311 AddEvent(condFunc1, condArgs2, doFunc, doArgs)
   313 AddEvent(condFunc1, condArgs2, doFunc, doArgs)
   313 AddEvent(condFunc2, condArgs1, doFunc, doArgs)
   315 AddEvent(condFunc2, condArgs1, doFunc, doArgs)
   314 AddEvent(condFunc2, condArgs2, doFunc, doArgs)
   316 AddEvent(condFunc2, condArgs2, doFunc, doArgs)
   315 RemoveEventFunc(condFunc1) --Removes all three events that have condFunc1
   317 RemoveEventFunc(condFunc1) --Removes all three events that have condFunc1
   316 RemoveEventFunc(condFunc2, condArgs1) --Removes a single event</code>
   318 RemoveEventFunc(condFunc2, condArgs1) --Removes a single event</code>
   317 
   319 
   318 === `CheckEvents` ===
   320 ==== `CheckEvents` ====
   319 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`.
   321 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`.
   320 
   322 
   321 
   323 
   322 = Params =
   324 == Params ==
   323 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.
   325 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.
   324 
   326 
   325 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:
   327 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:
   326 
   328 
   327 <code>speed=1</code>
   329 <code>speed=1</code>
   328 <code>health=100, ammo=5</code>
   330 <code>health=100, ammo=5</code>
   329 <code>param1=hello, param2=whatever, param3=5325.4</code>
   331 <code>param1=hello, param2=whatever, param3=5325.4</code>
   330 
   332 
   331 Using this library is by no means neccessary, you could use practically whatever syntax you wish if you write your own code for parsing.
   333 Using this library is by no means neccessary, you could use practically whatever syntax you wish if you write your own code for parsing.
   332 
   334 
   333 === `parseParams()` ===
   335 ==== `parseParams()` ====
   334 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.
   336 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.
   335 
   337 
   336 ==== Example  ====
   338 ===== Example  =====
   337 <code language="lua">
   339 <code language="lua">
   338 function onParameters()
   340 function onParameters()
   339     parseParams()
   341     parseParams()
   340     if params["myparam1"] == "hello" then
   342     if params["myparam1"] == "hello" then
   341         WriteLnToConsole("Hello World!")
   343         WriteLnToConsole("Hello World!")
   348 <code>myparam2=whatever, myparam1=hello</code>
   350 <code>myparam2=whatever, myparam1=hello</code>
   349 <code>g=4, f=56, m=56, myparam1=hello</code>
   351 <code>g=4, f=56, m=56, myparam1=hello</code>
   350 
   352 
   351 
   353 
   352 
   354 
   353 = !TargetPractice =
   355 == !TargetPractice ==
   354 Starting with 0.9.21, this library provides a function to create an entire target practice mission which follows some basic properties.
   356 Starting with 0.9.21, this library provides a function to create an entire target practice mission which follows some basic properties.
   355 
   357 
   356 Here is a brief description of the generated missions:
   358 Here is a brief description of the generated missions:
   357  * The player will get a team with a single hedgehog.
   359  * The player will get a team with a single hedgehog.
   358  * The team gets a single predefined weapon infinitely times.
   360  * The team gets a single predefined weapon infinitely times.
   431 	shootText = loc("You have thrown %d cluster bombs."),
   433 	shootText = loc("You have thrown %d cluster bombs."),
   432 }
   434 }
   433 
   435 
   434 TargetPracticeMission(params)</code>
   436 TargetPracticeMission(params)</code>
   435 
   437 
   436 = !SpeedShoppa =
   438 == !SpeedShoppa ==
   437 Starting with 0.9.22, this library provides a function to create a simple shoppa-style mission.
   439 Starting with 0.9.22, this library provides a function to create a simple shoppa-style mission.
   438 
   440 
   439 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.
   441 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.
   440 
   442 
   441 This library also loads the Locale library for its own purposes. If you use !SpeedShoppa, you do not have to explicitly load Locale anymore.
   443 This library also loads the Locale library for its own purposes. If you use !SpeedShoppa, you do not have to explicitly load Locale anymore.