author | Wuzzy |
Wed, 02 May 2018 23:42:11 +0100 | |
changeset 1365 | f7ca5312d2ff |
parent 1364 | a0547181393a |
child 1366 | 680a173ead44 |
permissions | -rw-r--r-- |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
1 |
#summary Lua library documentation: Tracker |
1346 | 2 |
#labels !LuaLibrary |
1329
bd781e19a52d
Split Lua libraries into several sub-pages
Wuzzy <almikes@aol.com>
parents:
diff
changeset
|
3 |
= Lua library: `Tracker` = |
1364 | 4 |
<wiki:toc max_depth="3" /> |
5 |
||
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 | 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 | 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. |
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 | 38 |
=== `trackHiding(gear)` === |
39 |
Will keep track of the given hedgehog gear when it is hidden. |
|
40 |
||
41 |
=== `trackRestoring(gear)` === |
|
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 | 45 |
These functions are used to run a function on tracked gears, teams and clans. |
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 | 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 | 56 |
=== `runOnHogsInOtherTeams(func, team)` === |
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 | 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 | 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 | 65 |
== Helper functions == |
66 |
=== `getFirstHogOfClan(clan)` === |
|
67 |
Returns the first hedgehog (alive or not) in the clan with clan ID `clan`. |
|
68 |
||
1361 | 69 |
== Key-value storage == |
1365 | 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 | 71 |
|
72 |
=== `getGearValue(gear, key)` === |
|
1365 | 73 |
Returns the gear value of the given `gear` for `key`. |
1361 | 74 |
|
75 |
=== `setGearValue(gear, key, value)` === |
|
1365 | 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 | 78 |
=== `increaseGearValue(gear, key)` === |
79 |
Increases the gear value for `key` by 1. This function *must not* be called if the current value is not a number. |
|
1361 | 80 |
|
1365 | 81 |
=== `decreaseGearValue(gear, key)` === |
82 |
Decreases the gear value for `key` by 1. This function *must not* be called if the current value is not a number. |
|
1361 | 83 |
|
84 |
=== `getTeamValue(team, key)` === |
|
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 | 87 |
=== `setTeamValue(team, key, value)` === |
88 |
Sets the team value with given `key` to `value`. `team` is the team name. |
|
89 |
||
90 |
=== `increaseTeamValue(team, key)` === |
|
1365 | 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 | 92 |
|
93 |
=== `decreaseTeamValue(team, key)` === |
|
1365 | 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 | 95 |
|
1365 | 96 |
=== `getClanValue(clan, key)` === |
1361 | 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 | 99 |
=== `setClanValue(clan, key, value)` === |
1361 | 100 |
Sets the clan value with given `key` to `value`. `clan` is the clan ID. |
101 |
||
1365 | 102 |
=== `increaseClanValue(clan, key)` === |
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 | 105 |
=== `decreaseClanValue(clan, key)` === |
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. |