LuaLibraryTracker.wiki
changeset 1364 a0547181393a
parent 1363 77bece04d563
child 1365 f7ca5312d2ff
equal deleted inserted replaced
1363:77bece04d563 1364:a0547181393a
     1 #summary Lua library documentation: Tracker
     1 #summary Lua library documentation: Tracker
     2 #labels !LuaLibrary
     2 #labels !LuaLibrary
     3 = Lua library: `Tracker` =
     3 = Lua library: `Tracker` =
       
     4 <wiki:toc max_depth="3" />
       
     5 
       
     6 == Introduction ==
     4 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.
     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.
     5 
     8 
     6 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`.
     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`.
     7 
    10 
     8 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:
    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:
    15         runOnHogs(killall)
    18         runOnHogs(killall)
    16     end
    19     end
    17 end</code>
    20 end</code>
    18 This will kill all hogs if a target is destroyed.
    21 This will kill all hogs if a target is destroyed.
    19 
    22 
    20 To see a commented example of the tracker in use by a script you can look at
    23 To see a commented example of `Tracker` in use by a script you can look at
    21 [https://hg.hedgewars.org/hedgewars/file/default/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Random Weapons].
    24 [https://hg.hedgewars.org/hedgewars/file/default/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Random Weapons].
    22 
    25 
    23 <wiki:toc max_depth="3" />
       
    24 == Tracking functions ==
    26 == Tracking functions ==
    25 === `trackGear(gear)` ===
    27 === `trackGear(gear)` ===
    26 Will keep track of the gear.
    28 Will keep track of the gear.
    27 
    29 
    28 === `trackDeletion(gear)` ===
    30 === `trackDeletion(gear)` ===