author | Wuzzy |
Wed, 21 Jun 2023 13:08:24 +0000 | |
changeset 2244 | e8e1c0dd32e5 |
parent 2243 | e58371e25834 |
child 2245 | 3e97c75aaddc |
permissions | -rw-r--r-- |
1374 | 1 |
#summary Lua library documentation of Animate; for cinematics, cut-scenes and other nice animations |
1347 | 2 |
#labels !LuaLibrary |
2103 | 3 |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
4 |
= Lua library: `Animate` = |
2239 | 5 |
<wiki:toc max_depth="3" /> |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
6 |
This library provides functions that aid cinematic/cut-scene creation and functions for handling events. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
7 |
|
2237 | 8 |
== Structure of an Animate script == |
9 |
||
10 |
The Animate library is somewhat complex, so this section explains how scripts using the Animate library are supposed to look like and how the functions interact. |
|
2236 | 11 |
|
2237 | 12 |
=== Initial code === |
13 |
||
14 |
For every script using this library, the following lines need to be at the beginning of `onGameTick`: |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
15 |
|
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
16 |
<code language="lua">function onGameTick() |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
17 |
AnimUnWait() |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
18 |
if ShowAnimation() == false then |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
19 |
return |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
20 |
end |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
21 |
ExecuteAfterAnimations() |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
22 |
CheckEvents() |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
23 |
end</code> |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
24 |
|
2236 | 25 |
Also, `AnimInit()` needs to be called in `onGameInit()`: |
26 |
||
27 |
<code language="lua">function onGameInit() |
|
28 |
AnimInit() |
|
29 |
end</code> |
|
30 |
||
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
31 |
Each of these functions will be explained below. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
32 |
|
2238 | 33 |
Also, if your script calls `SetInputMask`, you *must* replace each call of it with `AnimSetInputMask` (see function description below). Failing to do so may lead to bugs. |
2237 | 34 |
|
2238 | 35 |
Also, you *must not* call `SetCinematicMode` ever in your script. |
2237 | 36 |
|
37 |
=== Steps === |
|
38 |
||
39 |
The step is the primary data structure of this library. A step is a single action in an animation specified in table form. A step table must have the following fields: |
|
40 |
||
2238 | 41 |
* `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 could theoretically be any function, but usually you want to use one of the cinematic functions here. |
42 |
* `args` is a list containing the arguments that need to be passed to the function given, in the same order |
|
2244 | 43 |
* `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 1 in `args`. You *must* set this to `false` if argument 1 is not a hedgehog. |
2237 | 44 |
|
45 |
Example 1: |
|
46 |
<code language="lua"> |
|
47 |
-- This calls `AnimSay(myHog, "Snails! SNAILS!", SAY_SAY, 3000)`, |
|
48 |
-- meaning the hedgehog gear `myHog` will say "Snails!" and set the animation delay to 3000 milliseconds |
|
49 |
-- Because `swh` is not set, it is true, so `myHog` also becomes the current hedgehog |
|
50 |
local step1 = {func = AnimSay, args = {myHog, "Snails!", SAY_SAY, 3000}} |
|
51 |
</code> |
|
52 |
||
53 |
Example 2: |
|
54 |
<code language="lua"> |
|
55 |
-- Moves myHog to the left |
|
56 |
local step2 = {func = AnimMove, args = {myHog, "Left", 2000, 0}} |
|
57 |
</code> |
|
58 |
||
59 |
Example 3: |
|
60 |
<code language="lua"> |
|
61 |
-- Shows the caption "Hello, world!". Because argument 1 is not a hedgehog, `swh` is false |
|
62 |
local step3 = {func = AddCaption, swh = false, args = {"Hello, world!"}} |
|
63 |
</code> |
|
64 |
||
65 |
=== How animation works === |
|
66 |
||
67 |
The Animation library has two states: *Animating* and *Not Animating*. By default, the game starts in the *Not Animating* state, meaning the game behaves normally. In *Animating* state, the library looks at the list of registered animations and executes them one by one, in that order. |
|
68 |
||
69 |
You are expected to add to the list of animatinons with `AddAnim`. If the script is animating, this animation will be played after all the others have been played. If the script is not animating, the animation will be played immediately. (Assuming you have correctly added the boilerplate code mentioned at the beginning of this page.) |
|
70 |
||
71 |
Animations are basically cut scenes. During animation, Cinematic Mode is enabled (see `SetCinematicMode` which is part of the main Lua API) and most player input is blocked. Animations can cause various things to happen, like move hedgehogs, show speech bubbles, explode the landscape or just call (almost) any function. During an animation, the player can only watch or optionally skip (details later). The player can still move the camera. |
|
72 |
||
73 |
There is also an internal wait time. It starts at 0 and a few cinematic functions as well as `AnimWait` can increase this time. The wait time counts down to 0, during which the script waits to execute the next animation step. Adding to the wait time is important to time your animation correctly. |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
74 |
|
2242
031a5b86e533
LuaLibraryAnimate: Say what happens after animation ends
Wuzzy
parents:
2241
diff
changeset
|
75 |
Once all animations in the animation list have been played, the game returns to the *Not Animating* state and behaves normally again. |
031a5b86e533
LuaLibraryAnimate: Say what happens after animation ends
Wuzzy
parents:
2241
diff
changeset
|
76 |
|
2239 | 77 |
== Function reference == |
78 |
=== Cinematic handling === |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
79 |
|
2239 | 80 |
==== `AnimInit([startAnimating])` ==== |
1384 | 81 |
Initializes variables used by the other functions. Needs to be called in `onGameInit`. |
82 |
||
2077
514babfbad9e
Remove outdated legacy hints as clutter
Wuzzy <almikes@aol.com>
parents:
1985
diff
changeset
|
83 |
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. |
1384 | 84 |
|
2239 | 85 |
==== `AnimInsertStepNext(step)` ==== |
1384 | 86 |
Inserts `step` after the current step (read: action) in the cinematic array. Useful when an action depends on variables (e.g. positions). It can be used mostly with `AnimCustomFunction`. Note: In case of multiple consecutive calls, steps need to be added in reverse order. |
87 |
||
88 |
Example: |
|
89 |
<code language="lua">function BlowHog(deadHog) |
|
90 |
AnimInsertStepNext({func = DeleteGear, args = {deadHog}, swh = false}) |
|
91 |
AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog), GetY(deadHog), vgtBigExplosion, 0, true}, swh = false}) |
|
92 |
AnimInsertStepNext({func = AnimWait, args = {deadHog, 1200}}) |
|
93 |
AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) + 20, GetY(deadHog), vgtExplosion, 0, true}, swh = false}) |
|
94 |
AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}}) |
|
95 |
AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) + 10, GetY(deadHog), vgtExplosion, 0, true}, swh = false}) |
|
96 |
AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}}) |
|
97 |
AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) - 10, GetY(deadHog), vgtExplosion, 0, true}, swh = false}) |
|
98 |
AnimInsertStepNext({func = AnimWait, args = {deadHog, 100}}) |
|
99 |
AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog) - 20, GetY(deadHog), vgtExplosion, 0, true}, swh = false}) |
|
100 |
end |
|
101 |
cinem = {{func = AnimCustomFunction, args = {liveHog, BlowHog, {deadHog}}}}</code> |
|
102 |
||
2239 | 103 |
==== `ShowAnimation()` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
104 |
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)`. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
105 |
|
2239 | 106 |
==== `Animate(steps)` ==== |
1383 | 107 |
*THIS FUNCTION IS UNDOCUMENTED!* |
1382 | 108 |
|
2239 | 109 |
==== `AddAnim(steps)` ==== |
110 |
Adds `steps` to the array of animations, where `steps` is a table with numbers as keys and the values are animation steps. See the introduction above for the syntax of animation steps. |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
111 |
|
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
112 |
Example: |
2239 | 113 |
<code language="lua"> |
114 |
-- Makes myHog say "Snails! SNAILS!, wait 3 seconds, move it to the left until its X coordinate equals 2000, then show the caption "But he found no more snails ..." |
|
115 |
cinem = { |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
116 |
{func = AnimSay, args = {myHog, "Snails! SNAILS!", SAY_SAY, 3000}}, |
2239 | 117 |
{func = AnimMove, args = {myHog, "Left", 2000, 0}}, |
118 |
{func = AddCaption, swh = false, args = {"But he found no more snails ..."}} |
|
119 |
} |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
120 |
AddAnim(cinem)</code> |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
121 |
|
2239 | 122 |
==== `RemoveAnim(steps)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
123 |
Removes `steps` from the animations array. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
124 |
|
2239 | 125 |
==== `AddSkipFunction(anim, func, args)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
126 |
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. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
127 |
Example: |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
128 |
<code language="lua">AddSkipFunc(cinem, SkipCinem, {})</code> |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
129 |
|
2239 | 130 |
==== `RemoveSkipFunction(anim)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
131 |
Removes the skip function associated with `anim`. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
132 |
|
2239 | 133 |
==== `SetAnimSkip(bool)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
134 |
Sets the state of animation skipping to `bool`. It is useful in case the player is allowed to skip the animation. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
135 |
|
1866 | 136 |
By convention, a cut scene in a singleplayer mission should be skipped when the player presses the Precise key. In this case, use the `onPreciseLocal` callback for this. |
137 |
||
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
138 |
Example: |
1866 | 139 |
<code language="lua">function onPreciseLocal() |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
140 |
if AnimInProgress() then |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
141 |
SetAnimSkip(true) |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
142 |
end |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
143 |
end</code> |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
144 |
|
2239 | 145 |
==== `AnimInProgress()` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
146 |
Returns `true` if a cinematic is currently taking place, `false` otherwise. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
147 |
|
2239 | 148 |
==== `ExecuteAfterAnimations()` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
149 |
Calls the functions (added with `AddFunction`) that need to be executed after the cinematic. The best location for this function call is in `onGameTick`. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
150 |
|
2239 | 151 |
==== `AddFunction(element)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
152 |
Adds `element` to the functions array that are to be called after the cinematic. `element` is a table with the keys: `func`, `args`. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
153 |
|
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
154 |
Example: |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
155 |
<code language="lua">AddFunction({func = AfterCinem, args = {2}})</code> |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
156 |
|
2239 | 157 |
==== `RemoveFunction()` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
158 |
Removes the first function from the aforementioned list. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
159 |
|
2239 | 160 |
==== `AnimUnWait()` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
161 |
Decreases the wait time used by cinematics. It is best called in `onGameTick`. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
162 |
|
2239 | 163 |
==== `AnimSetInputMask(inputMask)` ==== |
1384 | 164 |
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. |
165 |
||
2235 | 166 |
Internally, the input mask you provide is simply AND-ed with the input mask used by the Animate library. Otherwise, this function works like `SetInputMask`. |
1384 | 167 |
|
2235 | 168 |
If you call `SetInputMask` directly, note that it might get quickly overwritten by the Animate library! |
1384 | 169 |
|
2239 | 170 |
=== Cinematic functions === |
2244 | 171 |
These are the functions you can specify in animation steps. In all functions except `AnimWait`, the `gear` argument switches the `CurrentHedgehog` to `gear` and follows it. Hedgehog switching can be disabled with `swh=false` (see definition of animation steps above). |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
172 |
|
2239 | 173 |
==== `AnimSwitchHog(gear)` ==== |
2243 | 174 |
Switches the `CurrentHedgehog` to `gear` and follows it. |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
175 |
|
2244 | 176 |
==== `AnimFollowGear(gear)` ==== |
177 |
Follows `gear`. |
|
178 |
||
2239 | 179 |
==== `AnimGiveState(gear, state)` ==== |
1909 | 180 |
Sets the [States gear state] of `gear` to `state` (full bitmask). |
1382 | 181 |
|
2239 | 182 |
==== `AnimRemoveState(gear, state)` ==== |
1385 | 183 |
Removes the [States gear state] `state` from `gear`. |
1382 | 184 |
|
2239 | 185 |
==== `AnimWait(gear, time)` ==== |
2243 | 186 |
Increases the wait time by `time` (in milliseconds) without changing the `CurrentHedgehog`. The `gear` argument is ignored (it exists for compability with `ShowAnimation). |
187 |
||
188 |
==== `AnimGearWait(gear, time)` ==== |
|
189 |
Increases the wait time by `time` (in milliseconds) and changes the `CurrentHedgehog` to `gear`. |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
190 |
|
2239 | 191 |
==== `AnimSay(gear, text, manner, time)` ==== |
2235 | 192 |
Calls `HogSay` with the first three arguments and increases the wait time by `time`. |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
193 |
|
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
194 |
Example: |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
195 |
<code language="lua">cinem = { |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
196 |
{func = AnimSay, args = {gear1, "You're so defensive!", SAY_SAY, 2500}}, |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
197 |
{func = AnimSay, args = {gear2, "No, I'm not!", SAY_SAY, 2000}} |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
198 |
}</code> |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
199 |
|
2239 | 200 |
==== `AnimSound(gear, sound, time)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
201 |
Plays the sound `sound` and increases the wait time by `time`. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
202 |
|
2239 | 203 |
==== `AnimTurn(hog, dir)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
204 |
Makes `hog` face in direction `dir`, where `dir` equals either `"Right"` or `"Left"`. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
205 |
|
2241 | 206 |
==== `AnimMove(hog, dir, x, y, maxMoveTime)` ==== |
207 |
Makes `hog` walk in direction `dir` (`"Right"` or `"Left"`) until either its horizontal coordinate equals `x` or its vertical coordinate equals `y`. `maxMoveTime` is optional. If specified, the animation will automatically end if this number of milliseconds have passed. |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
208 |
|
2239 | 209 |
==== `AnimJump(hog, jumpType)` ==== |
2240 | 210 |
Makes `hog` perform a jump of type `jumpType`, where `jumpType` is one of: |
211 |
||
212 |
* `"long"`: Long jump |
|
213 |
* `"high"`: High jump |
|
214 |
* `"back"`: Backjump |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
215 |
|
2239 | 216 |
==== `AnimSetGearPosition(gear, x, y, fall)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
217 |
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. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
218 |
|
2239 | 219 |
==== `AnimDisappear(gear, x, y)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
220 |
Teleports the gear to (`x`, `y`), adding some effects at the previous position and sounds. Doesn’t follow the gear. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
221 |
|
2239 | 222 |
==== `AnimOutOfNowhere(gear [, x, y])` ==== |
1985
39daa8abac0b
LuaLibraryAnimate: Optional args in AnimOutOfNowhere
Wuzzy
parents:
1909
diff
changeset
|
223 |
Teleports the gear to (`x`, `y`), adding effects and sounds at the final position. Follows gear. If `x` and `y` are not specified, gear will not teleport, only the animation is played. |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
224 |
|
2239 | 225 |
==== `AnimTeleportGear(gear, x, y)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
226 |
Teleports the gear to (`x`, `y`), adding effects and sounds both at the starting position and the final position. Follows gear. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
227 |
|
2239 | 228 |
==== `AnimVisualGear(gear, x, y, vgType, state, critical)` ==== |
1517 | 229 |
Calls `AddVisualGear` with arguments second to sixth. `gear` is for compatibility only. |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
230 |
|
2239 | 231 |
==== `AnimCaption(gear, text, time)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
232 |
Adds `text` as caption and increases wait time by `time`. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
233 |
|
2239 | 234 |
==== `AnimCustomFunction(gear, func, args)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
235 |
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. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
236 |
|
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
237 |
Example: |
2239 | 238 |
<code language="lua"> |
239 |
-- Make hog1 and hog2 look at each other |
|
240 |
function NeedToTurn(hog1, hog2) |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
241 |
if GetX(hog1) < GetX(hog2) then |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
242 |
HogTurnLeft(hog1, false) |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
243 |
HogTurnLeft(hog2, true) |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
244 |
else |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
245 |
HogTurnLeft(hog2, false) |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
246 |
HogTurnLeft(hog1, true) |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
247 |
end |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
248 |
end |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
249 |
|
2237 | 250 |
cinem = {{func = AnimCustomFunction, args = {hog1, NeedToTurn, {hog1, hog2}}}}</code> |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
251 |
|
2239 | 252 |
=== Event handling === |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
253 |
|
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
254 |
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. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
255 |
|
2239 | 256 |
==== `AddEvent(condFunc, condArgs, doFunc, doArgs, evType)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
257 |
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). |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
258 |
|
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
259 |
Example: |
2237 | 260 |
<code language="lua"> |
261 |
--[[ |
|
262 |
This code shows the mission text "Nice Work" if the hog `myHog` has an X coordinate above 1500, but only once. |
|
263 |
Also, it immediately gives `myHog` 5 grenades once it runs out of grenades. It does that every time this happens. |
|
264 |
]] |
|
265 |
function CheckPos() |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
266 |
return GetX(myHog) > 1500 |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
267 |
end |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
268 |
function CheckAmmo() |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
269 |
return GetAmmoCount(myHog, amGrenade) == 0 |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
270 |
end |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
271 |
function DoPos() |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
272 |
ShowMission("Scooter", "Mover", "Nice Work", 0, 0) |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
273 |
end |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
274 |
function DoAmmo() |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
275 |
AddAmmo(myHog, amGrenade, 5) |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
276 |
end |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
277 |
AddEvent(CheckPos, {}, DoPos, {}, 0) -- Add event that gets removed on completion |
2237 | 278 |
AddEvent(CheckAmmo, {}, DoAmmo, {}, 1) -- Add repeating event |
279 |
</code> |
|
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
280 |
|
2239 | 281 |
==== `AddNewEvent(condFunc, condArgs, doFunc, doArgs, evType)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
282 |
Does the same as `AddEvent`, but first checks if the event is already in the list so that it isn’t added twice. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
283 |
|
2239 | 284 |
==== `RemoveEventFunc(cFunc, cArgs)` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
285 |
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. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
286 |
|
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
287 |
Example: |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
288 |
<code language="lua">AddEvent(condFunc1, condArgs1, doFunc, doArgs) |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
289 |
AddEvent(condFunc1, condArgs2, doFunc, doArgs) |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
290 |
AddEvent(condFunc1, condArgs2, doFunc, doArgs) |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
291 |
AddEvent(condFunc2, condArgs1, doFunc, doArgs) |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
292 |
AddEvent(condFunc2, condArgs2, doFunc, doArgs) |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
293 |
RemoveEventFunc(condFunc1) --Removes all three events that have condFunc1 |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
294 |
RemoveEventFunc(condFunc2, condArgs1) --Removes a single event</code> |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
295 |
|
2239 | 296 |
==== `CheckEvents()` ==== |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
297 |
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`. |
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
298 |
|
2239 | 299 |
=== Misc. === |
1382 | 300 |
|
2239 | 301 |
==== `StoppedGear(gear)` ==== |
1382 | 302 |
Returns `true` if the gear is considered to be resting (not moving). (dX and dY are very small) or if the gear does not exist. |