author | Wuzzy |
Thu, 07 Apr 2016 19:40:46 +0100 | |
changeset 861 | ccbc115e68ad |
parent 798 | 30c5f1ebd552 |
child 867 | 30cc2f85c5e7 |
permissions | -rw-r--r-- |
84
6fa418422e57
Created wiki page through web user interface.
henrik.rostedt@gmail.com
parents:
diff
changeset
|
1 |
#summary Libraries for writing Lua scripts in Hedgewars. |
6fa418422e57
Created wiki page through web user interface.
henrik.rostedt@gmail.com
parents:
diff
changeset
|
2 |
|
742 | 3 |
= Lua libraries documentation = |
4 |
||
5 |
== Introduction == |
|
84
6fa418422e57
Created wiki page through web user interface.
henrik.rostedt@gmail.com
parents:
diff
changeset
|
6 |
|
6fa418422e57
Created wiki page through web user interface.
henrik.rostedt@gmail.com
parents:
diff
changeset
|
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. |
6fa418422e57
Created wiki page through web user interface.
henrik.rostedt@gmail.com
parents:
diff
changeset
|
8 |
|
6fa418422e57
Created wiki page through web user interface.
henrik.rostedt@gmail.com
parents:
diff
changeset
|
9 |
To use a library you only need to add one row at the top of the script: |
501
04b4b463bf33
Add HedgewarsScriptLoad, warn about the old and rusty loadfile function.
almikes@aol.com
parents:
500
diff
changeset
|
10 |
<code language="lua">HedgewarsScriptLoad("Scripts/<Library Name>.lua")</code> |
04b4b463bf33
Add HedgewarsScriptLoad, warn about the old and rusty loadfile function.
almikes@aol.com
parents:
500
diff
changeset
|
11 |
Where `<Library Name>` is replaced by the name. |
84
6fa418422e57
Created wiki page through web user interface.
henrik.rostedt@gmail.com
parents:
diff
changeset
|
12 |
|
501
04b4b463bf33
Add HedgewarsScriptLoad, warn about the old and rusty loadfile function.
almikes@aol.com
parents:
500
diff
changeset
|
13 |
*Note*: In old scripts, you will find this line instead: |
04b4b463bf33
Add HedgewarsScriptLoad, warn about the old and rusty loadfile function.
almikes@aol.com
parents:
500
diff
changeset
|
14 |
<code language="lua">loadfile(GetDataPath() .. "Scripts/<Library Name>.lua")()</code> |
525
b051cfd45c23
Edited wiki page LuaLibraries through web user interface.
almikes@aol.com
parents:
501
diff
changeset
|
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.* |
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
16 |
|
742 | 17 |
== Table of Contents == |
527 | 18 |
|
19 |
<wiki:toc max_depth="2" /> |
|
742 | 20 |
== Locale == |
84
6fa418422e57
Created wiki page through web user interface.
henrik.rostedt@gmail.com
parents:
diff
changeset
|
21 |
|
6fa418422e57
Created wiki page through web user interface.
henrik.rostedt@gmail.com
parents:
diff
changeset
|
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. |
6fa418422e57
Created wiki page through web user interface.
henrik.rostedt@gmail.com
parents:
diff
changeset
|
23 |
|
742 | 24 |
==== `loc(text)` ==== |
528 | 25 |
|
529 | 26 |
Returns the localised string of `text` or, if it is not found, it returns `text`. |
528 | 27 |
|
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
28 |
|
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
29 |
|
742 | 30 |
== Utils == |
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
31 |
|
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
32 |
This library includes miscellaneous functions to use, they are all independent of each other and can be used everywhere. |
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
33 |
|
742 | 34 |
==== `gearIsInBox(gear, x, y, w, h)` ==== |
528 | 35 |
|
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
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. |
528 | 37 |
|
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
38 |
|
742 | 39 |
==== `gearIsInCircle(gear, x, y, r, useRadius)` ==== |
528 | 40 |
|
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
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. |
528 | 42 |
|
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
43 |
|
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
44 |
|
742 | 45 |
== Tracker == |
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
46 |
|
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
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. |
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
48 |
|
528 | 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`. |
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
50 |
|
528 | 51 |
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: |
52 |
<code language="lua">function killall(gear) |
|
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
53 |
SetHealth(gear, 0) |
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
54 |
end |
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
55 |
|
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
56 |
function onGearDelete(gear) |
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
57 |
if GetGearType(gear) == gtTarget then |
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
58 |
runOnHogs(killall) |
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
59 |
end |
528 | 60 |
end</code> |
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
61 |
This will kill all hogs if a target is destroyed. |
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
62 |
|
103
023ff3c709ac
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
86
diff
changeset
|
63 |
To see a commented example of the tracker in use by a script you can look at |
798
30c5f1ebd552
global replace of http with https for hedgewars.org wiki links
nemo
parents:
742
diff
changeset
|
64 |
[https://hg.hedgewars.org/hedgewars/file/default/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Random Weapons]. |
103
023ff3c709ac
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
86
diff
changeset
|
65 |
|
742 | 66 |
=== Tracking functions === |
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
67 |
|
742 | 68 |
==== `trackGear(gear)` ==== |
528 | 69 |
|
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
70 |
Will keep track of the gear. |
528 | 71 |
|
72 |
||
742 | 73 |
==== `trackDeletion(gear)` ==== |
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
74 |
|
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
75 |
Will stop keeping track of the gear (gears not tracked will be ignored). |
528 | 76 |
|
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
77 |
|
742 | 78 |
==== `trackTeams()` ==== |
528 | 79 |
|
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
80 |
Will start the tracking of teams, clans and hedgehogs (hogs can be tracked without this). |
528 | 81 |
|
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
82 |
|
742 | 83 |
=== “`runOn`” functions === |
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
84 |
|
742 | 85 |
==== `runOnGears(func)` ==== |
528 | 86 |
|
87 |
Runs the function `func` on all gears. |
|
88 |
||
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
89 |
|
742 | 90 |
==== `runOnHogs(func)` ==== |
528 | 91 |
|
92 |
Runs the function `func` on all hedgehogs. |
|
93 |
||
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
94 |
|
742 | 95 |
==== `runOnHogsInTeam(func, team)` ==== |
528 | 96 |
|
97 |
Runs the function `func` on all hedgehogs in the specified team. |
|
98 |
||
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
99 |
|
742 | 100 |
==== runOnHogsInOtherTeams(func, team) ==== |
528 | 101 |
|
102 |
Runs the function `func` on all hedgehogs but those in the specified team. |
|
103 |
||
104 |
||
742 | 105 |
==== `runOnHogsInClan(func, clan)` ==== |
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
106 |
|
528 | 107 |
Runs the function `func` on all hedgehogs in the specified clan. |
108 |
||
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
109 |
|
742 | 110 |
==== `runOnHogsInOtherClans(func, clan)` ==== |
528 | 111 |
|
112 |
Runs the function `func` on all hedgehogs but those in the specified clan. |
|
113 |
||
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
114 |
|
742 | 115 |
=== Variable functions === |
85
9f1d2d3db844
Edited wiki page LuaLibraries through web user interface.
henrik.rostedt@gmail.com
parents:
84
diff
changeset
|
116 |
|
528 | 117 |
_To be continued …_ |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
118 |
|
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
119 |
|
742 | 120 |
== Animate == |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
121 |
|
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
122 |
This library provides functions that aid cinematic/cut-scene creation and functions for handling events. |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
123 |
|
528 | 124 |
In order to use its full potential, the following lines need to be at the beginning of `onGameTick`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
125 |
|
500 | 126 |
<code language="lua">function onGameTick() |
528 | 127 |
AnimUnWait() |
128 |
if ShowAnimation() == false then |
|
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
129 |
return |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
130 |
end |
528 | 131 |
ExecuteAfterAnimations() |
132 |
CheckEvents() |
|
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
133 |
end</code> |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
134 |
|
528 | 135 |
Also, `AnimInit()` needs to be called in `onGameInit()`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
136 |
Each of these functions will be explained below. |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
137 |
|
742 | 138 |
=== Cinematic handling === |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
139 |
|
742 | 140 |
==== `ShowAnimation()` ==== |
528 | 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)`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
142 |
|
742 | 143 |
==== `AddAnim(steps)` ==== |
528 | 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`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
145 |
|
528 | 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. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
147 |
|
528 | 148 |
* `args` is a table containing the arguments that need to be passed to the function given |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
149 |
|
528 | 150 |
* `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. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
151 |
Example: |
500 | 152 |
<code language="lua">cinem = { |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
153 |
{func = AnimSay, args = {myHog, "Snails! SNAILS!", SAY_SAY, 3000}}, |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
154 |
{func = AnimMove, args = {myhog, "Left", 2000, 0}}, |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
155 |
{func = AddCaption, swh = false, args = {"But he found no more snails..."}} |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
156 |
} |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
157 |
AddAnim(cinem)</code> |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
158 |
|
742 | 159 |
==== `RemoveAnim(steps)` ==== |
528 | 160 |
Removes `steps` from the animations array. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
161 |
|
528 | 162 |
=== `AddSkipFunction(anim, func, args)` === |
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. |
|
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
164 |
Example: |
500 | 165 |
<code language="lua">AddSkipFunc(cinem, SkipCinem, {})</code> |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
166 |
|
742 | 167 |
==== `RemoveSkipFunction(anim)` ==== |
528 | 168 |
Removes the skip function associated with `anim`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
169 |
|
742 | 170 |
==== `SetAnimSkip(bool)` ==== |
528 | 171 |
Sets the state of animation skipping to `bool`. It is useful in case the player is allowed to skip the animation. |
172 |
||
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
173 |
Example: |
500 | 174 |
<code language="lua">function onPrecise() |
528 | 175 |
if AnimInProgress() then |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
176 |
SetAnimSkip(true) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
177 |
end |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
178 |
end</code> |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
179 |
|
742 | 180 |
==== `AnimInProgress()` ==== |
528 | 181 |
Returns `true` if a cinematic is currently taking place, `false` otherwise. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
182 |
|
742 | 183 |
==== `ExecuteAfterAnimations()` ==== |
528 | 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`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
185 |
|
742 | 186 |
==== `AddFunction(element)` ==== |
528 | 187 |
Adds `element` to the functions array that are to be called after the cinematic. `element` is a table with the keys: `func`, `args`. |
188 |
||
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
189 |
Example: |
500 | 190 |
<code language="lua">AddFunction({func = AfterCinem, args = {2}})</code> |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
191 |
|
742 | 192 |
==== `RemoveFunction()` ==== |
528 | 193 |
Removes the first function from the aforementioned list. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
194 |
|
742 | 195 |
==== `AnimInit()` ==== |
528 | 196 |
Initializes variables used by the other functions. Needs to be called in `onGameInit`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
197 |
|
742 | 198 |
==== !AnimUnWait() ==== |
528 | 199 |
Decreases the wait time used by cinematics. It is best called in `onGameTick`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
200 |
|
742 | 201 |
=== Cinematic functions === |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
202 |
|
742 | 203 |
==== `AnimSwitchHog(gear)` ==== |
528 | 204 |
Switches to `gear` and follows it. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
205 |
|
742 | 206 |
==== `AnimWait(gear, time)` ==== |
528 | 207 |
Increases the wait time by `time`. `gear` is just for compatibility with `ShowAnimation`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
208 |
|
742 | 209 |
==== `AnimSay(gear, text, manner, time` ==== |
528 | 210 |
Calls `HogSay` with the first three arguments and increses the wait time by `time`. |
211 |
||
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
212 |
Example: |
500 | 213 |
<code language="lua">cinem = { |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
214 |
{func = AnimSay, args = {gear1, "You're so defensive!", SAY_SAY, 2500}}, |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
215 |
{func = AnimSay, args = {gear2, "No, I'm not!", SAY_SAY, 2000}} |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
216 |
}</code> |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
217 |
|
742 | 218 |
==== `AnimSound(gear, sound, time)` ==== |
528 | 219 |
Plays the sound `sound` and increases the wait time by `time`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
220 |
|
742 | 221 |
==== `AnimTurn(hog, dir)` ==== |
528 | 222 |
Makes `hog` face in direction `dir`, where `dir` equals either `"Right"` or `"Left"`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
223 |
|
742 | 224 |
==== `AnimMove(hog, dir, x, y)` ==== |
528 | 225 |
Makes `hog` move in direction `dir` until either his horizontal coordinate is `x` or his vertical coordinate is `y`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
226 |
|
742 | 227 |
==== `AnimJump(hog, jumpType)` ==== |
528 | 228 |
Makes `hog` perform a jump of type `jumpType`, where `jumpType` equals either `"long"`, `"high"` or `"back"`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
229 |
|
742 | 230 |
==== `AnimSetGearPosition(gear, x, y, fall)` ==== |
528 | 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. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
232 |
|
742 | 233 |
==== `AnimDisappear(gear, x, y)` ==== |
528 | 234 |
Teleports the gear to (`x`, `y`), adding some effects at the previous position and sounds. Doesn’t follow the gear. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
235 |
|
742 | 236 |
==== `AnimOutOfNowhere(gear, x, y)` ==== |
528 | 237 |
Teleports the gear to (`x`, `y`), adding effects and sounds at the final position. Follows gear. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
238 |
|
742 | 239 |
==== `AnimTeleportGear(gear, x, y)` ==== |
528 | 240 |
Teleports the gear to (`x`, `y`), adding effects and sounds both at the starting position and the final position. Follows gear. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
241 |
|
742 | 242 |
==== `AnimVisualGear(gear, x, y, vgType, state, critical, follow)` ==== |
528 | 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. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
244 |
|
742 | 245 |
==== `AnimCaption(gear, text, time)` ==== |
528 | 246 |
Adds `text` as caption and increases wait time by `time`. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
247 |
|
742 | 248 |
==== `AnimCustomFunction(gear, func, args)` ==== |
528 | 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. |
250 |
||
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
251 |
Example: |
500 | 252 |
<code language="lua">function NeedToTurn(hog1, hog2) |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
253 |
if GetX(hog1) < GetX(hog2) then |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
254 |
HogTurnLeft(hog1, false) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
255 |
HogTurnLeft(hog2, true) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
256 |
else |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
257 |
HogTurnLeft(hog2, false) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
258 |
HogTurnLeft(hog1, true) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
259 |
end |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
260 |
end |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
261 |
|
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
262 |
cinem = {{func = AnimCustomFunction, args = {hog1, NeedToTurn, {hog1, hg2}}}}</code> |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
263 |
|
742 | 264 |
==== `AnimInsertStepNext(step)` ==== |
528 | 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. |
266 |
||
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
267 |
Example: |
500 | 268 |
<code language="lua">function BlowHog(deadHog) |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
269 |
AnimInsertStepNext({func = DeleteGear, args = {deadHog}, swh = false}) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
270 |
AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog), GetY(deadHog), vgtBigExplosion, 0, true}, swh = false}) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
271 |
AnimInsertStepNext({func = AnimWait, args = {deadHog, 1200}}) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
272 |
AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) + 20, GetY(deadHog), vgtExplosion, 0, true}, swh = false}) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
273 |
AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}}) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
274 |
AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) + 10, GetY(deadHog), vgtExplosion, 0, true}, swh = false}) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
275 |
AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}}) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
276 |
AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) - 10, GetY(deadHog), vgtExplosion, 0, true}, swh = false}) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
277 |
AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}}) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
278 |
AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) - 20, GetY(deadHog), vgtExplosion, 0, true}, swh = false}) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
279 |
end |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
280 |
cinem = {{func = AnimCustomFunction, args = {liveHog, BlowHog, {deadHog}}}}</code> |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
281 |
|
742 | 282 |
=== Event handling === |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
283 |
|
528 | 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. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
285 |
|
742 | 286 |
==== `AddEvent(condFunc, condArgs, doFunc, doArgs, evType)` ==== |
528 | 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). |
288 |
||
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
289 |
Example: |
500 | 290 |
<code language="lua">function CheckPos() |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
291 |
return GetX(myHog) > 1500 |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
292 |
end |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
293 |
function CheckAmmo() |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
294 |
return GetAmmoCount(myHog, amGrenade) == 0 |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
295 |
end |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
296 |
function DoPos() |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
297 |
ShowMission("Scooter", "Mover", "Nice Work", 0, 0) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
298 |
end |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
299 |
function DoAmmo() |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
300 |
AddAmmo(myHog, amGrenade, 5) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
301 |
end |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
302 |
AddEvent(CheckPos, {}, DoPos, {}, 0) -- Add event that gets removed on completion |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
303 |
AddEvent(CheckAmmo, {}, DoAmmo, {}, 1) -- Add repeating event</code> |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
304 |
|
742 | 305 |
==== `AddNewEvent(condFunc, condArgs, doFunc, doArgs, evType)` ==== |
528 | 306 |
Does the same as `AddEvent`, but first checks if the event is already in the list so that it isn’t added twice. |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
307 |
|
742 | 308 |
==== `RemoveEventFunc(cFunc, cArgs)` ==== |
528 | 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. |
310 |
||
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
311 |
Example: |
500 | 312 |
<code language="lua">AddEvent(condFunc1, condArgs1, doFunc, doArgs) |
246
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
313 |
AddEvent(condFunc1, condArgs2, doFunc, doArgs) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
314 |
AddEvent(condFunc1, condArgs2, doFunc, doArgs) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
315 |
AddEvent(condFunc2, condArgs1, doFunc, doArgs) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
316 |
AddEvent(condFunc2, condArgs2, doFunc, doArgs) |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
317 |
RemoveEventFunc(condFunc1) --Removes all three events that have condFunc1 |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
318 |
RemoveEventFunc(condFunc2, condArgs1) --Removes a single event</code> |
7b1a6c46c3b5
Edited wiki page LuaLibraries through web user interface.
szabibibi@gmail.com
parents:
103
diff
changeset
|
319 |
|
742 | 320 |
==== `CheckEvents` ==== |
530 | 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`. |
526 | 322 |
|
323 |
||
742 | 324 |
== Params == |
526 | 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. |
326 |
||
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: |
|
328 |
||
531 | 329 |
<code>speed=1</code> |
330 |
<code>health=100, ammo=5</code> |
|
331 |
<code>param1=hello, param2=whatever, param3=5325.4</code> |
|
332 |
||
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. |
|
526 | 334 |
|
742 | 335 |
==== `parseParams()` ==== |
526 | 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. |
337 |
||
742 | 338 |
===== Example ===== |
526 | 339 |
<code language="lua"> |
340 |
function onParameters() |
|
341 |
parseParams() |
|
342 |
if params["myparam1"] == "hello" then |
|
343 |
WriteLnToConsole("Hello World!") |
|
344 |
end |
|
528 | 345 |
end</code> |
526 | 346 |
|
347 |
If the key-value pair `myparam1=hello` is present, this script writes “Hello World!” in the console. All these inputs would trigger the event: |
|
348 |
||
531 | 349 |
<code>myparam1=hello</code> |
350 |
<code>myparam2=whatever, myparam1=hello</code> |
|
532 | 351 |
<code>g=4, f=56, m=56, myparam1=hello</code> |
352 |
||
353 |
||
354 |
||
742 | 355 |
== !TargetPractice == |
532 | 356 |
Starting with 0.9.21, this library provides a function to create an entire target practice mission which follows some basic properties. |
357 |
||
358 |
Here is a brief description of the generated missions: |
|
359 |
* The player will get a team with a single hedgehog. |
|
360 |
* The team gets a single predefined weapon infinitely times. |
|
361 |
* A fixed sequence of targets will spawn at predefined positions. |
|
362 |
* When a target has been destroyed, the next target of the target sequence appears |
|
363 |
* The mission ends successfully when all targets have been destroyed |
|
364 |
* The mission ends unsuccessfully when the time runs out or the hedgehog dies |
|
365 |
* 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. |
|
366 |
||
367 |
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. |
|
368 |
||
369 |
Thos library also loads the Locale library for its own purposes. If you use !TargetPractice, you do not have to explicitly load Locale anymore. |
|
370 |
||
371 |
=== `TargetPracticeMission(params)` === |
|
372 |
This function sets up the *entire* training mission and needs one argument: `params`. |
|
373 |
`params` is a table containing fields which describe the training mission. |
|
374 |
||
375 |
There are mandatory and optional fields. The optional fields have default values. |
|
376 |
||
377 |
Mandatory fields: |
|
378 |
|| *Field name* || *Description* || |
|
379 |
|| `missionTitle` || The name of the mission || |
|
380 |
|| `map` || The name of the image map to be used || |
|
381 |
|| `theme` || The name of the theme (can be background theme, too) || |
|
382 |
|| `time` || The time limit in milliseconds || |
|
383 |
|| `ammoType` || The [AmmoTypes ammo type] of the weapon to be used || |
|
384 |
|| `gearType` || The [GearTypes gear type] of the gear which is fired by the weapon (used to count shots) || |
|
385 |
|| `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. || |
|
386 |
||
387 |
Optional fields: |
|
388 |
|| *Field name* || *Description * || |
|
389 |
|| `wind` || The initial wind (`-100` to `100`) (default: `0` (no wind)) || |
|
390 |
|| `solidLand` || Weather the terrain is indestructible (default: `false`) || |
|
391 |
|| `artillery` || If `true`, the hog can’t move (default: `false`) || |
|
392 |
|| `hogHat` || Hat of the hedgehog (default: `"NoHat"`) || |
|
393 |
|| `hogName` || Name of the hedgehog (default: `"Trainee"`) || |
|
394 |
|| `teamName` || Name of the hedgehog’s team (default: `"Training Team"`) || |
|
395 |
|| `teamGrave` || Name of the hedgehog’s grave || |
|
396 |
|| `clanColor` || Color of the (only) clan (default: `0xFF0204`, which is a red tone) || |
|
397 |
|| `goalText` || A short string explaining the goal of the mission (default: `"Destroy all targets within the time!"`) || |
|
398 |
|| `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."`) || |
|
399 |
||
400 |
||
401 |
==== Example ==== |
|
402 |
Below is the complete source code of the mission “Target Practice: Cluster Bomb”: |
|
403 |
||
404 |
<code language="lua">HedgewarsScriptLoad("/Scripts/TargetPractice.lua") |
|
405 |
||
406 |
local params = { |
|
407 |
ammoType = amClusterBomb, |
|
408 |
gearType = gtClusterBomb, |
|
409 |
missionTitle = "Cluster Bomb Training", |
|
410 |
solidLand = false, |
|
411 |
map = "Trash", |
|
412 |
theme = "Golf", |
|
413 |
hog_x = 756, |
|
414 |
hog_y = 370, |
|
415 |
hogName = loc("Private Nolak"), |
|
416 |
hogHat = "war_desertgrenadier1", |
|
417 |
teamName = loc("The Hogies"), |
|
418 |
targets = { |
|
419 |
{ x = 628, y = 0 }, |
|
420 |
{ x = 891, y = 0 }, |
|
421 |
{ x = 1309, y = 0 }, |
|
422 |
{ x = 1128, y = 0 }, |
|
423 |
{ x = 410, y = 0 }, |
|
424 |
{ x = 1564, y = 0 }, |
|
425 |
{ x = 1248, y = 476 }, |
|
426 |
{ x = 169, y = 0 }, |
|
427 |
{ x = 1720, y = 0 }, |
|
428 |
{ x = 1441, y = 0 }, |
|
429 |
{ x = 599, y = 0 }, |
|
430 |
{ x = 1638, y = 0 }, |
|
431 |
}, |
|
432 |
time = 180000, |
|
433 |
shootText = loc("You have thrown %d cluster bombs."), |
|
434 |
} |
|
435 |
||
683 | 436 |
TargetPracticeMission(params)</code> |
437 |
||
742 | 438 |
== !SpeedShoppa == |
683 | 439 |
Starting with 0.9.22, this library provides a function to create a simple shoppa-style mission. |
440 |
||
684 | 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. |
683 | 442 |
|
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. |
|
444 |
||
445 |
=== `SpeedShoppaMission(params)` === |
|
446 |
This function sets up the *entire* mission and needs one argument: `params`. |
|
447 |
The argument “`params`” is a table containing fields which describe the training mission. |
|
448 |
||
449 |
Mandatory fields: |
|
450 |
||
451 |
|| *Field name* || *Description* || |
|
452 |
|| `map` || The name of the map to be used || |
|
453 |
|| `theme` || The name of the theme (does not need to be a standalone theme) || |
|
454 |
|| `time` || The time limit in milliseconds || |
|
684 | 455 |
|| `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. || |
683 | 456 |
|
457 |
Optional fields: |
|
458 |
||
459 |
|| *Field name* || *Description* || |
|
460 |
|| `missionTitle` || The name of the mission (optional but highly recommended) (default: `"Speed Shoppa"`) || |
|
461 |
|| `hogHat` || Hat of the hedgehog (default: `"NoHat"`) || |
|
462 |
|| `hogName` || Name of the hedgehog (default: `"Roper"`) || |
|
463 |
|| `teamName` || Name of the hedgehog’s team (default: `"Shoppers"`) || |
|
464 |
|| `teamGrave` || Name of the hedgehog’s grave (default: `"Statue"`) || |
|
465 |
|| `teamFlag` || Name of the team’s flag (default: `"cm_shoppa"`) || |
|
466 |
|| `clanColor` || Color of the (only) clan (default: `0xFF0204`, which is a red tone) || |
|
467 |
|| `goalText` || A short string explaining the goal of the mission (default: `"Use your rope to collect all crates as fast as possible."`) || |
|
468 |
|| `faceLeft` || If `true`, the hog faces to the left initially, if false, it faces to the right. (default: `false` (=right)) || |
|
469 |
|| `crateType` || Specify the type of crate (this has no gameplay effect), pick one of `"ammo"`, `"utility"`, `"health"`. Default: `"ammo"` || |
|
470 |
|| `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 || |
|
471 |
|| `extra_onGameInit` || A function which is called at the end of this script's `onGameInit` || |