--- a/LuaLibraries.wiki Mon Dec 15 14:56:32 2014 +0000
+++ b/LuaLibraries.wiki Mon Dec 15 15:27:32 2014 +0000
@@ -5,7 +5,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.
To use a library you only need to add one row at the top of the script:
-<code lang="lua">
+<code language="lua">
loadfile(GetDataPath() .. "Scripts/<Library Name>.lua")()
</code>
Where <Library Name> is replaced by the name. Do not forget the "()" at the end as this initialises the file.
@@ -43,7 +43,7 @@
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.
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:
-<code lang="lua">
+<code language="lua">
function killall(gear)
SetHealth(gear, 0)
end
@@ -119,7 +119,7 @@
In order to use it's full potential, the following lines need to be at the beginning of onGameTick.
-<code lang="lua">function onGameTick()
+<code language="lua">function onGameTick()
!AnimUnWait()
if !ShowAnimation() == false then
return
@@ -145,7 +145,7 @@
* _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.</blockquote>
Example:
-<code lang="lua">cinem = {
+<code language="lua">cinem = {
{func = AnimSay, args = {myHog, "Snails! SNAILS!", SAY_SAY, 3000}},
{func = AnimMove, args = {myhog, "Left", 2000, 0}},
{func = AddCaption, swh = false, args = {"But he found no more snails..."}}
@@ -158,7 +158,7 @@
=== !AddSkipFunction(anim, func, args) ===
<blockquote>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.</blockquote>
Example:
-<code lang="lua">AddSkipFunc(cinem, SkipCinem, {})</code>
+<code language="lua">AddSkipFunc(cinem, SkipCinem, {})</code>
=== !RemoveSkipFunction(anim) ===
<blockquote> Removes the skip function associated with _anim_.</blockquote>
@@ -166,7 +166,7 @@
=== !SetAnimSkip(bool) ===
<blockquote> Sets the state of animation skipping to _bool_. It is useful in case the player is allowed to skip the animation.</blockquote>
Example:
-<code lang="lua">function onPrecise()
+<code language="lua">function onPrecise()
if !AnimInProgress() then
SetAnimSkip(true)
end
@@ -181,7 +181,7 @@
=== !AddFunction(element) ===
<blockquote> Adds _element_ to the functions array that are to be called after the cinematic. _element_ is a table with the keys: func, args.</blockquote>
Example:
-<code lang="lua">AddFunction({func = AfterCinem, args = {2}})</code>
+<code language="lua">AddFunction({func = AfterCinem, args = {2}})</code>
=== !RemoveFunction() ===
<blockquote> Removes the first function from the aforementioned list.</blockquote>
@@ -203,7 +203,7 @@
=== !AnimSay(gear, text, manner, time) ===
<blockquote> Calls HogSay with the first three arguments and increses the wait time by _time_.</blockquote>
Example:
-<code lang="lua">cinem = {
+<code language="lua">cinem = {
{func = AnimSay, args = {gear1, "You're so defensive!", SAY_SAY, 2500}},
{func = AnimSay, args = {gear2, "No, I'm not!", SAY_SAY, 2000}}
}</code>
@@ -241,7 +241,7 @@
=== !AnimCustomFunction(gear, func, args) ===
<blockquote> 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.</blockquote>
Example:
-<code lang="lua">function NeedToTurn(hog1, hog2)
+<code language="lua">function NeedToTurn(hog1, hog2)
if GetX(hog1) < GetX(hog2) then
HogTurnLeft(hog1, false)
HogTurnLeft(hog2, true)
@@ -256,7 +256,7 @@
=== !AnimInsertStepNext(step) ===
<blockquote> 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.</blockquote>
Example:
-<code lang="lua">function BlowHog(deadHog)
+<code language="lua">function BlowHog(deadHog)
AnimInsertStepNext({func = DeleteGear, args = {deadHog}, swh = false})
AnimInsertStepNext({func = AnimVisualGear, args = {deadHog, GetX(deadHog), GetY(deadHog), vgtBigExplosion, 0, true}, swh = false})
AnimInsertStepNext({func = AnimWait, args = {deadHog, 1200}})
@@ -277,7 +277,7 @@
=== !AddEvent(condFunc, condArgs, doFunc, doArgs, evType) ===
<blockquote> 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).</blockquote>
Example:
-<code lang="lua">function CheckPos()
+<code language="lua">function CheckPos()
return GetX(myHog) > 1500
end
function CheckAmmo()
@@ -298,7 +298,7 @@
=== !RemoveEventFunc(cFunc, cArgs) ===
<blockquote> Removes the event(s) that have _cFunc_ as the condition checking function. If _cArgs_ is not nil then only those events get removed that have _cArgs_ as arguments for _cFunc_, too.</blockquote>
Example:
-<code lang="lua">AddEvent(condFunc1, condArgs1, doFunc, doArgs)
+<code language="lua">AddEvent(condFunc1, condArgs1, doFunc, doArgs)
AddEvent(condFunc1, condArgs2, doFunc, doArgs)
AddEvent(condFunc1, condArgs2, doFunc, doArgs)
AddEvent(condFunc2, condArgs1, doFunc, doArgs)