LuaLibraryTracker.wiki
author Wuzzy
Wed, 02 May 2018 22:48:07 +0100
changeset 1330 d92ed3272533
parent 1329 bd781e19a52d
child 1337 846febb1625b
permissions -rw-r--r--
LuaLibraries: fix indent

#summary Lua library documentation: Tracker
#labels LuaLibrary WIP

= Lua library: `Tracker` =

**NOTE: Documentation of this library is incomplete, some functions are still undocumented.**

This Lua 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.

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 language="lua">function killall(gear)
    SetHealth(gear, 0)
end

function onGearDelete(gear)
    if GetGearType(gear) == gtTarget then
        runOnHogs(killall)
    end
end</code>
This will kill all hogs if a target is destroyed.

To see a commented example of the tracker in use by a script you can look at
[https://hg.hedgewars.org/hedgewars/file/default/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Random Weapons].

== Tracking functions ==

=== `trackGear(gear)` ===

Will keep track of the gear.


=== `trackDeletion(gear)` ===

Will stop keeping track of the gear (gears not tracked will be ignored).


=== `trackTeams()` ===

Will start the tracking of teams, clans and hedgehogs (hogs can be tracked without this).


== “`runOn`” functions ==

=== `runOnGears(func)` ===

Runs the function `func` on all gears.


=== `runOnHogs(func)` ===

Runs the function `func` on all hedgehogs.


=== `runOnHogsInTeam(func, team)` ===

Runs the function `func` on all hedgehogs in the specified team.


=== runOnHogsInOtherTeams(func, team) ===

Runs the function `func` on all hedgehogs but those in the specified team.


=== `runOnHogsInClan(func, clan)` ===

Runs the function `func` on all hedgehogs in the specified clan.


=== `runOnHogsInOtherClans(func, clan)` ===

Runs the function `func` on all hedgehogs but those in the specified clan.


== Variable functions ==

_To be continued …_