LuaLibraryTracker.wiki
author Wuzzy
Wed, 02 May 2018 23:42:11 +0100
changeset 1365 f7ca5312d2ff
parent 1364 a0547181393a
child 1366 680a173ead44
permissions -rw-r--r--
LuaLibraryTracker: Fix typos and stuff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
     1
#summary Lua library documentation: Tracker
1346
1886a29a6bce LuaLibraryTracker: labels
Wuzzy
parents: 1337
diff changeset
     2
#labels !LuaLibrary
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
     3
= Lua library: `Tracker` =
1364
a0547181393a LuaLibraryTracker: TOC 2
Wuzzy
parents: 1363
diff changeset
     4
<wiki:toc max_depth="3" />
a0547181393a LuaLibraryTracker: TOC 2
Wuzzy
parents: 1363
diff changeset
     5
a0547181393a LuaLibraryTracker: TOC 2
Wuzzy
parents: 1363
diff changeset
     6
== Introduction ==
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
     7
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.
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
     8
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
     9
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`.
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    10
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    11
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:
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    12
<code language="lua">function killall(gear)
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    13
    SetHealth(gear, 0)
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    14
end
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
function onGearDelete(gear)
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    17
    if GetGearType(gear) == gtTarget then
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    18
        runOnHogs(killall)
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    19
    end
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    20
end</code>
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    21
This will kill all hogs if a target is destroyed.
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    22
1364
a0547181393a LuaLibraryTracker: TOC 2
Wuzzy
parents: 1363
diff changeset
    23
To see a commented example of `Tracker` in use by a script you can look at
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    24
[https://hg.hedgewars.org/hedgewars/file/default/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Random Weapons].
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    25
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    26
== Tracking functions ==
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    27
These functions must be called to start tracking stuff. *IMPORTANT:* The other functions will only work on tracked objects. So make sure you track the things you care about.
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    28
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    29
=== `trackGear(gear)` ===
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    30
Will keep track of the gear.
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    31
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    32
=== `trackDeletion(gear)` ===
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    33
Will stop keeping track of the gear (gears not tracked will be ignored).
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    34
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    35
=== `trackTeams()` ===
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    36
Will start the tracking of teams, clans and hedgehogs (hogs can be tracked without this).
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    37
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    38
=== `trackHiding(gear)` ===
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    39
Will keep track of the given hedgehog gear when it is hidden.
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    40
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    41
=== `trackRestoring(gear)` ===
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    42
Will keep track of the given hedgehog gear when it is un-hidden.
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    43
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    44
== “`runOn`” functions ==
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    45
These functions are used to run a function on tracked gears, teams and clans.
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    46
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    47
=== `runOnGears(func)` ===
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    48
Runs the function `func` on all gears.
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    49
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    50
=== `runOnHogs(func)` ===
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    51
Runs the function `func` on all hedgehogs.
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    52
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    53
=== `runOnHogsInTeam(func, team)` ===
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    54
Runs the function `func` on all hedgehogs in the specified team (`team` = team name).
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    55
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    56
=== `runOnHogsInOtherTeams(func, team)` ===
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    57
Runs the function `func` on all hedgehogs but those in the specified team (`team` = team name).
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    58
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    59
=== `runOnHogsInClan(func, clan)` ===
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    60
Runs the function `func` on all hedgehogs in the specified clan (`clan` = clan ID).
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    61
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    62
=== `runOnHogsInOtherClans(func, clan)` ===
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    63
Runs the function `func` on all hedgehogs but those in the specified clan (`clan` = clan ID).
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    64
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    65
== Helper functions ==
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    66
=== `getFirstHogOfClan(clan)` ===
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    67
Returns the first hedgehog (alive or not) in the clan with clan ID `clan`.
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    68
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    69
== Key-value storage ==
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    70
For tracked gears, teams and clans, you can assign an arbitrary number of values. Each tracked object will have a simple key-value storage. Any data type (besides `nil`) can be used for keys and values. Initially, all keys have the value `nil`.
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    71
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    72
=== `getGearValue(gear, key)` ===
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    73
Returns the gear value of the given `gear` for `key`.
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    74
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    75
=== `setGearValue(gear, key, value)` ===
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    76
Sets the gear value for given `key` to `value`.
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    77
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    78
=== `increaseGearValue(gear, key)` ===
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    79
Increases the gear value for `key` by 1. This function *must not* be called if the current value is not a number.
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    80
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    81
=== `decreaseGearValue(gear, key)` ===
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    82
Decreases the gear value for `key` by 1. This function *must not* be called if the current value is not a number.
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    83
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    84
=== `getTeamValue(team, key)` ===
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    85
Returns the value of the given team (`team` is the team name) for the specified `key`.
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    86
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    87
=== `setTeamValue(team, key, value)` ===
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    88
Sets the team value with given `key` to `value`. `team` is the team name.
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    89
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    90
=== `increaseTeamValue(team, key)` ===
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    91
Increases the team value for `key` by 1. `team` is the team name. This function *must not* be called if the current value is not a number.
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    92
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    93
=== `decreaseTeamValue(team, key)` ===
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    94
Decreases the team value for `key` by 1. `team` is the team name. This function *must not* be called if the current value is not a number.
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    95
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    96
=== `getClanValue(clan, key)` ===
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
    97
Returns the value of the given clan (`clan` is the clan ID) for the specified `key`.
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
    98
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
    99
=== `setClanValue(clan, key, value)` ===
1361
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
   100
Sets the clan value with given `key` to `value`. `clan` is the clan ID.
367b835ac926 LuaLibraryTracker: Add missing functions
Wuzzy
parents: 1360
diff changeset
   101
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
   102
=== `increaseClanValue(clan, key)` ===
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
   103
Increases the clan value for `key` by 1. `clan` is the clan ID. This function *must not* be called if the current value is not a number.
1329
bd781e19a52d Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff changeset
   104
1365
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
   105
=== `decreaseClanValue(clan, key)` ===
f7ca5312d2ff LuaLibraryTracker: Fix typos and stuff
Wuzzy
parents: 1364
diff changeset
   106
Decreases the clan value for `key` by 1. `clan` is the clan ID. This function *must not* be called if the current value is not a number.