diff -r 58b5889fbce4 -r dc66ea78b36d LuaLibraries.wiki --- 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: - + loadfile(GetDataPath() .. "Scripts/.lua")() Where 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: - + 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. -function onGameTick() +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. Example: -cinem = { +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) ===
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.
Example: -AddSkipFunc(cinem, SkipCinem, {}) +AddSkipFunc(cinem, SkipCinem, {}) === !RemoveSkipFunction(anim) ===
Removes the skip function associated with _anim_.
@@ -166,7 +166,7 @@ === !SetAnimSkip(bool) ===
Sets the state of animation skipping to _bool_. It is useful in case the player is allowed to skip the animation.
Example: -function onPrecise() +function onPrecise() if !AnimInProgress() then SetAnimSkip(true) end @@ -181,7 +181,7 @@ === !AddFunction(element) ===
Adds _element_ to the functions array that are to be called after the cinematic. _element_ is a table with the keys: func, args.
Example: -AddFunction({func = AfterCinem, args = {2}}) +AddFunction({func = AfterCinem, args = {2}}) === !RemoveFunction() ===
Removes the first function from the aforementioned list.
@@ -203,7 +203,7 @@ === !AnimSay(gear, text, manner, time) ===
Calls HogSay with the first three arguments and increses the wait time by _time_.
Example: -cinem = { +cinem = { {func = AnimSay, args = {gear1, "You're so defensive!", SAY_SAY, 2500}}, {func = AnimSay, args = {gear2, "No, I'm not!", SAY_SAY, 2000}} } @@ -241,7 +241,7 @@ === !AnimCustomFunction(gear, func, args) ===
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.
Example: -function NeedToTurn(hog1, hog2) +function NeedToTurn(hog1, hog2) if GetX(hog1) < GetX(hog2) then HogTurnLeft(hog1, false) HogTurnLeft(hog2, true) @@ -256,7 +256,7 @@ === !AnimInsertStepNext(step) ===
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.
Example: -function BlowHog(deadHog) +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) ===
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).
Example: -function CheckPos() +function CheckPos() return GetX(myHog) > 1500 end function CheckAmmo() @@ -298,7 +298,7 @@ === !RemoveEventFunc(cFunc, cArgs) ===
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.
Example: -AddEvent(condFunc1, condArgs1, doFunc, doArgs) +AddEvent(condFunc1, condArgs1, doFunc, doArgs) AddEvent(condFunc1, condArgs2, doFunc, doArgs) AddEvent(condFunc1, condArgs2, doFunc, doArgs) AddEvent(condFunc2, condArgs1, doFunc, doArgs)