LuaAPI.wiki
author Wuzzy
Thu, 04 Apr 2019 13:52:44 +0100
changeset 1717 e0911cd9bd82
parent 1716 029712a337ba
child 1718 49d91eb0c2c0
permissions -rw-r--r--
LuaAPI: Fix wrong claims about escape sequences
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
67
eecbb1c261bb Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 66
diff changeset
     1
#summary API for writing Lua scripts in Hedgewars.
284
365362b51148 This is cool stuff, let's put it on the project frontpage (adding "featured" tag)
sheepyluva@gmail.com
parents: 244
diff changeset
     2
#labels Featured
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
     3
741
8fa25c5a4967 LuaAPI: Add title
Wuzzy
parents: 692
diff changeset
     4
= Core Lua API documentation =
8fa25c5a4967 LuaAPI: Add title
Wuzzy
parents: 692
diff changeset
     5
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
     6
== Introduction ==
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
     7
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
     8
Version 0.9.13 of Hedgewars introduced the ability to use Lua scripts to modify Hedgewars behaviour for different maps without having to recompile the whole game. The till then used triggers (only appeared in training maps) were removed.
1426
2a4793897bb1 LuaAPI: fix typos
Wuzzy
parents: 1425
diff changeset
     9
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    10
Lua is an easy to learn scripting language that’s implemented using open source libraries. If you’d like to learn more about Lua, have a look at [http://www.lua.org Lua's official homepage]. Even though its easy to learn syntax this wiki page won't explain all basics of using Lua, e.g. declaring variables or using control structures. There are tons of step-by-step tutorials and documentation available on the internet. Just throw “Lua” into your favourite search engine and give it a try.
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    11
519
b757c990bd5c Moved TOC a little bit further down.
almikes@aol.com
parents: 515
diff changeset
    12
=== About this wiki page ===
1240
7c0f5e773736 LuaAPI: fix typo
Wuzzy
parents: 1235
diff changeset
    13
This page might become outdated. For a list of undocumented functions, see [http://hw.ercatec.net/docs/lua_wiki_check.php].
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    14
519
b757c990bd5c Moved TOC a little bit further down.
almikes@aol.com
parents: 515
diff changeset
    15
<wiki:toc max_depth="4" />
b757c990bd5c Moved TOC a little bit further down.
almikes@aol.com
parents: 515
diff changeset
    16
859
16f26a7c87d9 LuaAPI: fix typo in title overview
Wuzzy
parents: 858
diff changeset
    17
== Overview ==
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    18
=== How Hedgewars handles Lua scripts ===
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    19
As of Version 0.9.20, Hedgewars supports Lua scripts for two similar tasks: Define tutorial missions, campaign missions or provide special map behaviour for precreated maps. It is also used for multiplayer scripts to create new game styles.
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    20
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    21
=== Tutorial missions ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    22
Tutorial missions are located within text files inside `share/hedgewars/Data/Missions/Training`. The game will list all files with the lua extension inside this directory in the Training selection screen. You’ll find some premade example scripts within this directory that contain several comments on the script lines and what they do.
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    23
567
17cf8a0c007f Link to [Missions].
almikes@aol.com
parents: 564
diff changeset
    24
See [Missions] for details.
17cf8a0c007f Link to [Missions].
almikes@aol.com
parents: 564
diff changeset
    25
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    26
=== Special maps ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    27
In addition to tutorial missions predrawn maps (maps not created using the random map creator) may contain a single lua script file named `map.lua`. If it’s there, it will be used once the map is played. This way it’s possible to play maps alone or over the internet using custom goals. Mission maps can be found in singleplayer mode under the “training” button and in multiplayer mode, it is selectable as a map type.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    28
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    29
See also [PresetMaps] for more information about such maps.
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    30
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    31
=== How Lua scripts are used ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    32
Several parts of script files are executed multiple times. In general, the whole script file is read while loading the map. Declarations as well as function calls outside functions are executed at once. Later on the game will call special predefined function names at special occassions such as the creation of new game objects (called “gears”).
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    33
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    34
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    35
=== Important things to know ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    36
It is possible to play missions in multiplayer. However this requires all participating players to have the exact same version of the map files, including the `map.lua` script file. If this isn’t the case the game will probably desync and “kick” at least the one player using a different version of the map files. To avoid problems when running prepackaged maps, you should never modify any maps provided with the Hedgewars default package. Instead, create a copy of the existing map and modify this one. Feel free to share your work on the forums.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    37
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    38
Another thing to note is the current status of our scripting implementation. Similar to the whole game, this is still work in progress and we can’t guarantee that scripts working in this version will run in future revisions of the game as we might extend, change or rename parts of the scripting engine.
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    39
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    40
=== Global variables/constants ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    41
Global variables are used by the game to interact with the scripts by passing and retrieving their values. While some of the variables are never read by the engine some allow you to modify the engine’s behaviour, e.g. the theme to be used for the current map.
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    42
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    43
  	  	 
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    44
=== Functions called by the game: Event handlers ===
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    45
After successfully loading the Lua script the game will call the following functions on different occasions. To be used, they have to use the exact same name as defined below.
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    46
478
7b95addbe9fc Move “color” into new data types section.
almikes@aol.com
parents: 477
diff changeset
    47
== Data types ==
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    48
This section defines some commonly used non-primitive parameter types which are used in multiple functions. This section is a bit incomplete at the moment.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
    49
478
7b95addbe9fc Move “color” into new data types section.
almikes@aol.com
parents: 477
diff changeset
    50
=== Color ===
477
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    51
Some functions take a `color` parameter.
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    52
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
    53
Colors are stored in RGB or RGBA format and are specified as a three- or four-byte number, respecively.
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
    54
In 3-byte (RGB) colors, each byte represents a color component. The value 0 means no intensity and 255 is largest intensity of the component.
477
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    55
The first byte is for the red component, the second byte for the green component and the third byte for the blue component.
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
    56
Four-byte (RGBA) colors use the first 3 bytes for the color components (like for the 3-byte colors) and the fourth byte is used for opacity, where 255 means maximum opacity and 0 means fully transparent (also called the “alpha channel”).
477
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    57
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    58
Specifying the color number becomes much easier if you write it in hexadecimal notation.
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    59
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
    60
Examples for RGB (3-byte) colors:
477
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    61
<code language="lua">
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    62
c = 0x000000 -- black (R, G, B are all 0)
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    63
c = 0xFF0000 -- red
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    64
c = 0x00FF00 -- green
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    65
c = 0x0000FF -- blue
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    66
c = 0xFFFFFF -- white
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    67
c = 0x808080 -- gray (50%)</code>
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    68
885
40aae8355e3e LuaAPI: www.colorpicker.com
Wuzzy
parents: 881
diff changeset
    69
Hint: On [http://www.colorpicker.com/] you find a color-picking tool for getting RGB colors easily.
40aae8355e3e LuaAPI: www.colorpicker.com
Wuzzy
parents: 881
diff changeset
    70
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    71
491
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    72
== Globally available variables and constants ==
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    73
The following variables are made available by Hedgewars in Lua and can be used to quickly query a value. Lua scripts schould normally *not* write to these variables, only read from them.
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    74
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    75
=== General variables and constants ===
1632
4c982152eb2e LuaAPI: fix *
Wuzzy
parents: 1631
diff changeset
    76
Here are some unsorted variables or constants which are available in Lua. *Consider these variables to be read-only.*
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
    77
491
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    78
|| *Identifier* || *Description* ||
1654
5c7dfdedb5f8 LuaAPI: Move some globals
Wuzzy
parents: 1653
diff changeset
    79
|| `LOCALE` || Current locale identifier (e.g. `"de"` for German) ||
5c7dfdedb5f8 LuaAPI: Move some globals
Wuzzy
parents: 1653
diff changeset
    80
|| `INTERFACE` || Type of the game interface: `"desktop"` for desktop, `"touch"` for touchscreen ||
5c7dfdedb5f8 LuaAPI: Move some globals
Wuzzy
parents: 1653
diff changeset
    81
|| `MAX_HOG_HEALTH` || Maximum possible hedgehog health ||
5c7dfdedb5f8 LuaAPI: Move some globals
Wuzzy
parents: 1653
diff changeset
    82
|| `MAX_TURN_TIME` || Maximum possible turn time in milliseconds ||
1532
94030dc69d1e LuaAPI: Explain map variables that they are set when onGameStart is called
Wuzzy
parents: 1531
diff changeset
    83
|| `LAND_WIDTH` || The width of the landscape in pixels. Not available before `onGameStart` ||
94030dc69d1e LuaAPI: Explain map variables that they are set when onGameStart is called
Wuzzy
parents: 1531
diff changeset
    84
|| `LAND_HEIGHT` || The height of the landscape in pixels. Not available before `onGameStart` ||
94030dc69d1e LuaAPI: Explain map variables that they are set when onGameStart is called
Wuzzy
parents: 1531
diff changeset
    85
|| `LeftX` || X coordinate of the leftmost point of the landscape. Not available before `onGameStart` ||
94030dc69d1e LuaAPI: Explain map variables that they are set when onGameStart is called
Wuzzy
parents: 1531
diff changeset
    86
|| `RightX` || X coordinate of the rightmost point of the landscape. Not available before `onGameStart` ||
94030dc69d1e LuaAPI: Explain map variables that they are set when onGameStart is called
Wuzzy
parents: 1531
diff changeset
    87
|| `TopY` || Y coordinate of the topmost point of the landscape. Not available before `onGameStart` ||
1648
77f8cfe4ee8d LuaAPI: Add some globals
Wuzzy
parents: 1647
diff changeset
    88
|| `CursorX` || The X position of the cursor if the player is choosing a target. Otherwise, this equals `NO_CURSOR` ||
77f8cfe4ee8d LuaAPI: Add some globals
Wuzzy
parents: 1647
diff changeset
    89
|| `CursorY` || The Y position of the cursor if the player is choosing a target. Otherwise, this equals `NO_CURSOR` ||
491
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    90
|| `WaterLine` || The y position of the water, used to determine at which position stuff drowns. Use `SetWaterLine` to change. ||
1157
700fccda9e4d LuaAPI: Clarify globals
Wuzzy
parents: 1156
diff changeset
    91
|| `ClansCount` || Number of clans, including defeated ones (a clan is a group of teams with same color) ||
700fccda9e4d LuaAPI: Clarify globals
Wuzzy
parents: 1156
diff changeset
    92
|| `TeamsCount` || Number of teams, including defeated ones ||
1631
50432569b972 LuaAPI: Update TurnTimeLeft/ReadyTimeLeft
Wuzzy
parents: 1629
diff changeset
    93
|| `TurnTimeLeft` || Number of game ticks (milliseconds) left until the current turn ends. To set this value, use `SetTurnTimeLeft` ||
50432569b972 LuaAPI: Update TurnTimeLeft/ReadyTimeLeft
Wuzzy
parents: 1629
diff changeset
    94
|| `ReadyTimeLeft` || Remaining ready time in millseconds, 0 if turn in progress. To set this value, use `SetReadyTimeLeft` ||
491
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    95
|| `GameTime` || Number of total game ticks ||
1650
11fce1b6d39b LuaAPI: Simplify TotalRounds
Wuzzy
parents: 1649
diff changeset
    96
|| `TotalRounds` || Number of rounds that have passed. Equals `-1` if game has not started yet or hogs are still being placed. ||
491
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    97
|| `CurrentHedgehog` || The hedgehog gear that is currently in play ||
1155
90bf2e940925 LuaAPI: clarify ClansCount, TeamsCount
Wuzzy
parents: 1112
diff changeset
    98
|| `AmmoTypeMax` || Maximum ammo type ID (useful to iterate through all ammo types, starting by 0) ||
125
b0b7654c6de6 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 123
diff changeset
    99
491
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   100
=== !GameFlags ===
557
7a25067aa32c fix link to gameflag functions
sheepyluva@gmail.com
parents: 556
diff changeset
   101
The !GameFlags are used to store simple boolean settings of the game.
7a25067aa32c fix link to gameflag functions
sheepyluva@gmail.com
parents: 556
diff changeset
   102
You can read/modify them using the [LuaAPI#GameFlags_functions GameFlags-Functions].
102
86cf695636c6 Added gfResetHealth to Gameflags section along with a note.
RedGrinner@gmail.com
parents: 101
diff changeset
   103
491
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   104
|| *Identifier* || *Description (active state)* ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   105
|| `gfOneClanMode` || Used when only one clan is in the game. This game flag is primarily used for training missions. ||
1657
899707a349b3 LuaAPI: fix typo
Wuzzy
parents: 1656
diff changeset
   106
|| `gfMultiWeapon` || Shooting any weapon enters multi-shot mode with infinite shots. The remaining shots counter for weapons like shotgun is suppressed. Intended for target practice missions, not recommended for anything else. ||
1300
dff2be85c8d2 LuaAPI: add gfSwitchHog
Wuzzy
parents: 1299
diff changeset
   107
|| `gfSwitchHog` || Free hog switching at turn start ||
1629
1068da1c7ada LuaAPI: Specify game flag priority
Wuzzy
parents: 1593
diff changeset
   108
|| `gfDivideTeams` || Each clan will start in its own side of the terrain. No effect if `gfPlaceHog` is active. ||
626
c243eb309e6f Explain gfShoppaBorder
Wuzzy
parents: 625
diff changeset
   109
|| `gfBorder` || An indestructible border is active around the map. ||
491
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   110
|| `gfBottomBorder` || There is an indestructable border at the bottom of the map. ||
626
c243eb309e6f Explain gfShoppaBorder
Wuzzy
parents: 625
diff changeset
   111
|| `gfShoppaBorder` || The terrain edge will be replaced by a decorative black/yellow “danger stripe”. This has no gameplay effect. ||
491
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   112
|| `gfSolidLand` || The terrain is indestructible. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   113
|| `gfLowGravity` || The gravity is low. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   114
|| `gfLaserSight` || A laser sight is almost always active. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   115
|| `gfInvulnerable` || All hedgehogs are invulnerable. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   116
|| `gfVampiric` || All hedgehogs become vampires and get 80% of the damage they deal as health. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   117
|| `gfKarma` || Attackers share the damage they deal to enemies. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   118
|| `gfArtillery` || Hedgehogs can’t walk. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   119
|| `gfRandomOrder` || The game is played in random order. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   120
|| `gfPlaceHog` || Placement mode: At the beginning of the round, all hedgehogs are placed manually first. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   121
|| `gfKing` || King Mode: One hedgehog per team becomes their king, if the king dies, the team loses. ||
1629
1068da1c7ada LuaAPI: Specify game flag priority
Wuzzy
parents: 1593
diff changeset
   122
|| `gfSharedAmmo` || Teams in the same clan share their ammo. Takes precedence over `gfPerHogAmmo`.  ||
491
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   123
|| `gfDisableGirders` || No girders will be created in random maps ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   124
|| `gfDisableLandObjects` || No land objects will be created in random maps ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   125
|| `gfAISurvival` || Computer-controlled hedgehogs will be revived after they die. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   126
|| `gfInfAttack` || Attacks don’t end the turn. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   127
|| `gfResetWeps` || The weapons will be reset to the initial state each turn. ||
1629
1068da1c7ada LuaAPI: Specify game flag priority
Wuzzy
parents: 1593
diff changeset
   128
|| `gfPerHogAmmo` || Each hedgehog has its own weapon stash. No effect if `gfSharedAmmo` is active. ||
491
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   129
|| `gfDisableWind` || There is no wind. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   130
|| `gfMoreWind` || There is always strong wind. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   131
|| `gfTagTeam` || Tag Team: Teams in the same clan share their turn time. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   132
|| `gfResetHealth` || The health of all living hedgehogs is reset at the end of each turn. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   133
540
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   134
=== Land flags ===
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   135
The land flags denote several types of terrain. Like all flags, they can be combined at will.
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   136
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   137
|| *Identifier* || *Meaning* ||
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   138
|| `lfIce` || Slippery terrain, hogs will slide on it. ||
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   139
|| `lfBouncy` || Bouncy terrain, hogs and some other gears will bounce off when they collide with it. ||
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   140
|| `lfIndestructible` || Almost indestructible terrain, most weapons will not destroy it. ||
1228
460d8f3aaf32 LuaAPI: Rewrite SetGearCollisionMask
Wuzzy
parents: 1227
diff changeset
   141
|| `0` || Normal destroyable terrain. Note that this is the case when no other land flag is set. ||
540
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   142
491
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   143
=== More constants ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   144
More constants are at at [GearTypes Gear Types] , [AmmoTypes Ammo Types], [Sounds], [States], [Sprites], [VisualGearTypes Visual Gear Types].
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   145
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   146
== Event handlers ==
890
74b9c19e4b50 LuaAPI: fix typos
Wuzzy
parents: 885
diff changeset
   147
Lua scripts are supposed to _define_ these functions to do something. The functions are then _called_ by Hedgewars when a certain event has occoured.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   148
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   149
=== <tt>onGameInit()</tt> ===
860
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   150
This function is called before the game loads its resources. One can read and modify various game variables here. These variables will become globally available after `onGameInit` has been invoked, but changing them has only an effect in `onGameInit`.
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   151
Most variables are optional, but for missions, `Theme` must be set by the scripter if you want to use a random map, rather than an image map. All other variables do not need to be set by the scripter and have default values.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   152
860
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   153
List of game variables:
863
825d0dcd739f LuaAPI: fix typos
Wuzzy
parents: 862
diff changeset
   154
|| *Identifier* || *Default* || *Description* ||
860
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   155
|| `Theme` || _depends_ || The theme to be used. When `Map` is set, a default value is used. For missions which don't use an image map, `Theme` *must* be set explicitly ||
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   156
|| `Map` || `""` || The image map being played or `""` if no image map is used ||
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   157
|| `Seed` || `0` || Seed of the random number generator ||
1579
00bcd6b833a5 LuaAPI: Add LandDigest
Wuzzy
parents: 1578
diff changeset
   158
|| `LandDigest` || _N/A_ || Digest for the current map. Only meant for internal use by Hedgewars ||
860
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   159
|| `MapGen` || `mgRandom` || Type of map generator. One of `mgRandom`, `mgMaze`, `mgPerlin`, `mgDrawn`. ||
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   160
|| `TemplateFilter` || `0` || _unknown meaning_ ||
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   161
|| `TemplateNumber` || `0` || _unknown meaning_ ||
1683
e8df7f4501a6 LuaAPI: new MapFeatureSize default
Wuzzy
parents: 1679
diff changeset
   162
|| `MapFeatureSize` || `50` (`12` in 1.0.0) || Used by random maps to determine its “curvyness” or complexity. This value can be set by the user with the slider under the random map preview in the game setup screen. The user-set value ranges from 1 (leftmost position) to 25 (rightmost position). A good starting value is `12`. ||
1251
6afb77fb97bc LuaAPI: Discourage setting GameFlags directly
Wuzzy
parents: 1246
diff changeset
   163
|| `GameFlags` || `0` || All `GameFlags` combined as a bitmask. Setting `GameFlags` directly is discouraged, use the [LuaAPI#GameFlags_functions] instead ||
860
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   164
|| `Ready` || `5000` || Ready timer at the start of the turn (in milliseconds) ||
1679
3f5e880b0375 LuaAPI: clarify Delay
Wuzzy
parents: 1678
diff changeset
   165
|| `Delay` || `100` || Time the current hedgehog needs to be inactive before gear stuff gets updated in infinite attack mode, like applying hog damage and deaths. This is quite an obscure variable, only change it if you know what you're doing ||
860
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   166
|| `TurnTime` || `45000` || Turn time in milliseconds ||
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   167
|| `GetAwayTime` || `100` || Retreat time in percent ||
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   168
|| `CaseFreq` || `5` || Probability that a crate drops in a turn. 0: never, >0: probability = `1/CaseFreq` ||
1647
4185517621d5 LuaAPI: Add MaxCaseDrops
Wuzzy
parents: 1645
diff changeset
   169
|| `MaxCaseDrops` || `5` || Maximum number of crates that can be in the game before the random crate drops stop ||
860
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   170
|| `HealthCaseProb` || `35` || Chance that a crate drop is a health crate, in percent (other crates are ammo or utility crates) ||
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   171
|| `HealthCaseAmount` || `25` || Amount of health in a health crate ||
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   172
|| `DamagePercent` || `100` || Global damage in percent, affects damage and knockback ||
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   173
|| `RopePercent` || `100` || Rope length in percent ||
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   174
|| `MinesNum` || `4` || Number of mines being placed on a medium-sized map ||
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   175
|| `MinesTime` || `3000` || Time for a mine to explode from activated (in milliseconds), `-1000` for random ||
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   176
|| `MineDudPercent` || `0` || Chance of mine being a dud, in percent ||
1111
f6d0d5772a6c LuaAPI: Edited via web interface
Wuzzy
parents: 1075
diff changeset
   177
|| `AirMinesNum` || `0` || Number of air mines being placed on a medium-sized map ||
860
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   178
|| `Explosives` || `2` || Number of barrels being placed on a medium-sized map ||
1574
004caa91e6fe LuaAPI: Clarify SuddenDeathTurns (2)
Wuzzy
parents: 1573
diff changeset
   179
|| `SuddenDeathTurns` || `15` || Number of rounds until Sudden Death begins, _after the first round is over_. E.g. 0 = SD starts in 2nd round ||
862
d06141c36428 LuaAPI: Sudden Death disable
Wuzzy
parents: 861
diff changeset
   180
|| `WaterRise` || `47` || Height of water rise in pixels for each Sudden Death turn ||
861
ccbc115e68ad LuaAPI: fix broken onGameInit table
Wuzzy
parents: 860
diff changeset
   181
|| `HealthDecrease` || `5` || Amount of health decreased on each turn in Sudden Death ||
1715
5cac9aadcc27 LuaAPI: Update special escape characters for ShowMission
Wuzzy
parents: 1711
diff changeset
   182
|| `Goals` || `""` || Use this to add additional text to the goal text popup shown at the beginning and when using the quit or pause keys. The text is added to the default text which usually explains the game modifiers and does not replace it. The text supports the same special characters as in `ShowMission` ||
1111
f6d0d5772a6c LuaAPI: Edited via web interface
Wuzzy
parents: 1075
diff changeset
   183
|| `WorldEdge` || `weNone` || Type edges being used at the left and right sides of the terrain (see below). ||
860
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   184
|| `ScreenWidth` || _N/A_ || Width of the Hedgewars window or screen ||
890
74b9c19e4b50 LuaAPI: fix typos
Wuzzy
parents: 885
diff changeset
   185
|| `ScreenHeight` || _N/A_ || Height of the Hedgewars window or screen ||
860
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   186
862
d06141c36428 LuaAPI: Sudden Death disable
Wuzzy
parents: 861
diff changeset
   187
The proper way to disable Sudden Death is by setting both `WaterRise` and `HealthDecrease` to `0`.
d06141c36428 LuaAPI: Sudden Death disable
Wuzzy
parents: 861
diff changeset
   188
860
a7ddaecf54f3 LuaAPI: Put onGameInit variables into neat table
Wuzzy
parents: 859
diff changeset
   189
If you want to add teams or hogs manually, you have to do it here. If you want to draw your own map using `AddPoint` and `FlushPoints`, you have to do this within this function as well.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   190
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
   191
==== <tt>!WorldEdge</tt> ====
917
c05279ae1ac2 LuaAPI: Add WorldEdge
Wuzzy
parents: 916
diff changeset
   192
The value of `WorldEdge` can have the following values:
c05279ae1ac2 LuaAPI: Add WorldEdge
Wuzzy
parents: 916
diff changeset
   193
c05279ae1ac2 LuaAPI: Add WorldEdge
Wuzzy
parents: 916
diff changeset
   194
|| *Identifier* || *Meaning* ||
c05279ae1ac2 LuaAPI: Add WorldEdge
Wuzzy
parents: 916
diff changeset
   195
|| `weNone` || No world edges ||
c05279ae1ac2 LuaAPI: Add WorldEdge
Wuzzy
parents: 916
diff changeset
   196
|| `weBounce` || Bouncy world edges ||
c05279ae1ac2 LuaAPI: Add WorldEdge
Wuzzy
parents: 916
diff changeset
   197
|| `weWrap` || World wraps around at the edges ||
c05279ae1ac2 LuaAPI: Add WorldEdge
Wuzzy
parents: 916
diff changeset
   198
|| `weSea` || Ocean world edges ||
c05279ae1ac2 LuaAPI: Add WorldEdge
Wuzzy
parents: 916
diff changeset
   199
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   200
=== <tt>onGameStart()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   201
This function is called when the first round starts.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   202
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   203
Can be used to show the mission and for more setup, for example initial target spawning.
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   204
1532
94030dc69d1e LuaAPI: Explain map variables that they are set when onGameStart is called
Wuzzy
parents: 1531
diff changeset
   205
At this stage, the global variables `LeftX`, `RightX`, `TopY`, `LAND_WIDTH` and `LAND_HEIGHT` become available.
94030dc69d1e LuaAPI: Explain map variables that they are set when onGameStart is called
Wuzzy
parents: 1531
diff changeset
   206
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   207
=== <tt>onPreviewInit()</tt> ===
461
168508caf60d Add onPreviewInit
almikes@aol.com
parents: 421
diff changeset
   208
This function is called when the map preview in the frontend is initialized. This happens when the script is selected or you change a map generator parameter.
168508caf60d Add onPreviewInit
almikes@aol.com
parents: 421
diff changeset
   209
168508caf60d Add onPreviewInit
almikes@aol.com
parents: 421
diff changeset
   210
It is useful for scripts which create their own maps (see `AddPoint` and `FlushPoints`). If you create a map in this function, a preview will be generated from this map and is exposed to the frontend.
168508caf60d Add onPreviewInit
almikes@aol.com
parents: 421
diff changeset
   211
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   212
=== <tt>onParameters()</tt> ===
505
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   213
This function is called when the script parameters (as specified in the game scheme) become available. The script parameter string is stored in the global variable `ScriptParam`.
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   214
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   215
Please note that it is normally not safe to call many of the other functions inside this function, this function is called very early in the game, only use this to initialize variables and other internal stuff like that.
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   216
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   217
*Tip*: If you use the Params library  (`/Scripts/Params.lua`), you can make the task of dissecting the string into useful values a bit easier, but it’s not required. (The Params library is not documented yet, however).
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   218
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   219
*Tip*: If you use this callback, make sure to document the interpretation of the parameters so others know how to set the parameters properly.
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   220
64
a651a8ab85d5 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 63
diff changeset
   221
=== <tt>onGameTick()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   222
This function is called on every game tick, i.e. 1000 times a second. If you just need to check on something periodically, consider `onGameTick20`.
346
5f322c85c0e0 toss in onGameTick20 - this page needs more updating tho
kyberneticist@gmail.com
parents: 328
diff changeset
   223
5f322c85c0e0 toss in onGameTick20 - this page needs more updating tho
kyberneticist@gmail.com
parents: 328
diff changeset
   224
=== <tt>onGameTick20()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   225
This function is called every 20 game ticks, which equals 50 times a second. It reduces Lua overhead for simple monitoring that doesn’t need to happen every single tick.
64
a651a8ab85d5 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 63
diff changeset
   226
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   227
=== <tt>onNewTurn()</tt> ===
1112
f8b1be6befc7 LuaAPI: ReadyTimeLeft and AmmoTypeMax
Wuzzy
parents: 1111
diff changeset
   228
This function calls at the start of every turn. You can set `ReadyTimeLeft` here to change the ready time for this turn. (See also: `Ready`)
63
24004a9003ec Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 62
diff changeset
   229
1189
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   230
=== <tt>onEndTurn()</tt> (0.9.24) ===
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   231
This function calls at the end of every turn. The end of a turn is defined as the point of time after the current hedgehog lost control and all the important gears are either gone or have settled.
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   232
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   233
`CurrentHedgehog` holds the gear ID of the hedgehog whose turn just ended.
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   234
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   235
This function is called at one of the earliest possible moment after the end of a turn. After this callback, Hedgewars then performs all the other stuff between turns. This includes things like: Applying poison or Sudden Death damage, calculating total hog damage, rising the water in Sudden Death, dropping a crate, checking victory, giving control to the next hog.
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   236
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   237
Because this function is called *before* victories are checked, this is useful to set up your victory conditions here.
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   238
1269
347b7c9acf0a LuaAPI: Add SkipTurn and onSkipTurn
Wuzzy
parents: 1265
diff changeset
   239
=== <tt>onSkipTurn()</tt> (0.9.24) ===
347b7c9acf0a LuaAPI: Add SkipTurn and onSkipTurn
Wuzzy
parents: 1265
diff changeset
   240
This function calls when a hog skips its turn.
347b7c9acf0a LuaAPI: Add SkipTurn and onSkipTurn
Wuzzy
parents: 1265
diff changeset
   241
1693
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
   242
=== <tt>onGameResult(winningClan)</tt> (0.9.25) ===
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
   243
This function calls when the game ends with a winner or in a draw. If a clan wins, `winningClan` is the clan ID of the winning clan. If the game ends in a draw, `winningClan` is set to -1f.
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
   244
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   245
=== <tt>onSuddenDeath()</tt> ===
649
a33b0ddce148 onSuddenDeath
Wuzzy
parents: 648
diff changeset
   246
This function is called on the start of Sudden Death.
a33b0ddce148 onSuddenDeath
Wuzzy
parents: 648
diff changeset
   247
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   248
=== <tt>onGearAdd(gearUid)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   249
This function is called when a new gear is added. Useful in combination with `GetGearType(gearUid)`.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   250
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   251
=== <tt>onGearDelete(gearUid)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   252
This function is called when a new gear is deleted. Useful in combination with `GetGearType(gearUid)`.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   253
916
a01743eb08f1 LuaAPI: onVisualGearAdd, onVisualGearDelete, GetVisualGearType
Wuzzy
parents: 913
diff changeset
   254
=== <tt>onVisualGearAdd(vgUid)</tt> (0.9.23) ===
a01743eb08f1 LuaAPI: onVisualGearAdd, onVisualGearDelete, GetVisualGearType
Wuzzy
parents: 913
diff changeset
   255
This function is called when a new visual gear is added. Useful in combination with `GetVisualGearType(vgUid)`.
a01743eb08f1 LuaAPI: onVisualGearAdd, onVisualGearDelete, GetVisualGearType
Wuzzy
parents: 913
diff changeset
   256
a01743eb08f1 LuaAPI: onVisualGearAdd, onVisualGearDelete, GetVisualGearType
Wuzzy
parents: 913
diff changeset
   257
=== <tt>onVisualGearDelete(vgUid)</tt> (0.9.23) ===
a01743eb08f1 LuaAPI: onVisualGearAdd, onVisualGearDelete, GetVisualGearType
Wuzzy
parents: 913
diff changeset
   258
This function is called when a new visual gear is deleted. Useful in combination with `GetVisualGearType(vgUid)`.
a01743eb08f1 LuaAPI: onVisualGearAdd, onVisualGearDelete, GetVisualGearType
Wuzzy
parents: 913
diff changeset
   259
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   260
=== <tt>onGearDamage(gearUid, damage)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   261
This function is called when a gear is damaged.
55
ef26ff619aea Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 54
diff changeset
   262
ef26ff619aea Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 54
diff changeset
   263
Example:
ef26ff619aea Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 54
diff changeset
   264
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   265
<code language="lua">    function onGearDamage(gear, damage)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   266
        if (GetGearType(gear) == gtHedgehog) then
55
ef26ff619aea Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 54
diff changeset
   267
            -- adds a message saying, e.g. "Hoggy H took 25 points of damage"
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   268
            AddCaption(GetHogName(gear) .. ' took ' .. damage .. ' points of damage')
55
ef26ff619aea Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 54
diff changeset
   269
        end
ef26ff619aea Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 54
diff changeset
   270
    end</code>
1642
e8da1dd5c93c LuaAPI: add onGearResurrect param
Wuzzy
parents: 1641
diff changeset
   271
=== <tt>onGearResurrect(gearUid, spawnedVGear) </tt> ===
942
cca9e43e9d72 LuaAPI: Clarify description of onGearResurrect
Wuzzy
parents: 940
diff changeset
   272
This function is called when a gear is resurrected due to the hog effect `heResurrectable` being set (see `SetEffect`) and/or being an AI hog when the game modifier “AI Survival” (`gfAISurvival`) is active. It is *not* called when a hog was resurrected by the resurrector tool you can use in the game.
44
bf53e635a2ac Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 43
diff changeset
   273
1642
e8da1dd5c93c LuaAPI: add onGearResurrect param
Wuzzy
parents: 1641
diff changeset
   274
`spawnedVGear` is a visual gear handle of the “resurrection effect”. You can use this handle to modify or delete the resurrection animation.
e8da1dd5c93c LuaAPI: add onGearResurrect param
Wuzzy
parents: 1641
diff changeset
   275
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   276
=== <tt>onAmmoStoreInit()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   277
This function is called when the game is initialized to request the available ammo and ammo probabilities. Use `SetAmmo` here.
98
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   278
203
08cc35ba4d34 Edited wiki page LuaAPI through web user interface.
kyberneticist@gmail.com
parents: 202
diff changeset
   279
=== <tt>onNewAmmoStore(team/clan index, hog index)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   280
This function is identical to `onAmmoStoreInit` in function, but is called once per ammo store.  This allows different ammo sets for each clan, team or hedgehog depending on the mode.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   281
If `gfSharedAmmo` is set, the parameters passed are the clan index, and `-1`, and the function will be called once for each clan.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   282
If `gfPerHogAmmo` is set, the parameters passed are the team index and the hog index in that team, and the function will be called once for each hedgehog.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   283
If neither is set, the parameters passed are the team index and `-1`, and the function will be called once for each team.
202
47363108b6b6 Edited wiki page LuaAPI through web user interface.
kyberneticist@gmail.com
parents: 184
diff changeset
   284
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   285
These indexes can be used to look up details of the clan/team/hedgehog prior to gear creation. Routines to do these lookups will be created as needed.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   286
If you add this hook, the expectation is that you will call SetAmmo appropriately. Any values from `onAmmoStoreInit` are ignored.
202
47363108b6b6 Edited wiki page LuaAPI through web user interface.
kyberneticist@gmail.com
parents: 184
diff changeset
   287
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   288
=== <tt>onGearWaterSkip(gear)</tt> ===
502
7bd6701bb077 Add onGearWaterSkip
almikes@aol.com
parents: 491
diff changeset
   289
This function is called when the gear `gear` skips over water.
7bd6701bb077 Add onGearWaterSkip
almikes@aol.com
parents: 491
diff changeset
   290
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   291
=== <tt>onScreenResize()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   292
This function is called when you resize the screen. Useful place to put a redraw function for any `vgtHealthTags` you're using.
145
547ac6a1d14e Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 144
diff changeset
   293
98
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   294
=== <tt>onAttack()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   295
This function is called when your Hedgehog attacks.
98
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   296
107
kyberneticist
parents: 102
diff changeset
   297
=== <tt>onHJump()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   298
This function is called when you press the high jump key.
98
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   299
107
kyberneticist
parents: 102
diff changeset
   300
=== <tt>onLJump()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   301
This function is called when you press the long jump key.
98
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   302
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   303
=== <tt>onPrecise()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   304
This function is called when you press the precise key.
98
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   305
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   306
=== <tt>onLeft()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   307
This function is called when you press the left key.
98
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   308
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   309
=== <tt>onRight()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   310
This function is called when you press the right key.
98
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   311
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   312
=== <tt>onUp()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   313
This function is called when you press the up key.
98
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   314
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   315
=== <tt>onDown()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   316
This function is called when you press the down key.
98
54e178bb6986 Added basic (not entirely accurate) entries for the event handlers relating to actions taken by Hedgehogs / user input.
RedGrinner@gmail.com
parents: 95
diff changeset
   317
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   318
=== <tt>onAttackUp()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   319
This function is called when you release the attack key.
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   320
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   321
=== <tt>onDownUp()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   322
This function is called when you release the down key.
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   323
 
535
5cb76f048bd9 Update onHogAttack
almikes@aol.com
parents: 533
diff changeset
   324
=== <tt>onHogAttack(ammoType)</tt> ===
1572
ed20d7c7c667 LuaAPI: Add hint for onHogAttack to use onSkipTurn to detect a skip turn
Wuzzy
parents: 1570
diff changeset
   325
This function is called when you press the attack key. Beginning with 0.9.21, the parameter `ammoType` is provided. It contains the ammo type of the weapon used for the attack. 
ed20d7c7c667 LuaAPI: Add hint for onHogAttack to use onSkipTurn to detect a skip turn
Wuzzy
parents: 1570
diff changeset
   326
ed20d7c7c667 LuaAPI: Add hint for onHogAttack to use onSkipTurn to detect a skip turn
Wuzzy
parents: 1570
diff changeset
   327
Note: If you want to detect when a turn was skipped, use `onSkipTurn()`. There is no guarantee that `onHogAttack(amSkip)` is called in such an event.
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   328
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   329
=== <tt>onLeftUp()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   330
This function is called when you release the left key.
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   331
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   332
=== <tt>onPreciseUp()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   333
This function is called when you release the precise key.
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   334
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   335
=== <tt>onRightUp()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   336
This function is called when you release the right key.
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   337
622
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   338
=== <tt>onSetWeapon(msgParam)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   339
It is get called when a weapon is selected or switched.
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   340
622
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   341
`msgParam` tells you which ammo type was selected.
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   342
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   343
=== <tt>onSlot(msgParam)</tt> ===
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   344
This function is called when one of the weapon slot keys has been pressed.
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   345
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   346
`msgParam` tells the slot number minus 1 (i.e. `0` is for slot number 1, `1` is for slot number 2, etc.).
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   347
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   348
=== <tt>onSwitch()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   349
This function is called when a hog is switched to another.
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   350
622
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   351
=== <tt>onTaunt(msgParam)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   352
This function is called when the player uses an animated emote for example by using the chat commands `/wave`, `/juggle`, etc.
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   353
622
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   354
`msgParam` tells you which animation was played:
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   355
623
704e373ae691 Fix onTaunt table
Wuzzy
parents: 622
diff changeset
   356
|| *`msgParam`* || *Animation* || *Associated chat command* ||
704e373ae691 Fix onTaunt table
Wuzzy
parents: 622
diff changeset
   357
|| 0 || Rolling up || `/rollup` ||
704e373ae691 Fix onTaunt table
Wuzzy
parents: 622
diff changeset
   358
|| 1 || Sad face || `/sad` ||
704e373ae691 Fix onTaunt table
Wuzzy
parents: 622
diff changeset
   359
|| 2 || Waving hand || `/wave` ||
704e373ae691 Fix onTaunt table
Wuzzy
parents: 622
diff changeset
   360
|| 3 || Stupid winner's grin / “Awesome” face || `/hurrah` ||
704e373ae691 Fix onTaunt table
Wuzzy
parents: 622
diff changeset
   361
|| 4 || Peeing || `/ilovelotsoflemonade` ||
704e373ae691 Fix onTaunt table
Wuzzy
parents: 622
diff changeset
   362
|| 5 || Shrug || `/shrug` ||
704e373ae691 Fix onTaunt table
Wuzzy
parents: 622
diff changeset
   363
|| 6 || Juggling || `/juggle` ||
622
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   364
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   365
=== <tt>onTimer(msgParam)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   366
This function is called when one of the timer keys is pressed.
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   367
622
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   368
`msgParams` tells the set timer in seconds (i.e. `3` for the 3 seconds timer key).
d7c2a5db19a4 Add msgParam for onSlot, onTaunt, onTimer and onSetWeapon
Wuzzy
parents: 616
diff changeset
   369
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   370
=== <tt>onUpUp()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   371
This function is called when you release the up key.
178
dde460404412 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 177
diff changeset
   372
946
3ca13c637fd0 LuaAPI: Add onUsedAmmo
Wuzzy
parents: 942
diff changeset
   373
=== <tt>onUsedAmmo(ammoType)</tt> (0.9.23) ===
3ca13c637fd0 LuaAPI: Add onUsedAmmo
Wuzzy
parents: 942
diff changeset
   374
Called after a weapon has been used completely, with `ammoType` as the used ammo type.
3ca13c637fd0 LuaAPI: Add onUsedAmmo
Wuzzy
parents: 942
diff changeset
   375
947
155307e52864 LuaAPI: fix onUsedAmmo explanation
Wuzzy
parents: 946
diff changeset
   376
For example, it is called right after a bazooka is fired, when both shots of a shotgun have been fired, when extra time is used, or when all 4 shots of a portable portal device have been fired. It is also called when using a multi-shot ammo has been aborted by changing the weapon selection mid-way, because this still uses up the ammo.
946
3ca13c637fd0 LuaAPI: Add onUsedAmmo
Wuzzy
parents: 942
diff changeset
   377
1491
78f16ba1709e LuaAPI: Add warning for onUsedAmmo
Wuzzy
parents: 1443
diff changeset
   378
*Warning:* In 0.9.24 or earlier, you must not manipulate any ammo within this callback, e.g. by using `AddAmmo`. The ammo storage might become garbled otherwise.
78f16ba1709e LuaAPI: Add warning for onUsedAmmo
Wuzzy
parents: 1443
diff changeset
   379
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   380
=== <tt>onHogHide(gearUid)</tt> ===
689
e919bdf895f7 Add parameter for onHogHide and onHogRestore
Wuzzy
parents: 688
diff changeset
   381
This function is called when a hedgehog with the gear ID `gearUid` is hidden (removed from the map).
179
156e5fba2e2c Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 178
diff changeset
   382
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   383
=== <tt>onHogRestore(gearUid)</tt> ===
689
e919bdf895f7 Add parameter for onHogHide and onHogRestore
Wuzzy
parents: 688
diff changeset
   384
This function is called when a hedgehog with the specified gear ID `gearUid` is restored (unhidden).
173
ef246592a16e Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 172
diff changeset
   385
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   386
=== <tt>onSpritePlacement(spriteId, centerX, centerY)</tt> ===
411
dbb7937903a4 Add onSpritePlacement.
almikes@aol.com
parents: 410
diff changeset
   387
This function is called when a [Sprites Sprite] has been placed.
dbb7937903a4 Add onSpritePlacement.
almikes@aol.com
parents: 410
diff changeset
   388
dbb7937903a4 Add onSpritePlacement.
almikes@aol.com
parents: 410
diff changeset
   389
`spriteID` is the type of the sprite, you find a list at [Sprites Sprites]. `centerX` and `centerY` are the coordinates of the center of the sprite.
dbb7937903a4 Add onSpritePlacement.
almikes@aol.com
parents: 410
diff changeset
   390
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   391
=== <tt>onGirderPlacement(frameIdx, centerX, centerY)</tt> ===
402
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   392
This function is called when a girder has been placed.
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   393
940
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
   394
`frameIdx` is used for the length and orientation of the girder. The possible values are explained in `PlaceGirder`. `centerX` and `centerY` are the coordinates of the girder’s center.
402
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   395
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   396
=== <tt>onRubberPlacement(frameIdx, centerX, centerY)</tt> ===
402
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   397
This function is called when a rubber has been placed.
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   398
940
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
   399
`frameIdx` is used for the rubber orientation. The possible values are explained in `PlaceRubber`. `centerX` and `centerY` are the coordinates of the rubber’s center.
402
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   400
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
   401
=== <tt>onSpecialPoint(x, y, flags)</tt> ===
1223
868b783afc88 LuaAPI: Add onSpecialPoints. I hope it's more or less correct
Wuzzy
parents: 1221
diff changeset
   402
This is used while a special hand-drawn map is loaded. The engine is building these hand-drawn maps by reading points from the map definition. Optionally, some of these points may be “special”. These are not actually drawn on the map, but are used to store additional information for a position on the map. Special points currently need to be added manually in the map, the in-game editor is not able to add those yet (as of 0.9.23).
868b783afc88 LuaAPI: Add onSpecialPoints. I hope it's more or less correct
Wuzzy
parents: 1221
diff changeset
   403
Now, when such a special point at the coordinates `x` and `y` with an assigned value of `flags` is added, this function is called. `flags` is a whole number between `0` and `255` inclusive.
868b783afc88 LuaAPI: Add onSpecialPoints. I hope it's more or less correct
Wuzzy
parents: 1221
diff changeset
   404
868b783afc88 LuaAPI: Add onSpecialPoints. I hope it's more or less correct
Wuzzy
parents: 1221
diff changeset
   405
This function is used in Racer and !TechRacer to define waypoints.
868b783afc88 LuaAPI: Add onSpecialPoints. I hope it's more or less correct
Wuzzy
parents: 1221
diff changeset
   406
1692
cb3ddd1c394a LuaAPI: fix typo
Wuzzy
parents: 1683
diff changeset
   407
=== <tt>onAchievementsDeclaration()</tt> ===
1229
ff97ab480e0d LuaAPI: rewrite onAchievementsDeclaration
Wuzzy
parents: 1228
diff changeset
   408
This function is called after the stats for the stats screen (after the game) have been generated. You are supposed to call `DeclareAchievement` here.
1225
64b95a681971 LuaAPI: Add onAchievementsDeclaration and DeclareAchievement
Wuzzy
parents: 1224
diff changeset
   409
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   410
== Functions for creating gears ==
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   411
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   412
=== <tt>!AddGear(x, y, gearType, state, dx, dy, timer)</tt> ===
1519
1b32e9ff8adf LuaAPI: Define gears
Wuzzy
parents: 1518
diff changeset
   413
This creates a new gear at position x,y (measured from top left) of kind `gearType` (see [GearTypes Gear Types]).  Gears are dynamic objects or events in the world that affect the gameplay, including hedgehogs, projectiles, weapons, land objects, active utilities and a few more esoteric things.
1b32e9ff8adf LuaAPI: Define gears
Wuzzy
parents: 1518
diff changeset
   414
The initial velocities are `dx` and `dy`. All arguments are numbers. The function returns the `uid` of the gear created. Gears can have multple states at once: `state` is a bitmask, the flag variables can be found in [States].
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   415
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   416
Example:
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   417
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   418
<code language="lua">    local gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   419
    FindPlace(gear, true, 0, LAND_WIDTH)</code>
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   420
1165
7438c7dfeff6 LuaAPI: Add layer param to AddVisualGear
Wuzzy
parents: 1159
diff changeset
   421
=== <tt>!AddVisualGear(x, y, visualGearType, state, critical [, layer])</tt> ===
1519
1b32e9ff8adf LuaAPI: Define gears
Wuzzy
parents: 1518
diff changeset
   422
This attempts to create a new visual gear at position x,y (measured from top left) of kind `visualGearType` (see [VisualGearTypes Visual Gear Types]).  Visual gears are decorational objects which are usually used for purely decorational graphical effects.  They have no effect on gameplay.  Visual gears are not the same as gears, but they share some similarities.
1518
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   423
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   424
The function returns the `uid` of the visual gear created or `nil` if creation failed.  There is no guarantee that a visual gear will spawn.  *IMPORTANT: Do not rely on visual gears to spawn*. *Always* be prepared for this function to return `nil`.
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   425
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   426
Set `critical` to `true` if the visual gear is crucial to gameplay and must always be spawned when in-game.  Use `false` if it is just an effect or eye-candy, and its creation can be skipped when in fast-forward mode (such as when joining a room).
1511
3c0c822ecdb9 LuaAPI: Update AddvisualGear
Wuzzy
parents: 1510
diff changeset
   427
1518
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   428
You can set an optional `layer` to specify which visual gears get drawn on top.
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   429
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   430
Most visual gears delete themselves eventually.
1511
3c0c822ecdb9 LuaAPI: Update AddvisualGear
Wuzzy
parents: 1510
diff changeset
   431
1704
09694f0d4e90 LuaAPI: fix some asterisks
Wuzzy
parents: 1703
diff changeset
   432
*NOTE:* Visual gears *must* only be used for decorational/informational/rendering purposes. *Never* use the visual gear's internal state to manipulate anything gameplay-related. Visual gears are not safe for reliable storage and using them as that would lead to strange bugs.
1518
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   433
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   434
*NOTE:* Since 0.9.25, visual gears will never spawn when Hedgewars is run in a testing mode (i.e. not as the real game), so don't rely for visual gears to spawn even if they're critical.
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   435
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   436
Example:
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   437
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   438
<code language="lua">  -- adds an non-critical explosion at position 1000,1000. Returns 0 if it was not created.
1518
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   439
    local vgear = AddVisualGear(1000, 1000, vgtExplosion, 0, false) 
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   440
</code>
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   441
871
3222b4cfef8a LuaAPI: Additional parameter for SpawnHealthCrate, SpawnAmmoCrate, SpawnUtilityCrate
Wuzzy
parents: 869
diff changeset
   442
=== <tt>!SpawnHealthCrate(x, y, [, health])</tt> ===
1235
dae4580eca94 LuaAPI: Discourage negative health for health crates
Wuzzy
parents: 1232
diff changeset
   443
Spawns a health crate at the specified position. If `x` and `y` are set to 0, the crate will spawn on a random position (but always on land). Set `health` for the initial health contained in the health crate. If not set, the default health (`HealthCaseAmount`) is used. Do not use a negative value for `health`.
417
f4b7962d39cd Better documentation about the special coordinates x=0, y=0 for the crate spawn functions.
almikes@aol.com
parents: 416
diff changeset
   444
1189
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   445
=== <tt>!SpawnSupplyCrate(x, y, ammoType [, amount])</tt> (0.9.24) ===
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   446
Spawns an ammo or utility crate at the specified position with the given ammo type and an optional amount (default: 1). The crate type is chosen automatically based on the ammo type.
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   447
Otherwise, this function behaves like `SpawnAmmoCrate`.
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   448
871
3222b4cfef8a LuaAPI: Additional parameter for SpawnHealthCrate, SpawnAmmoCrate, SpawnUtilityCrate
Wuzzy
parents: 869
diff changeset
   449
=== <tt>!SpawnAmmoCrate(x, y, ammoType [, amount])</tt> ===
1189
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   450
Spawns an ammo crate at the specified position with content of `ammoType` (see [AmmoTypes Ammo Types]). Any `ammoType` is permitted, an ammo crate is spawned even if the ammo is normally defined as an utility.
1648
77f8cfe4ee8d LuaAPI: Add some globals
Wuzzy
parents: 1647
diff changeset
   451
If `ammoType` is set to `amNothing`, a random weapon (out of the available weapons from the weapon scheme) will be selected. If `x` and `y` are set to 0, the crate will spawn on a random position (but always on land). The `amount` parameter specifies the amount of ammo contained in the crate. If `amount` is `nil` or `0`, the value set by `SetAmmo` is used, or if `SetAmmo` has not been used, it falls back to the weapon scheme's value. If `amount` is equal to or greater than `AMMO_INFINITE`, the amount is infinite.
1031
637ad254daf9 LuaAPI: Explain the initial ammo setting in missions
Wuzzy
parents: 1030
diff changeset
   452
637ad254daf9 LuaAPI: Explain the initial ammo setting in missions
Wuzzy
parents: 1030
diff changeset
   453
Note that in Lua missions, the default number of ammo in crates is 0, so it has to be set to at least 1 with `SetAmmo` first, see the example:
417
f4b7962d39cd Better documentation about the special coordinates x=0, y=0 for the crate spawn functions.
almikes@aol.com
parents: 416
diff changeset
   454
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   455
Example:
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   456
1033
ea42a17739d0 LuaAPI: fix spawnammocrate mistakes
Wuzzy
parents: 1032
diff changeset
   457
<code language="lua">    SetAmmo(amGrenade, 0, 0, 0, 1) -- grenade ammo crates now contain 1 grenade each
ea42a17739d0 LuaAPI: fix spawnammocrate mistakes
Wuzzy
parents: 1032
diff changeset
   458
    SpawnAmmoCrate(0, 0, amGrenade) -- spawn grenade ammo crate at random position</code>
417
f4b7962d39cd Better documentation about the special coordinates x=0, y=0 for the crate spawn functions.
almikes@aol.com
parents: 416
diff changeset
   459
871
3222b4cfef8a LuaAPI: Additional parameter for SpawnHealthCrate, SpawnAmmoCrate, SpawnUtilityCrate
Wuzzy
parents: 869
diff changeset
   460
=== <tt>!SpawnUtilityCrate(x, y, ammoType [, amount])</tt> ===
881
ab6bd4812ca4 LuaAPI: special amNothing for SpawnAmmoCrate / SpawnUtilityCrate
Wuzzy
parents: 871
diff changeset
   461
Spawns an utility crate with some ammo at the specified position. The function behaves almost like `SpawnAmmoCrate`, the differences are 1) the crate looks different and 2) if `ammoType` is set to `amNothing`, a random utility out of the set of available utilities from the weapon scheme is chosen as content.
417
f4b7962d39cd Better documentation about the special coordinates x=0, y=0 for the crate spawn functions.
almikes@aol.com
parents: 416
diff changeset
   462
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   463
Example:
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   464
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   465
<code language="lua">    SetAmmo(amLaserSight, 0, 0, 0, 1)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   466
    SpawnUtilityCrate(0, 0, amLaserSight)</code>
400
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   467
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   468
=== <tt>!SpawnFakeAmmoCrate(x, y, explode, poison) </tt> ===
417
f4b7962d39cd Better documentation about the special coordinates x=0, y=0 for the crate spawn functions.
almikes@aol.com
parents: 416
diff changeset
   469
Spawns a crate at the specified coordinates which looks exactly like a real ammo crate but contains not any ammo. It can be use useful for scripted events or to create a trap. If `x` and `y` are set to 0, the crate will spawn on a random position (but always on land).
400
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   470
`explode` and `poison` are booleans.
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   471
If `explode` is `true`, the crate will explode when collected.
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   472
If `poison` is `true`, the collector will be poisoned.
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   473
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   474
Example:
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   475
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   476
<code language="lua">SpawnFakeAmmoCrate(500, 432, false, false) -- Spawns a fake ammo crate at the coordinates (500, 434) without explosion and poison.
400
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   477
</code>
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   478
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   479
=== <tt>!SpawnFakeHealthCrate(x, y, explode, poison) </tt> ===
1241
50cb37fde767 LuaAPI: Simplify SpawnFakeHealthCrate and SpawnFakeUtilityCrate
Wuzzy
parents: 1240
diff changeset
   480
Same as `SpawnFakeAmmoCrate`, except the crate will look like a health crate.
400
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   481
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   482
=== <tt>!SpawnFakeUtilityCrate(x, y, explode, poison) </tt> ===
1241
50cb37fde767 LuaAPI: Simplify SpawnFakeHealthCrate and SpawnFakeUtilityCrate
Wuzzy
parents: 1240
diff changeset
   483
Same as `SpawnFakeAmmoCrate`, except the crate will look like an utility crate.
400
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   484
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   485
=== <tt>!AddHog(hogname, botlevel, health, hat)</tt> ===
1578
80a793600049 LuaAPI: AddHog: Paragraph
Wuzzy
parents: 1577
diff changeset
   486
Adds a new hedgehog for current team (last created one with the `AddTeam` function), with a bot level, an initial health and a hat.
80a793600049 LuaAPI: AddHog: Paragraph
Wuzzy
parents: 1577
diff changeset
   487
1577
f1af9c28ce70 LuaAPI: Mention that you are not allowed to mix computer and human hogs in the same team
Wuzzy
parents: 1574
diff changeset
   488
`botlevel` ranges from `0` to `5`, where `0` denotes a human player and `1` to `5` denote the skill level of a bot, where `1` is strongest and `5` is the weakest. Note that this is the reverse order of how the bot level is displayed in the game. Note that mixing human-controlled and computer-controlled hedgehogs in the same team is not permitted, but it is permitted to use different computer difficulty levels in the same team.
413
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
   489
1694
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   490
Returns the gear ID.
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   491
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   492
*Warning*: This only works in singleplayer mode (e.g. missions). Also, Hedgewars only supports up to 64 hedgehogs in a game.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   493
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   494
Example:
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   495
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   496
<code language="lua">    local player = AddHog("HH 1", 0, 100, "NoHat") -- botlevel 0 means human player
1694
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   497
    SetGearPosition(player, 1500, 1000)
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   498
    -- hint: If you don't call `SetGearPosition`, the hog spawns randomly</code>
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   499
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   500
=== <tt>!AddMissionHog(health)</tt> (0.9.25) ===
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   501
Add a hedgehog for the current team, using the player-chosen team identity when playing in singleplayer missions. The “current team” is the last team that was added with `AddMissionTeam` or `AddTeam`.
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   502
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   503
The name and hat match the player's team definition. The hog is also always player-controlled.
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   504
1697
699a39df73c5 LuaAPI: Small tweaks
Wuzzy
parents: 1696
diff changeset
   505
Examples:
1694
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   506
<code language="lua">-- Add player team with 3 hogs
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   507
AddMissionTeam(-1)
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   508
AddMissionHog(100)
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   509
AddMissionHog(100)
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   510
AddMissionHog(100)</code>
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   511
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   512
<code language="lua">-- You can also mix mission hogs with “hardcoded” hogs.
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   513
-- This adds a player team with 2 hogs taken from the player team and 1 hog with a hardcoded name, botlevel and hat.
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   514
AddMissionTeam(-2)
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   515
AddMissionHog(100)
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   516
AddMissionHog(100)
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   517
AddHog("My Hardcoded Hog", 0, 100, "NoHat")
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   518
</code>
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
   519
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   520
== Functions to get gear properties ==
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   521
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   522
=== <tt>!GetGearType(gearUid)</tt> ===
1513
18582093d894 LuaAPI: Update GetVisualGearType and GetGearType
Wuzzy
parents: 1512
diff changeset
   523
This function returns the [GearTypes gear type] for the specified gear, if it exists.  If it doesn't exist, `nil` is returned.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   524
916
a01743eb08f1 LuaAPI: onVisualGearAdd, onVisualGearDelete, GetVisualGearType
Wuzzy
parents: 913
diff changeset
   525
=== <tt>!GetVisualGearType(vgUid)</tt> (0.9.23) ===
1513
18582093d894 LuaAPI: Update GetVisualGearType and GetGearType
Wuzzy
parents: 1512
diff changeset
   526
This function returns the [VisualGearTypes visual gear type] for the specified visual gear, if it exists.  If it doesn't exist, `nil` is returned.
916
a01743eb08f1 LuaAPI: onVisualGearAdd, onVisualGearDelete, GetVisualGearType
Wuzzy
parents: 913
diff changeset
   527
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   528
=== <tt>!GetGearPosition(gearUid)</tt> ===
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   529
Returns x,y coordinates for the specified gear. Not to be confused with `GetGearPos`.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   530
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
   531
=== <tt>GetGearCollisionMask(gearUid)</tt> ===
1244
fb89844d7b78 LuaAPI: Move GetGearCollisionMask
Wuzzy
parents: 1243
diff changeset
   532
Returns the current collision mask of the given gear. See `SetGearCollisionMask` for an explanation of the mask.
fb89844d7b78 LuaAPI: Move GetGearCollisionMask
Wuzzy
parents: 1243
diff changeset
   533
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   534
=== <tt>!GetGearRadius(gearUid)</tt> ===
1409
755e96dd1ff1 LuaAPI: fix link
Wuzzy
parents: 1398
diff changeset
   535
Returns the `Radius` value for the specified gear. For most [GearTypes gear types] for “projectile” gears (like `gtShell` or `gtGrenade`), the radius refers to the gear's collision radius. This is an invisible circle around the center of the gear which is used for the collision checks. For a few gear types, its radius means something different, see [GearTypes] for a full list.
892
05bb5a116783 LuaAPI: proper description of GetGearRadius
Wuzzy
parents: 891
diff changeset
   536
05bb5a116783 LuaAPI: proper description of GetGearRadius
Wuzzy
parents: 891
diff changeset
   537
To set the `Radius` value, use `SetGearValues`.
148
f343b50d5619 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 147
diff changeset
   538
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   539
=== <tt>!GetGearVelocity(gearUid)</tt> ===
555
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   540
Returns a tuple of dx,dy values for the specified gear.
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   541
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   542
=== <tt>!GetFlightTime(gearUid)</tt> ===
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   543
Returns the `FlightTime` of the specified gear. The `FlightTime` is a gear varialbe used to store a general time interval. The precise meaning of the `FlightTime` depends on the gear type.
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   544
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   545
For example: The `FlightTime` of a hedgehog (`gtHedgehog`) is the time since they last have stood on solid ground. For most projectile gear types (i.e. `gtShell`), it stores the time after it has been launched.
71
2dcbebb06088 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 70
diff changeset
   546
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   547
=== <tt>!GetGearElasticity(gearUid) </tt> ===
611
a1d30b3b866c Elasticity and friction
Wuzzy
parents: 610
diff changeset
   548
Returns the elasticity of the specified gear. The elasticity normally determines how strong the gear will bounce after collisions, where higher elasticity is for stronger bounces.
a1d30b3b866c Elasticity and friction
Wuzzy
parents: 610
diff changeset
   549
1514
f9f99f1cf286 LuaAPI: non-zero number: GetGearElasticity
Wuzzy
parents: 1513
diff changeset
   550
This is also useful for determining if a hog is on a rope or not. If a hog is attached to a rope, or is busy firing one, the elasticity of the rope will be a non-zero number.
611
a1d30b3b866c Elasticity and friction
Wuzzy
parents: 610
diff changeset
   551
a1d30b3b866c Elasticity and friction
Wuzzy
parents: 610
diff changeset
   552
=== <tt>!GetGearFriction(gearUid) </tt> ===
a1d30b3b866c Elasticity and friction
Wuzzy
parents: 610
diff changeset
   553
Returns the friction of the specified gear. The friction normally determines how well the gear will slide on terrain. Higher values are for increased sliding properties.
74
6130cad02b02 Added GetGearElasticity
RedGrinner
parents: 73
diff changeset
   554
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   555
=== <tt>!GetHogClan(gearUid)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   556
Returns the clan ID of the specified hedgehog gear.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   557
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
   558
=== <tt>!GetHogTeamName(gearUid)</tt> ===
1039
e312e2616b75 LuaAPI: GetHogTeamName: Allow gtGrave
Wuzzy
parents: 1038
diff changeset
   559
Returns the name of the specified gear’s team. `gearUid` can be a hedgehog or a grave.
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
   560
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   561
=== <tt>!GetHogName(gearUid)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   562
Returns the name of the specified hedgehog gear.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   563
1498
17a55d9cc7b9 LuaAPI: GetVampirism, GetLaserSight, IsHogHidden
Wuzzy
parents: 1491
diff changeset
   564
=== <tt>!IsHogHidden(gearUid)</tt> (0.9.25) ===
1499
798c1cf9de65 LuaAPI: fix hidden typo
Wuzzy
parents: 1498
diff changeset
   565
Returns true if hedgehog gear is hidden (e.g. via `HideHog` or the !TimeBox), false if it isn't, nil if that hedgehog never existed.
1498
17a55d9cc7b9 LuaAPI: GetVampirism, GetLaserSight, IsHogHidden
Wuzzy
parents: 1491
diff changeset
   566
140
04d82b673bc4 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 139
diff changeset
   567
=== <tt>!GetEffect(gearUid, effect)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   568
Returns the state of given effect for the given hedgehog gear.
140
04d82b673bc4 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 139
diff changeset
   569
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   570
See `SetEffect` for further details.
373
0f9322acd00a update GetEffect/SetEffect info
sheepyluva@gmail.com
parents: 369
diff changeset
   571
133
b737ccb5b49a Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 132
diff changeset
   572
=== <tt>!GetHogHat(gearUid)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   573
Returns the hat of the specified hedgehog gear.
133
b737ccb5b49a Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 132
diff changeset
   574
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   575
=== <tt>!GetHogFlag(gearUid)</tt> ===
610
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   576
Returns the name of the flag of the team of the specified hedgehog gear.
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   577
932
86ddcaa6813a LuaAPI: GetHogFort
Wuzzy
parents: 926
diff changeset
   578
=== <tt>!GetHogFort(gearUid)</tt> (0.9.23) ===
86ddcaa6813a LuaAPI: GetHogFort
Wuzzy
parents: 926
diff changeset
   579
Returns the name of the fort of the team of the specified hedgehog gear.
86ddcaa6813a LuaAPI: GetHogFort
Wuzzy
parents: 926
diff changeset
   580
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   581
=== <tt>!GetHogGrave(gearUid)</tt> ===
610
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   582
Returns the name of the grave of the team of the specified hedgehog gear.
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   583
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   584
=== <tt>!GetHogVoicepack(gearUid)</tt> ===
610
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   585
Returns the name of the voicepack of the team of the specified hedgehog gear.
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   586
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   587
=== <tt>!GetAmmoCount(gearUid, ammoType)</tt> ===
1658
65f6dd2bf801 LuaAPI: Add AMMO_INFINITE
Wuzzy
parents: 1657
diff changeset
   588
Returns the ammo count of the specified ammo type for the specified hedgehog gear. If infinite, returns `AMMO_INFINITE`.
133
b737ccb5b49a Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 132
diff changeset
   589
1410
6d356877f1d2 LuaAPI: add GetAmmoTimer
Wuzzy
parents: 1409
diff changeset
   590
=== <tt>!GetAmmoTimer(gearUid, ammoType)</tt> (0.9.25) ===
6d356877f1d2 LuaAPI: add GetAmmoTimer
Wuzzy
parents: 1409
diff changeset
   591
Returns the currently configured ammo timer (in milliseconds) for the given hedgehog gear and specified ammo type. This is the timer which is set by the player by using the timer keys (1-5). For ammo types for which the timer cannot be changed, `nil` is returned.
6d356877f1d2 LuaAPI: add GetAmmoTimer
Wuzzy
parents: 1409
diff changeset
   592
6d356877f1d2 LuaAPI: add GetAmmoTimer
Wuzzy
parents: 1409
diff changeset
   593
Example:
6d356877f1d2 LuaAPI: add GetAmmoTimer
Wuzzy
parents: 1409
diff changeset
   594
<code lang="lua">GetAmmoTimer(CurrentHedgehog, amGrenade)
6d356877f1d2 LuaAPI: add GetAmmoTimer
Wuzzy
parents: 1409
diff changeset
   595
-- May return 1000, 2000, 3000, 4000 or 5000</code>
6d356877f1d2 LuaAPI: add GetAmmoTimer
Wuzzy
parents: 1409
diff changeset
   596
913
33b5b51f54d6 LuaAPI: Add IsHogLocal
Wuzzy
parents: 912
diff changeset
   597
=== <tt>!IsHogLocal(gearUid)</tt> (0.9.23) ===
1190
0d33477246bc LuaAPI: update IsHogLocal
Wuzzy
parents: 1189
diff changeset
   598
Returns `true` if the specified hedgehog gear is controlled by a human player on the computer on which Hedgewars runs on (i.e. not over a computer over the network). Also returns `true` if the hog is a member of any of the local clans. Returns `false` otherwise. Returns `nil` if `gearUid` is invalid.
0d33477246bc LuaAPI: update IsHogLocal
Wuzzy
parents: 1189
diff changeset
   599
0d33477246bc LuaAPI: update IsHogLocal
Wuzzy
parents: 1189
diff changeset
   600
This is perfect to hide certain captions like weapon messages from enemy eyes.
913
33b5b51f54d6 LuaAPI: Add IsHogLocal
Wuzzy
parents: 912
diff changeset
   601
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   602
=== <tt>!GetGearTarget(gearUid, x, y) </tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   603
Returns the x and y coordinate of target-based weapons/utilities. 
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   604
<b>Note:</b>: This can’t be used in `onGearAdd()` but must be called after gear creation. 
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   605
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   606
=== <tt>GetX(gearUid)</tt> ===
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   607
Returns x coordinate of the gear.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   608
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   609
=== <tt>GetY(gearUid)</tt> ===
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   610
Returns y coordinate of the gear.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   611
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   612
=== <tt>!GetState(gearUid)</tt> ===
415
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   613
Returns the state of the gear. The gear state is a bitmask which is built out of the variables as shown in [States].
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   614
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   615
This function is usually used in combination with `band` to extract the truth value of a single flag. It is also used together with `SetState` and `bor` in order to activate a single flag.
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   616
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   617
Examples:
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   618
<code language="lua">
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   619
local state = GetState(gear)
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   620
--[[ Stores the full raw bitmask of gear in state. Usually
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   621
useless on its own. ]]
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   622
</code>
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   623
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   624
<code language="lua">
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   625
isDrowning = band(GetState(CurrentHedgehog),gstDrowning) ~= 0
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   626
--[[ GetState(CurrentHedgehog) returns the state bitmask of
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   627
CurrentHedgehog, gstDrowning is a bitmask where only the
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   628
“drowning” bit is set. band does a bitwise AND on both, if
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   629
it returns a non-zero value, the hedgehog is drowning.]]
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   630
</code>
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   631
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   632
<code language="lua">
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   633
SetState(CurrentHedgehog, bor(GetState(CurrentHedgehog), gstInvisible))
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   634
--[[ first the state bitmask of CurrentHedgehog is bitwise ORed with
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   635
the gstInvisible flag, thus making the bit responsible for
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   636
invisiblity to become 1. Then the new bitmask is applied to
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   637
CurrentHedgehog, thus making it invisible.]]
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   638
</code>
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   639
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   640
114
e311af715b57 Edited wiki page LuaAPI through web user interface.
henrik.rostedt@gmail.com
parents: 107
diff changeset
   641
=== <tt>!GetGearMessage(gearUid)</tt> ===
625
e463f9d97820 Some copy-editing
Wuzzy
parents: 624
diff changeset
   642
Returns the message of the gear. This is a bitmask built out of flags seen in [GearMessages].
419
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   643
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   644
=== <tt>!GetTag(gearUid)</tt> ===
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   645
Returns the tag of the specified gear (by `gearUid`). 
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   646
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   647
The `Tag` of a gear is just another arbitrary variable to hold the gear's state. The meaning of a tag depends on the gear type. For example, for `gtBall` gears, it specifies the ball color, for `gtAirAttack` gears (airplane) it specifies the direction of the plane, etc. See [GearTypes] for a full list. The returned value will be an integer.
419
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   648
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   649
Note that the word “tag” here does _not_ refer to the name and health tags you see above hedgehogs, this is something different. 
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   650
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   651
<code language="lua">
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   652
-- This adds a ball (the one from the ballgun) at (123, 456):
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   653
ball = AddGear(123, 456, gtBall, 0, 0, 0, 0)
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   654
-- The tag of a ball defines its color. It will automatically chosen at random when created.
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   655
colorTag = GetTag(ball)
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   656
-- Now colorTag stores the tag of ball (in this case a number denoting its color)
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   657
</code>
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   658
421
d584704354ad Add link to GearTypes for SetTag and GetTag.
almikes@aol.com
parents: 419
diff changeset
   659
The meaning of tags are described in [GearTypes].
419
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   660
209
26805ae2a319 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 203
diff changeset
   661
=== <tt>!GetFollowGear()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   662
Returns the uid of the gear that is currently being followed.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   663
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   664
=== <tt>!GetTimer(gearUid)</tt> ===
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   665
Returns the timer of the gear. This is for example the time it takes for watermelon, mine, etc. to explode. This is also the time used to specify the blowtorch or RC plane time. See [GearTypes] for a full list.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   666
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   667
=== <tt>!GetHealth(gearUid)</tt> ===
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   668
Returns the health of the gear. Depending on the gear type, the gear's “health” can also refer to other things, see [GearTypes] for a full list.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   669
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   670
=== <tt>!GetHogLevel(gearUid)</tt> ===
1243
770aa6d54ae2 LuaAPI: clarify HogLevel stuff
Wuzzy
parents: 1241
diff changeset
   671
Returns the bot level ranging from `0` to `5`. `1` is the strongest bot level and `5` is the weakest one (this is the reverse of what players see). `0` is for human player.
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   672
503
87a36ae53518 Add GetGearPos
almikes@aol.com
parents: 502
diff changeset
   673
=== <tt>!GetGearPos(gearUid)</tt> ===
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   674
Get the `Pos` value of the specified gear. `Pos` is just another arbitrary value to hold the state of the gear, such as `Tag` and `Health`, the meaning depends on the gear type. See [GearTypes] for the conrete meaning of a gear's `Pos` value. 
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   675
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   676
*Important*: Pos is *not* related to the gear's position, use `GetGearPosition` for that.
503
87a36ae53518 Add GetGearPos
almikes@aol.com
parents: 502
diff changeset
   677
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   678
=== <tt>!GetGearValues(gearUid)</tt> ===
616
51fafc27af9c Fix GetGearValues return value
Wuzzy
parents: 615
diff changeset
   679
This returns a bunch of values associated with the gear, their meaning is often depending on the gear type and many values might be unused for certain gear types.
612
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   680
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   681
This is returned (all variables are integers):
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   682
688
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
   683
`Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, nImpactSounds, Tint, Damage, Boom`
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
   684
612
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   685
A rough description of some of the parameters:
615
632e4dcc8b52 Fix bullet point lists
Wuzzy
parents: 614
diff changeset
   686
632e4dcc8b52 Fix bullet point lists
Wuzzy
parents: 614
diff changeset
   687
 * `Radius`: Effect or collision radius, most of the time
625
e463f9d97820 Some copy-editing
Wuzzy
parents: 624
diff changeset
   688
 * `ImpactSound`: Sound it makes on a collision (see [Sounds])
615
632e4dcc8b52 Fix bullet point lists
Wuzzy
parents: 614
diff changeset
   689
 * `Tint`: Used by some gear types to determine its colorization. The color is in RGBA format.
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   690
 * `Boom`: Used by most gears to determine the damage dealt.
612
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   691
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   692
Example:
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   693
<code language="lua">
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   694
-- Get all values in a single line of code:
1703
c7d3e5459a58 LuaAPI: Add Scale argument for *VisualGearValues
Wuzzy
parents: 1702
diff changeset
   695
local Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, nImpactSounds, Tint, Damage, Boom, Scale = GetGearValues(myGear)
612
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   696
</code>
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   697
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   698
=== <tt>!GetVisualGearValues(vgUid)</tt> ===
1518
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   699
This returns the typically set visual gear values for the specified visual gear `vgUid`, useful if manipulating things like smoke, bubbles or circles. On success, it returns the following values:
614
64c94ad363c8 Prettify GetVisualGearValues documentation
Wuzzy
parents: 613
diff changeset
   700
1703
c7d3e5459a58 LuaAPI: Add Scale argument for *VisualGearValues
Wuzzy
parents: 1702
diff changeset
   701
`X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint, Scale`
614
64c94ad363c8 Prettify GetVisualGearValues documentation
Wuzzy
parents: 613
diff changeset
   702
1703
c7d3e5459a58 LuaAPI: Add Scale argument for *VisualGearValues
Wuzzy
parents: 1702
diff changeset
   703
The meaning of these values is the same as in `SetVisualGearValues`.
614
64c94ad363c8 Prettify GetVisualGearValues documentation
Wuzzy
parents: 613
diff changeset
   704
1521
c48e03ba077c LuaAPI: GetVisualGearValues warning
Wuzzy
parents: 1520
diff changeset
   705
If the visual gear does not exist, `nil` is returned. Always check the result for `nil` before you plug in the values anywhere.
1520
b52c6f8689bc LuaAPI: GetVisualGearValues return value
Wuzzy
parents: 1519
diff changeset
   706
b52c6f8689bc LuaAPI: GetVisualGearValues return value
Wuzzy
parents: 1519
diff changeset
   707
Most visual gears require little to no modification of parameters.
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   708
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   709
Example:
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   710
1522
4f9e1a0d56d9 LuaAPI: better GetVisualGearValuesExample
Wuzzy
parents: 1521
diff changeset
   711
<code language="lua">-- Return visual gear values
1703
c7d3e5459a58 LuaAPI: Add Scale argument for *VisualGearValues
Wuzzy
parents: 1702
diff changeset
   712
local X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint, Scale = GetVisualGearValues(vgUid)
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   713
</code>
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   714
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   715
== Functions to modify gears ==
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   716
243
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   717
=== <tt>!HideHog(gearUid)</tt> ===
1004
94d046b03855 LuaAPI: Update HideHog
Wuzzy
parents: 1003
diff changeset
   718
Removes a hedgehog from the map. The hidden hedgehog can be restored with `RestoreHog(gearUid)`. Since 0.9.23, returns `true` on success and `false` on failure (if gear does not exist / hog is already hidden).
243
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   719
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   720
Example: 
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   721
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   722
<code language="lua">    gear = AddGear(...)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   723
     HideHog(gear) -- Hide the newly created gear.</code>
243
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   724
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   725
=== <tt>!RestoreHog(gearUid)</tt> ===
1513
18582093d894 LuaAPI: Update GetVisualGearType and GetGearType
Wuzzy
parents: 1512
diff changeset
   726
Restores a previously hidden hedgehog.  Nothing happens if the hedgehog does not exist or is not hidden.
243
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   727
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   728
Example: 
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   729
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   730
<code language="lua">    gear = AddGear(...)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   731
     HideHog(gear) -- Hide the newly created gear.
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   732
     RestoreHog(gear) -- Restore the newly hidden gear.</code>
243
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   733
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   734
=== <tt>!DeleteGear(gearUid)</tt> ===
1513
18582093d894 LuaAPI: Update GetVisualGearType and GetGearType
Wuzzy
parents: 1512
diff changeset
   735
Deletes a gear.  If the specified gear did not exist, nothing happens.
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   736
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   737
Example:
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   738
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   739
<code language="lua">    gear = AddGear(...)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   740
    DeleteGear(gear) -- Delete the newly created gear.</code>
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   741
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   742
=== <tt>!DeleteVisualGear(vgUid)</tt> ===
1513
18582093d894 LuaAPI: Update GetVisualGearType and GetGearType
Wuzzy
parents: 1512
diff changeset
   743
Deletes a visual gear.  If it does not exist, nothing happens. 
18582093d894 LuaAPI: Update GetVisualGearType and GetGearType
Wuzzy
parents: 1512
diff changeset
   744
18582093d894 LuaAPI: Update GetVisualGearType and GetGearType
Wuzzy
parents: 1512
diff changeset
   745
Note, most visual gears delete themselves after a while.
18582093d894 LuaAPI: Update GetVisualGearType and GetGearType
Wuzzy
parents: 1512
diff changeset
   746
18582093d894 LuaAPI: Update GetVisualGearType and GetGearType
Wuzzy
parents: 1512
diff changeset
   747
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   748
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   749
Example:
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   750
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   751
<code language="lua">    vgear = AddVisualGear(...)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   752
    DeleteVisualGear(vgear) -- Delete the newly created visual gear.</code>
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   753
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   754
=== <tt>!SetGearValues(gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, ImpactSounds, Tint, Damage, Boom)</tt> ===
1512
06e3cd099d4b LuaAPI: No-op for SetGearValues
Wuzzy
parents: 1511
diff changeset
   755
Sets various gear value for the specified gear (`gearUid`). The meaining of each value often depends on the gear type. See the documentation on !GetGearValues for a brief description of the gear values. If `gearUid` is invalid or the gear does not exist, nothing happens.
612
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   756
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   757
Set `nil` for each value you do not want to change.
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   758
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   759
Example:
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   760
<code language="lua">
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   761
-- Paints all RC planes into a white color
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   762
function onGearAdd(gear)
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   763
    if GetGearType(gear) == gtRCPlane then
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   764
         SetGearValues(gear, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xFFFFFFFF)
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   765
    end
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   766
end
376d1dcb3114 SetGearValues, GetGearValues
Wuzzy
parents: 611
diff changeset
   767
</code>
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   768
1703
c7d3e5459a58 LuaAPI: Add Scale argument for *VisualGearValues
Wuzzy
parents: 1702
diff changeset
   769
=== <tt>!SetVisualGearValues(vgUid, X, Y, dX, dY, Angle, Frame, !FrameTicks, State, Timer, Tint, Scale)</tt> ===
1518
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   770
This allows manipulation of the internal state of the visual gear `vgUid`. If `vgUid` is invalid or the `vgUid` does not refer to an existing visual gear, the function does nothing. Thus, you can safely call this function even if you are not sure if the visual gear actually exists.
1510
b402473a77ba LuaAPI: Update SetVisualGearVaues
Wuzzy
parents: 1506
diff changeset
   771
b402473a77ba LuaAPI: Update SetVisualGearVaues
Wuzzy
parents: 1506
diff changeset
   772
All visual gear values are numbers. Each visual gear may be using these parameters differently, but the *usual* meaning of these is the following:
613
50ad270cfcfb Prettify SetVisualGearValues documentation
Wuzzy
parents: 612
diff changeset
   773
615
632e4dcc8b52 Fix bullet point lists
Wuzzy
parents: 614
diff changeset
   774
 * `X`, `Y`: Position
1188
fbcd3b2458b8 LuaAPI: details for SetVisualGearValues
Wuzzy
parents: 1165
diff changeset
   775
 * `dX`, `dY`: Speed along the X and Y axis
fbcd3b2458b8 LuaAPI: details for SetVisualGearValues
Wuzzy
parents: 1165
diff changeset
   776
 * `Angle`: Current rotation
fbcd3b2458b8 LuaAPI: details for SetVisualGearValues
Wuzzy
parents: 1165
diff changeset
   777
 * `Frame`: Image frame, if using a sprite sheet
1703
c7d3e5459a58 LuaAPI: Add Scale argument for *VisualGearValues
Wuzzy
parents: 1702
diff changeset
   778
 * `FrameTicks` is usually an animation counter
1188
fbcd3b2458b8 LuaAPI: details for SetVisualGearValues
Wuzzy
parents: 1165
diff changeset
   779
 * `State`: Helper value to save some internal state
fbcd3b2458b8 LuaAPI: details for SetVisualGearValues
Wuzzy
parents: 1165
diff changeset
   780
 * `Timer`: Time in milliseconds until it expires
615
632e4dcc8b52 Fix bullet point lists
Wuzzy
parents: 614
diff changeset
   781
 * `Tint`: RGBA color
1703
c7d3e5459a58 LuaAPI: Add Scale argument for *VisualGearValues
Wuzzy
parents: 1702
diff changeset
   782
 * `Scale` is a scale factor (not used by all visual gears)
613
50ad270cfcfb Prettify SetVisualGearValues documentation
Wuzzy
parents: 612
diff changeset
   783
1510
b402473a77ba LuaAPI: Update SetVisualGearVaues
Wuzzy
parents: 1506
diff changeset
   784
Some visual gears interpret these values differently, just like normal gears. See [VisualGearTypes] for details.  Also, most visual gears are not using all possible values, while some values are just ignored.
1188
fbcd3b2458b8 LuaAPI: details for SetVisualGearValues
Wuzzy
parents: 1165
diff changeset
   785
fbcd3b2458b8 LuaAPI: details for SetVisualGearValues
Wuzzy
parents: 1165
diff changeset
   786
Note that most visual gears require little to no modification of their values.
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   787
1704
09694f0d4e90 LuaAPI: fix some asterisks
Wuzzy
parents: 1703
diff changeset
   788
*NOTE*: *Never* use the visual gear's internal state to manipulate/store anything gameplay-related.  Visual gears are not safe for reliable storage and using them as that would lead to strange bugs.
1518
1840cbe874bb LuaAPI: Clarify the restrictions of visual gears
Wuzzy
parents: 1515
diff changeset
   789
613
50ad270cfcfb Prettify SetVisualGearValues documentation
Wuzzy
parents: 612
diff changeset
   790
Example 1:
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   791
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   792
<code language="lua">  -- set a circle to position 1000,1000 pulsing from opacity 20 to 200 (8%-78%), radius of 50, 3px thickness, bright red.
552
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   793
    SetVisualGearValues(circleUid, 1000,1000, 20, 200, 0, 0, 100, 50, 3, 0xff0000ff)</code>
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   794
1188
fbcd3b2458b8 LuaAPI: details for SetVisualGearValues
Wuzzy
parents: 1165
diff changeset
   795
Only the first argument is required. Everything else is optional. Any such argument which is declared as `nil` will not overwrite the corresponding value of the visual gear.
552
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   796
613
50ad270cfcfb Prettify SetVisualGearValues documentation
Wuzzy
parents: 612
diff changeset
   797
Example 2:
552
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   798
1188
fbcd3b2458b8 LuaAPI: details for SetVisualGearValues
Wuzzy
parents: 1165
diff changeset
   799
<code language="lua">  -- set a visual gear to position 1000,1000
552
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   800
    SetVisualGearValues(circleUid, 1000, 1000)</code>
1188
fbcd3b2458b8 LuaAPI: details for SetVisualGearValues
Wuzzy
parents: 1165
diff changeset
   801
<code language="lua">  -- set the tint of a visual gear to bright red.
552
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   802
    SetVisualGearValues(circleUid, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xff0000ff)</code>
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   803
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   804
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   805
=== <tt>!FindPlace(gearUid, fall, left, right[, tryHarder])</tt> ===
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   806
Finds a place for the specified gear between x=`left` and x=`right` and places it there. `tryHarder` is optional, setting it to `true`/`false` will determine whether the engine attempts to make additional passes, even attempting to place gears on top of each other.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   807
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   808
Example:
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   809
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   810
<code language="lua">    gear = AddGear(...)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   811
    FindPlace(gear, true, 0, LAND_WIDTH) -- places the gear randomly between 0 and LAND_WIDTH</code>
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
   812
=== <tt>HogSay(gearUid, text, manner [,vgState])</tt> ===
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   813
Makes the specified gear say, think, or shout some text in a comic-style speech or thought bubble. `gearUid` is _not_ limited to hedgehogs, altough the function name suggests otherwise.
533
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   814
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   815
The `manner` parameter specifies the type of the bubble and can have one of these values:
59
233360620ae2 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 58
diff changeset
   816
533
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   817
|| *Value of `manner`* || *Looks* ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   818
|| `SAY_THINK` || Thought bubble ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   819
|| `SAY_SAY` || Speech bubble ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   820
|| `SAY_SHOUT` || Exclamatory bubble (denotes shouting) ||
59
233360620ae2 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 58
diff changeset
   821
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   822
There is a optional 4th parameter `vgState`, it defines wheather the speechbubble is drawn fully opaque or semi-transparent. The value `0` is the default value.
533
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   823
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   824
|| *Value of `vgState`* || *Effect* ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   825
|| `0` || If the specified gear is a hedgehog, and it’s the turn of the hedgehog’s team, the bubble is drawn fully opaque.<br>If the gear is a hedgehog, and it’s another team’s turn, the bubble is drawn translucent.<br>If the gear is not a hedgehog, the bubble is drawn fully opaque. ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   826
|| `1` || The bubble is drawn translucent. ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   827
|| `2` || The bubble is drawn fully opaque. ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   828
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   829
Examples:
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   830
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   831
<code language="lua">HogSay(CurrentHedgehog, "I wonder what to do …", SAY_THINK) -- thought bubble with text “I wonder what to do …”</code>
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   832
<code language="lua">HogSay(CurrentHedgehog, "I'm hungry.", SAY_SAY) -- speech bubble with text “I’m hungry.”</code>
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   833
<code language="lua">HogSay(CurrentHedgehog, "I smell CAKE!", SAY_SHOUT) -- exclamatory bubble with text “I smell CAKE!”</code>
52
714b56de5ea1 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 51
diff changeset
   834
=== <tt>!HogTurnLeft(gearUid, boolean)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   835
Faces the specified hog left or right.
52
714b56de5ea1 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 51
diff changeset
   836
714b56de5ea1 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 51
diff changeset
   837
Example:
714b56de5ea1 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 51
diff changeset
   838
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   839
<code language="lua">    HogTurnLeft(CurrentHedgehog, true) -- turns CurrentHedgehog left 
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   840
    HogTurnLeft(CurrentHedgehog, false) -- turns CurrentHedgehog right</code>
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   841
=== <tt>!SetGearPosition(gearUid, x, y)</tt> ===
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   842
Places the specified gear exactly at the position (`x`,`y`). Not to be confused with `SetGearPos`.
71
2dcbebb06088 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 70
diff changeset
   843
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
   844
=== <tt>SetGearCollisionMask(gearUid, mask)</tt> ===
1227
edda2e2b973f LuaAPI: Add SetGearCollisionMask and GetGearCollisionMask
Wuzzy
parents: 1226
diff changeset
   845
Set the collision mask of the given gear with `gearUid`.
edda2e2b973f LuaAPI: Add SetGearCollisionMask and GetGearCollisionMask
Wuzzy
parents: 1226
diff changeset
   846
The collision mask defines with which gears and terrain types the gear can collide.
edda2e2b973f LuaAPI: Add SetGearCollisionMask and GetGearCollisionMask
Wuzzy
parents: 1226
diff changeset
   847
1302
3083c0d7e422 LuaAPI: fix some landflag issues
Wuzzy
parents: 1301
diff changeset
   848
`mask` is a number between `0x0000` and `0xFFFF` and used as a bitfield, which means you can combine these flags with `bor`. These are the available flags:
1227
edda2e2b973f LuaAPI: Add SetGearCollisionMask and GetGearCollisionMask
Wuzzy
parents: 1226
diff changeset
   849
1303
3a0bedfe5c75 LuaAPI: remove value colum of gearcollisionmask
Wuzzy
parents: 1302
diff changeset
   850
|| *Identifier* || *Collision with …* ||
3a0bedfe5c75 LuaAPI: remove value colum of gearcollisionmask
Wuzzy
parents: 1302
diff changeset
   851
|| `lfLandMask` || Terrain ||
1637
e747c0c6bf26 LuaAPI: lfCurHogCrate
Wuzzy
parents: 1632
diff changeset
   852
|| `lfCurHogCrate` || Current hedgehog, and crates ||
1303
3a0bedfe5c75 LuaAPI: remove value colum of gearcollisionmask
Wuzzy
parents: 1302
diff changeset
   853
|| `lfHHMask` || Any hedgehogs ||
3a0bedfe5c75 LuaAPI: remove value colum of gearcollisionmask
Wuzzy
parents: 1302
diff changeset
   854
|| `lfNotHHObjMask` || Objects, not hogs (e.g. mines, explosives) ||
3a0bedfe5c75 LuaAPI: remove value colum of gearcollisionmask
Wuzzy
parents: 1302
diff changeset
   855
|| `lfAllObjMask` || Hedgehogs and objects ||
1227
edda2e2b973f LuaAPI: Add SetGearCollisionMask and GetGearCollisionMask
Wuzzy
parents: 1226
diff changeset
   856
edda2e2b973f LuaAPI: Add SetGearCollisionMask and GetGearCollisionMask
Wuzzy
parents: 1226
diff changeset
   857
Beware, the collision mask is often set by the engine as well.
edda2e2b973f LuaAPI: Add SetGearCollisionMask and GetGearCollisionMask
Wuzzy
parents: 1226
diff changeset
   858
1228
460d8f3aaf32 LuaAPI: Rewrite SetGearCollisionMask
Wuzzy
parents: 1227
diff changeset
   859
Examples:
1637
e747c0c6bf26 LuaAPI: lfCurHogCrate
Wuzzy
parents: 1632
diff changeset
   860
<code language="lua">SetGearCollisionMask(gear, bnot(lfCurHogCrate))
1231
550b1afc9300 LuaAPI: fix code syntax
Wuzzy
parents: 1230
diff changeset
   861
-- Ignore collision with current hedgehog</code>
1227
edda2e2b973f LuaAPI: Add SetGearCollisionMask and GetGearCollisionMask
Wuzzy
parents: 1226
diff changeset
   862
1231
550b1afc9300 LuaAPI: fix code syntax
Wuzzy
parents: 1230
diff changeset
   863
<code language="lua">SetGearCollisionMask(gear, 0xFFFF)
550b1afc9300 LuaAPI: fix code syntax
Wuzzy
parents: 1230
diff changeset
   864
-- Collide with everything</code>
1228
460d8f3aaf32 LuaAPI: Rewrite SetGearCollisionMask
Wuzzy
parents: 1227
diff changeset
   865
1302
3083c0d7e422 LuaAPI: fix some landflag issues
Wuzzy
parents: 1301
diff changeset
   866
<code language="lua">SetGearCollisionMask(gear, lfAllObjMask)
1231
550b1afc9300 LuaAPI: fix code syntax
Wuzzy
parents: 1230
diff changeset
   867
-- Collide with hedgehogs and objects</code>
1228
460d8f3aaf32 LuaAPI: Rewrite SetGearCollisionMask
Wuzzy
parents: 1227
diff changeset
   868
1231
550b1afc9300 LuaAPI: fix code syntax
Wuzzy
parents: 1230
diff changeset
   869
<code language="lua">SetGearCollisionMask(gear, 0x0000)
550b1afc9300 LuaAPI: fix code syntax
Wuzzy
parents: 1230
diff changeset
   870
-- Collide with nothing</code>
1228
460d8f3aaf32 LuaAPI: Rewrite SetGearCollisionMask
Wuzzy
parents: 1227
diff changeset
   871
1304
41f5508fe01c LuaAPI: setgearcollisionmask exposure
Wuzzy
parents: 1303
diff changeset
   872
There are actual more flags availbable, but they are not as useful for use in Lua and their constants have not been exposed to Lua. You can find the full range of flags in the engine source code (in Pascal):
41f5508fe01c LuaAPI: setgearcollisionmask exposure
Wuzzy
parents: 1303
diff changeset
   873
41f5508fe01c LuaAPI: setgearcollisionmask exposure
Wuzzy
parents: 1303
diff changeset
   874
[https://hg.hedgewars.org/hedgewars/file/default/hedgewars/uConsts.pas#l112]
1227
edda2e2b973f LuaAPI: Add SetGearCollisionMask and GetGearCollisionMask
Wuzzy
parents: 1226
diff changeset
   875
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   876
=== <tt>!SetGearVelocity(gearUid, dx, dy)</tt> ===
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   877
Gives the specified gear the velocity of `dx`, `dy`.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   878
555
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   879
=== <tt>!SetFlightTime(gearUid, flighttime)</tt> ===
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   880
Sets the `FlightTime` of the given gear to `flighttime`. The meaning of `FlightTime` is explained in the section `GetFlightTime`.
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   881
611
a1d30b3b866c Elasticity and friction
Wuzzy
parents: 610
diff changeset
   882
=== <tt>!SetGearElasticity(gearUid, Elasticity) </tt> ===
a1d30b3b866c Elasticity and friction
Wuzzy
parents: 610
diff changeset
   883
Sets the elasticity of the specified gear. For most gears, the elasticity determines how strong the gear will bounce after collisions, where higher elasticity is for stronger bounces. Recommended are values between `0` and `9999`.
a1d30b3b866c Elasticity and friction
Wuzzy
parents: 610
diff changeset
   884
a1d30b3b866c Elasticity and friction
Wuzzy
parents: 610
diff changeset
   885
=== <tt>!SetGearFriction(gearUid, Friction) </tt> ===
a1d30b3b866c Elasticity and friction
Wuzzy
parents: 610
diff changeset
   886
Sets the friction of the specified gear. The friction normally determines how well the gear will slide on terrain. Higher values are for increased sliding properties. `0` is for no sliding whatsoever, where `9999` is for very long slides, greater values are not recommended.
a1d30b3b866c Elasticity and friction
Wuzzy
parents: 610
diff changeset
   887
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   888
=== <tt>!SetHealth(gearUid, health)</tt> ===
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   889
Sets the health of the specified gear. The “health” of a gear can refer to many things, depending on the gear type.
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   890
1381
6695b6e1d39a LuaAPI: Point to HealHog
Wuzzy
parents: 1327
diff changeset
   891
*Hint*: If you like to increase the health of a hedgehog with nice visual effects, consider using `HealHog` instead.
6695b6e1d39a LuaAPI: Point to HealHog
Wuzzy
parents: 1327
diff changeset
   892
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   893
Use cases:
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   894
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   895
  * Setting the health of a hedgehog (`gtHedgehog`) to 99
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   896
  * Starting the RC Plane (`gtRCPlane`) with 10 bombs
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   897
  * Starting flying saucer (`gtJetpack`) with only 50% fuel
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   898
  * Setting all the mines (`gtMine`) to duds
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   899
  * And more!
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   900
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   901
See [GearTypes] for a full description.
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   902
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   903
<code language="lua">    function onGearAdd(gear)
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   904
       if (GetGearType(gear) == gtHedgehog) then
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   905
            -- Set hedgehog health to 99
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   906
            SetHealth(gear, 99)
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   907
       end
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   908
       if (GetGearType(gear) == gtRCPlaane) then
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   909
            -- Give the plane 10 bombs
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   910
            SetHealth(gear, 10)
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   911
       end
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   912
       if (GetGearType(gear) == gtJetpack) then
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   913
            -- Set fuel to 50% only
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   914
            SetHealth(gear, 1000)
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   915
       end
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   916
       if (GetGearType(gear) == gtMine) then
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   917
            -- Turn mine into dud
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   918
            SetHealth(gear, 0)
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   919
       end
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   920
    end</code>
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   921
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
   922
=== <tt>HealHog(gearUid, healthBoost[, showMessage[, tint]])</tt> (0.9.24) ===
1381
6695b6e1d39a LuaAPI: Point to HealHog
Wuzzy
parents: 1327
diff changeset
   923
Convenience function to increase the health of a hedgehog with default visual effects.
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   924
1381
6695b6e1d39a LuaAPI: Point to HealHog
Wuzzy
parents: 1327
diff changeset
   925
Specifically, this increases the health of the hedgehog gear with the given ID `gearUid` by `healthBoost`, displays some healing particles at the hedgehog and shows the health increae as a message. This is similar to the behavour after taking a health crate, or getting a health boost from vampirism.
1189
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   926
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
   927
If `showMessage` is false, no message is shown. With `tint` you can set the RGBA color of the particles (default: `0x00FF00FF`).
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   928
1191
40698f589acb LuaAPI: HealHog does not affect poison
Wuzzy
parents: 1190
diff changeset
   929
This function does not affect the poison state, however (see `SetEffect`).
40698f589acb LuaAPI: HealHog does not affect poison
Wuzzy
parents: 1190
diff changeset
   930
373
0f9322acd00a update GetEffect/SetEffect info
sheepyluva@gmail.com
parents: 369
diff changeset
   931
=== <tt>!SetEffect(gearUid, effect, effectState)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   932
Sets the state for one of the effects <tt>heInvulnerable, heResurrectable, hePoisoned, heResurrected, heFrozen</tt> for the specified hedgehog gear.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   933
A value of 0 usually means the effect is disabled, values other than that indicate that it is enabled and in some cases specify e.g. the remaining time of that effect.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   934
824
adfb23d8bc13 LuaAPI: fix typo
Wuzzy
parents: 823
diff changeset
   935
|| *`effect`* || *Description* || *`effectState`* ||
823
83dacaa4d7d0 LuaAPI: Explain the different hedgehog effects
Wuzzy
parents: 822
diff changeset
   936
|| `heInvulnerable` || Wether hog is invulnerable || Any non-zero value turns on invulnerability. `0` turns it off. ||
83dacaa4d7d0 LuaAPI: Explain the different hedgehog effects
Wuzzy
parents: 822
diff changeset
   937
|| `hePoisoned` || Poison damage, damages hog each turn. || Amount of damage per turn. Use `0` to disable poisoning. ||
83dacaa4d7d0 LuaAPI: Explain the different hedgehog effects
Wuzzy
parents: 822
diff changeset
   938
|| `heResurrectable` || Whether to resurrect the hog on death || With a non-zero value, the hedgehog will be resurrected and teleported to a random location on death. `0` disables this. ||
824
adfb23d8bc13 LuaAPI: fix typo
Wuzzy
parents: 823
diff changeset
   939
|| `heResurrected` || Whether the hedgehog has been resurrected once. This is only a subtle graphical effect. || With a non-zero value, the hedgehog was resurrected, `0` otherwise. ||
1216
6f312a1ab443 LuaAPI: fix syntax fail near heFrozen
Wuzzy
parents: 1215
diff changeset
   940
|| `heFrozen` || Freeze level. Frozen hedgehogs skip turn, are heavy and take half damage || The hog is considered frozen if the value is `256` or higher, otherwise not. A number of `256` or higher denotes “how frozen” the hedgehog is, i.e. how long it takes to melt. The freezer sets this to `199999` initially. The value will be reduced by `50000` each round. Being hit by a flame reduces this number by `1000`. The values `0` to `255` are used for the freeze/melt animations. ||
1299
c0cade1e3676 LuaAPI: 0.9.24 updates
Wuzzy
parents: 1272
diff changeset
   941
|| `heArtillery` || If enabled, the hedgehog can't walk (since 0.9.24). || `0` = disabled. `1` = permanently enabled. `2` = temporarily enabled (used by sniper rifle between shots) ||
823
83dacaa4d7d0 LuaAPI: Explain the different hedgehog effects
Wuzzy
parents: 822
diff changeset
   942
83dacaa4d7d0 LuaAPI: Explain the different hedgehog effects
Wuzzy
parents: 822
diff changeset
   943
Example (sets all bots poisoned with poison damage of 1):
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   944
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   945
<code language="lua">    function onGearAdd(gear)
558
e9a42aa9e4c2 GetHogLevel, not GetBotLevel
nemo
parents: 557
diff changeset
   946
        if (GetGearType(gear) == gtHedgehog) and (GetHogLevel(gear) > 0) then
373
0f9322acd00a update GetEffect/SetEffect info
sheepyluva@gmail.com
parents: 369
diff changeset
   947
            SetEffect(gear, hePoisoned, 1)
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   948
        end
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   949
    end</code>
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   950
17
2893bd461cc7 LuaAPI: minor improvement
tobias.neumann
parents: 16
diff changeset
   951
=== <tt>CopyPV(gearUid, gearUid)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   952
This sets the position and velocity of the second gear to the first one.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   953
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   954
=== <tt>!FollowGear(gearUid)</tt> ===
1515
ca760c9fcca4 LuaAPI: Update FollowGear
Wuzzy
parents: 1514
diff changeset
   955
Makes the game client follow the specifiec gear (if it exists). Does not work for visual gears.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   956
139
6bf231a611a7 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 138
diff changeset
   957
=== <tt>!SetHogName(gearUid, name)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   958
Sets the name of the specified hedgehog gear.
139
6bf231a611a7 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 138
diff changeset
   959
398
1f9f7fb00be3 Added entries for SetHogTeamName, SetWeapon
RedGrinner@gmail.com
parents: 394
diff changeset
   960
=== <tt>!SetHogTeamName(gearUid, name)</tt> ===
1039
e312e2616b75 LuaAPI: GetHogTeamName: Allow gtGrave
Wuzzy
parents: 1038
diff changeset
   961
Sets the team name of the specified gear. The gear can be a hedgehog or grave.
398
1f9f7fb00be3 Added entries for SetHogTeamName, SetWeapon
RedGrinner@gmail.com
parents: 394
diff changeset
   962
139
6bf231a611a7 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 138
diff changeset
   963
=== <tt>!SetHogHat(gearUid, hat)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   964
Sets the hat of the specified hedgehog gear.
139
6bf231a611a7 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 138
diff changeset
   965
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
   966
=== <tt>!SetGearTarget(gearUid, x, y)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   967
Sets the x and y coordinate of target-based weapons/utilities.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   968
*Note*: This can’t be used in onGearAdd() but must be called after gear creation.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
   969
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   970
=== <tt>!SetState(gearUid, state)</tt> ===
415
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   971
Sets the state of the specified gear to the specified `state`. This is a bitmask made out of the variables as seen in [States].
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   972
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   973
This function is often used together with `GetState` and the bitmask utility functions `band` and `bnot` in order to manipulate a single flag.
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   974
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   975
Examples:
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   976
<code language="lua">
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   977
SetState(CurrentHedgehog, bor(GetState(CurrentHedgehog), gstInvisible))
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   978
--[[ first the state bitmask of CurrentHedgehog is bitwise ORed with
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   979
the gstInvisible flag, thus making the bit responsible for
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   980
invisiblity to become 1. Then the new bitmask is applied to
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   981
CurrentHedgehog, thus making it invisible. ]]
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   982
</code>
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   983
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   984
<code language="lua">
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   985
SetState(CurrentHedgehog, band(GetState(CurrentHedgehog), bnot(gstInvisible)))
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   986
--[[ The reverse of the above: This function toggles CurrentHedgehog’s
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   987
gstInvisible flag off, thus making it visible again. ]]
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   988
</code>
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
   989
114
e311af715b57 Edited wiki page LuaAPI through web user interface.
henrik.rostedt@gmail.com
parents: 107
diff changeset
   990
=== <tt>!SetGearMessage(gearUid, message)</tt> ===
625
e463f9d97820 Some copy-editing
Wuzzy
parents: 624
diff changeset
   991
Sets the gear messages of the specified gear. `message` is a bitmask built out of flags seen in [GearMessages].
114
e311af715b57 Edited wiki page LuaAPI through web user interface.
henrik.rostedt@gmail.com
parents: 107
diff changeset
   992
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   993
=== <tt>!SetTag(gearUid, tag)</tt> ===
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
   994
Sets the `Tag` value of the specified gear (by `gearUid`). The `Tag` value of a gear is simply an extra variable to modify misc. things. The meaning of a tag depends on the gear type. For example, for `gtBall` gears, it specifies the ball color, for `gtAirAttack` gears (airplane) it specifies the direction of the plane, etc. See [GearTypes] for a full list. `tag` has to be an integer.
419
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   995
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   996
Note that the word “tag” here does _not_ refer to the name and health tags you see above hedgehogs, this is something different. 
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   997
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   998
<code language="lua">
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   999
-- This adds a ball (the one from the ballgun) at (123, 456):
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
  1000
ball = AddGear(123, 456, gtBall, 0, 0, 0, 0)
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
  1001
-- This sets the tag of the gear. For gtBall, the tag specified the color. “8” is the color white.
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
  1002
SetTag(ball, 8) -- 
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
  1003
</code>
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
  1004
421
d584704354ad Add link to GearTypes for SetTag and GetTag.
almikes@aol.com
parents: 419
diff changeset
  1005
The meaning of tags are described in [GearTypes].
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
  1006
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
  1007
=== <tt>!SetTimer(gearUid, timer)</tt> ===
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
  1008
Sets the timer of the specified gear. Also see `GetTimer`.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
  1009
360
2fcb523f0cc4 small fixes
sheepyluva@gmail.com
parents: 359
diff changeset
  1010
=== <tt>!SetHogLevel(gearUid, level)</tt> ===
1243
770aa6d54ae2 LuaAPI: clarify HogLevel stuff
Wuzzy
parents: 1241
diff changeset
  1011
Sets the bot level from 0 to 5. `1` is the strongest bot level and `5` is the weakest one (this is the reverse of what players see). `0` means human player.
69
48f6e6c0076d Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 68
diff changeset
  1012
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1013
=== <tt>SetGearAIHints(gearUid, aiHint)</tt> ===
1224
90c14fae29f2 LuaAPI: Add SetGearAIHints
Wuzzy
parents: 1223
diff changeset
  1014
Set some behaviour hints for computer-controlled hedgehogs for any given gear with `gearUid`.
90c14fae29f2 LuaAPI: Add SetGearAIHints
Wuzzy
parents: 1223
diff changeset
  1015
90c14fae29f2 LuaAPI: Add SetGearAIHints
Wuzzy
parents: 1223
diff changeset
  1016
Set `aiHint` to either of:
90c14fae29f2 LuaAPI: Add SetGearAIHints
Wuzzy
parents: 1223
diff changeset
  1017
90c14fae29f2 LuaAPI: Add SetGearAIHints
Wuzzy
parents: 1223
diff changeset
  1018
 * `aihUsualProcessing`: AI hogs treat this gear the usual way. This is the default.
90c14fae29f2 LuaAPI: Add SetGearAIHints
Wuzzy
parents: 1223
diff changeset
  1019
 * `aihDoesntMatter`: AI hogs don't bother attacking this gear intentionally.
90c14fae29f2 LuaAPI: Add SetGearAIHints
Wuzzy
parents: 1223
diff changeset
  1020
90c14fae29f2 LuaAPI: Add SetGearAIHints
Wuzzy
parents: 1223
diff changeset
  1021
Example:
90c14fae29f2 LuaAPI: Add SetGearAIHints
Wuzzy
parents: 1223
diff changeset
  1022
1231
550b1afc9300 LuaAPI: fix code syntax
Wuzzy
parents: 1230
diff changeset
  1023
<code language="lua">
1224
90c14fae29f2 LuaAPI: Add SetGearAIHints
Wuzzy
parents: 1223
diff changeset
  1024
SetGearAIHints(uselessHog, aihDoesntMatter)
1231
550b1afc9300 LuaAPI: fix code syntax
Wuzzy
parents: 1230
diff changeset
  1025
-- This makes AI hogs stop caring about attacking uselessHog</code>
1224
90c14fae29f2 LuaAPI: Add SetGearAIHints
Wuzzy
parents: 1223
diff changeset
  1026
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1027
=== <tt>!SetGearPos(gearUid, value)</tt> ===
891
d991247c5c05 LuaAPI: minor description fixes
Wuzzy
parents: 890
diff changeset
  1028
Sets the `Pos` value (not the position!) of the specified gear to specified value. See `GetGearPos` for more information.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1029
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1030
== Gameplay functions ==
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
  1031
549
fdff535292e4 Minor fix.
almikes@aol.com
parents: 540
diff changeset
  1032
=== `GameFlags` functions ===
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1033
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1034
==== <tt>!ClearGameFlags()</tt> ====
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1035
Disables *all* !GameFlags.
380
b9bd613524ca adding gameflag api documentation
sheepyluva@gmail.com
parents: 379
diff changeset
  1036
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1037
==== <tt>!DisableGameFlags(gameflag, ...)</tt> ====
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1038
Disables the listed !GameFlags, without changing the status of other !GameFlags.
380
b9bd613524ca adding gameflag api documentation
sheepyluva@gmail.com
parents: 379
diff changeset
  1039
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1040
==== <tt>!EnableGameFlags(gameflag, ...)</tt> ====
1253
ea75236aa30c LuaAPI: clarify initial GameFlags
Wuzzy
parents: 1252
diff changeset
  1041
Enables the listed !GameFlags, without changing the status of other !GameFlags. In missions, no !GameFlags are set initially.
380
b9bd613524ca adding gameflag api documentation
sheepyluva@gmail.com
parents: 379
diff changeset
  1042
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1043
==== <tt>!GetGameFlag(gameflag)</tt> ====
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1044
Returns `true` if the specified gameflag is enabled, otherwise `false`.
380
b9bd613524ca adding gameflag api documentation
sheepyluva@gmail.com
parents: 379
diff changeset
  1045
1568
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1046
=== Turns ===
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1047
==== <tt>SkipTurn()</tt> (0.9.24) ====
1568
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1048
Forces the current hedgehog to skip its turn.
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1049
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1050
==== <tt>EndTurn([noTaunts])</tt> (0.9.23) ====
1568
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1051
Ends the current turn immediately.
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1052
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1053
Normally, a “Coward” taunt may be played and an announcer message may be shown (depending on the situation). Set the optional `noTaunts` parameter to `true` to force the engine to never play a taunt or show a message. `noTaunts` is `false` by default.
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1054
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1055
==== <tt>Retreat(time [, respectGetAwayTimeFactor)</tt> (0.9.25) ====
1568
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1056
Forces the current turn into the retreating phase, as if the hog made an attack. That is, the current hedgehog is unable to attack or select a weapon, only movement is possible until the retreat time is up.
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1057
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1058
The retreat time must be set with `time` in milliseconds. By default, this time is automatically multiplied with get-away time percentage from the game scheme for seamless integration with schemes. If you want to ignore the game scheme for some reason and set the retreat time no matter what, set `respectGetAwayTimeFactor` to `false`.
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1059
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1060
If the current hedgehog was busy doing an attack, the attack is aborted, no shot is made. If this function is called in the ready phase of af a turn, the ready phase continues normally, but the turn will begin in the retreat phase instead.
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1061
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1062
Note: If you want the turn to end instantly, it is recommended to use `EndTurn` instead.
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1063
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1064
==== <tt>!SetTurnTimeLeft(newTurnTimeLeft)</tt> (0.9.25) ====
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1065
Set the remaining turn time in milliseconds. The current remaining turn time can be read from the variable `TurnTimeLeft`.
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1066
1569
6bdb276e48b6 LuaAPI: Fix header of SetReadyTimeLeft
Wuzzy
parents: 1568
diff changeset
  1067
==== <tt>!SetReadyTimeLeft(newReadyTimeLeft)</tt> (0.9.25) ====
1570
c58f82d24761 LuaAPI: Fix SetReadyTimeLeft description
Wuzzy
parents: 1569
diff changeset
  1068
Set the remaining ready time in milliseconds. This function should only be called in onNewTurn. The current remaining ready time can be read from the variable `ReadyTimeLeft`.
1568
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1069
1693
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
  1070
==== <tt>!SetTurnTimePaused(isPaused)</tt> (0.9.25) ====
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
  1071
Pauses the turn time indefinitely if `isPaused` is set to `true`, disabled the turn time pause if `isPaused` is set to `false`.
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
  1072
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
  1073
==== <tt>!GetTurnTimePaused()</tt> (0.9.25) ====
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
  1074
Returns `true` if the turn time is currently paused by `SetTurnTimePaused`, otherwise returns `false`.
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
  1075
1568
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1076
==== <tt>!EndGame()</tt> ====
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1077
Makes the game end.
bd6376af4de2 LuaAPI: Add SetTurnTimeLeft and SetReadyTimeLeft
Wuzzy
parents: 1539
diff changeset
  1078
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1079
=== Environment ===
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1080
==== <tt>!SetGravity(percent)</tt> ====
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1081
Changes the current gravity of the game in percent (relative to default, integer value).
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1082
Setting it to 100 will set gravity to default gravity of hedgewars, 200 will double it, etc.
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1083
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1084
==== <tt>!GetGravity()</tt> ====
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1085
Returns the current gravity in percent.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1086
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1087
==== <tt>!SetWaterLine(waterline)</tt> ====
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1088
Sets the water level (`WaterLine`) to the specified y-coordinate.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1089
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1090
==== <tt>!SetWind(windSpeed)</tt> ====
1189
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1091
Sets the current wind in the range of -100 to 100 inclusive. Use together with `gfDisableWind` for full control.
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1092
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1093
==== <tt>!GetWind()</tt> (0.9.24) ====
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1094
Returns current wind, expressed as a floating point number between -100 to 100 inclusive. Note there may be rounding errors.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1095
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1096
==== <tt>!SetMaxBuildDistance(distInPx)</tt> ====
790
1c4b787e841d LuaAPI: fix SetMaxBuildDistance documentation
Wuzzy
parents: 775
diff changeset
  1097
Sets the maximum building distance for of girders and rubber bands in pixels to `distInPx`. If `distInPx` is `0`, the limit is disabled. If called without arguments, the distance will be reset to the default value.
608
9a49d69316f2 SetMaxBuildDistance
Wuzzy
parents: 583
diff changeset
  1098
1655
e7d9a849444b LuaAPI: use <tt>
Wuzzy
parents: 1654
diff changeset
  1099
==== <tt>Explode(x, y, radius[, options])</tt> (0.9.24) ====
1270
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1100
Cause an explosion or erase land, push or damage gears.
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1101
1271
006fe546bd26 LuaAPI: fix typos
Wuzzy
parents: 1270
diff changeset
  1102
By default, an explosion destroys a circular piece of land and damages and pushes gears in its radius.
006fe546bd26 LuaAPI: fix typos
Wuzzy
parents: 1270
diff changeset
  1103
006fe546bd26 LuaAPI: fix typos
Wuzzy
parents: 1270
diff changeset
  1104
The explosion occours at coordinates `(x, y)` with the given `radius`. Assuming 100% damage, the explosion damage at the center equals the explosion radius.
1270
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1105
1272
4f93f837c427 LuaAPI: Explode: animation
Wuzzy
parents: 1271
diff changeset
  1106
The explosion will also have a visual effect (by spawning an explosion visual gear), unless the radius is very small.
4f93f837c427 LuaAPI: Explode: animation
Wuzzy
parents: 1271
diff changeset
  1107
1270
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1108
`options` is a bitmask which can be used to tweak how the explosion behaves:
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1109
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1110
|| *Flag* || *Meaning* ||
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1111
|| `EXPLAutoSound` || Plays an appropriate sound ||
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1112
|| `EXPLNoDamage` || Deal no damage to gears ||
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1113
|| `EXPLDoNotTouchHH` || Do not push hedgehogs ||
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1114
|| `EXPLDoNotTouchAny` || Do not push any gears ||
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1115
|| `EXPLDontDraw` || Do not destroy land ||
1649
c22e796992aa LuaAPI: Add capcol constants
Wuzzy
parents: 1648
diff changeset
  1116
|| `EXPLForceDraw` || Destroy land, even if `gfSolidLand` is active ||
1270
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1117
|| `EXPLNoGfx` || Do not show an explosion animation and do not shake the screen ||
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1118
|| `EXPLPoisoned` || Poison all hedgehogs in explosion radius ||
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1119
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1120
`options` is assumed to be `EXPLAutoSound` by default. Set `options` to 0 to disable all flags.
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1121
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1122
Examples:
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1123
<code language="lua">
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1124
-- Simple explosion at (100, 50) with radius 50
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1125
Explode(100, 50, 50)
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1126
1539
7c038e79eddf LuaAPI: fix simlpe typo
Wuzzy
parents: 1538
diff changeset
  1127
-- Simple explosion without sound
1270
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1128
Explode(100, 50, 50, 0)
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1129
1271
006fe546bd26 LuaAPI: fix typos
Wuzzy
parents: 1270
diff changeset
  1130
-- Fake explosion which only pushes gears but deals no damage to gears and terrain
1270
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1131
Explode(500, 1000, 50, EXPLAutoSound + EXPLNoDamage + EXPLDontDraw)
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1132
1271
006fe546bd26 LuaAPI: fix typos
Wuzzy
parents: 1270
diff changeset
  1133
-- Erase a circle of land without side effects
1270
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1134
Explode(500, 100, 100, EXPLNoDamage + EXPLDoNotTouchAny + EXPLNoGfx)
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1135
</code>
2c4320387c2f LuaAPI: Explode()
Wuzzy
parents: 1269
diff changeset
  1136
912
ea13b02292c5 LuaAPI: Move non-gear related ammo functions to new section
Wuzzy
parents: 911
diff changeset
  1137
=== Ammo ===
ea13b02292c5 LuaAPI: Move non-gear related ammo functions to new section
Wuzzy
parents: 911
diff changeset
  1138
==== <tt>!SetAmmo(ammoType, count, probability, delay, numberInCrate)</tt> ====
1425
640e28c5c860 LuaAPI: Define SetAmmo parameters
Wuzzy
parents: 1411
diff changeset
  1139
This updates the settings (initial ammo, crate probability, etc.) for a specified [AmmoTypes ammo type]. This must only be used in the `onAmmoStoreInit()` event handler. In other places, this function will not work.
912
ea13b02292c5 LuaAPI: Move non-gear related ammo functions to new section
Wuzzy
parents: 911
diff changeset
  1140
1032
8ce955537e1c LuaAPI: fix **all** syntax fail
Wuzzy
parents: 1031
diff changeset
  1141
In Lua missions, for *all* ammo types, the ammo count, probability, delay and number in crates is set to 0 initially. Note: This also includes skip!
1031
637ad254daf9 LuaAPI: Explain the initial ammo setting in missions
Wuzzy
parents: 1030
diff changeset
  1142
1425
640e28c5c860 LuaAPI: Define SetAmmo parameters
Wuzzy
parents: 1411
diff changeset
  1143
Parameters:
640e28c5c860 LuaAPI: Define SetAmmo parameters
Wuzzy
parents: 1411
diff changeset
  1144
1426
2a4793897bb1 LuaAPI: fix typos
Wuzzy
parents: 1425
diff changeset
  1145
 * `ammoType`: Ammo type to be set
2a4793897bb1 LuaAPI: fix typos
Wuzzy
parents: 1425
diff changeset
  1146
 * `count`: Initial ammo count. 9 = infinite
2a4793897bb1 LuaAPI: fix typos
Wuzzy
parents: 1425
diff changeset
  1147
 * `probability`: Crate probability. Max. value is 9. 0 = never
2a4793897bb1 LuaAPI: fix typos
Wuzzy
parents: 1425
diff changeset
  1148
 * `delay`: Number of rounds this ammo is delayed
2a4793897bb1 LuaAPI: fix typos
Wuzzy
parents: 1425
diff changeset
  1149
 * `numberInCrate`: Amount of ammo in a crate
1425
640e28c5c860 LuaAPI: Define SetAmmo parameters
Wuzzy
parents: 1411
diff changeset
  1150
912
ea13b02292c5 LuaAPI: Move non-gear related ammo functions to new section
Wuzzy
parents: 911
diff changeset
  1151
Example:
ea13b02292c5 LuaAPI: Move non-gear related ammo functions to new section
Wuzzy
parents: 911
diff changeset
  1152
ea13b02292c5 LuaAPI: Move non-gear related ammo functions to new section
Wuzzy
parents: 911
diff changeset
  1153
<code language="lua">    SetAmmo(amShotgun, 9, 0, 0, 0) -- unlimited amount of shotgun ammo for players
1031
637ad254daf9 LuaAPI: Explain the initial ammo setting in missions
Wuzzy
parents: 1030
diff changeset
  1154
    SetAmmo(amGrenade, 0, 0, 0, 3) -- crates should contain always three grenade
637ad254daf9 LuaAPI: Explain the initial ammo setting in missions
Wuzzy
parents: 1030
diff changeset
  1155
    SetAmmo(amSkip, 9, 0, 0, 0) -- enable skip</code>
637ad254daf9 LuaAPI: Explain the initial ammo setting in missions
Wuzzy
parents: 1030
diff changeset
  1156
637ad254daf9 LuaAPI: Explain the initial ammo setting in missions
Wuzzy
parents: 1030
diff changeset
  1157
Hint: It is recommended to always enable skip in missions. Only in exceptional circumstances you should choose to not enable skip.
912
ea13b02292c5 LuaAPI: Move non-gear related ammo functions to new section
Wuzzy
parents: 911
diff changeset
  1158
1427
7325e47d2e2f LuaAPI: GetAmmo
Wuzzy
parents: 1426
diff changeset
  1159
==== <tt>!GetAmmo(ammoType)</tt> ====
7325e47d2e2f LuaAPI: GetAmmo
Wuzzy
parents: 1426
diff changeset
  1160
Returns ammo settings (initial ammo, crate probability, etc.) for a specified [AmmoTypes ammo type]. This function is analogue to `SetAmmo`.
7325e47d2e2f LuaAPI: GetAmmo
Wuzzy
parents: 1426
diff changeset
  1161
7325e47d2e2f LuaAPI: GetAmmo
Wuzzy
parents: 1426
diff changeset
  1162
This function returns four numbers, in this order: initial ammo count, probability, delay and number in crate. These values correspond to the parameters 2-5 provided in `SetAmmo` and have the same meaning.
7325e47d2e2f LuaAPI: GetAmmo
Wuzzy
parents: 1426
diff changeset
  1163
7325e47d2e2f LuaAPI: GetAmmo
Wuzzy
parents: 1426
diff changeset
  1164
Example:
7325e47d2e2f LuaAPI: GetAmmo
Wuzzy
parents: 1426
diff changeset
  1165
7325e47d2e2f LuaAPI: GetAmmo
Wuzzy
parents: 1426
diff changeset
  1166
<code language="lua">count, prob, delay, numberInCrate = GetAmmo(amGrenade) -- Get ammo settings of amGrenade</code>
7325e47d2e2f LuaAPI: GetAmmo
Wuzzy
parents: 1426
diff changeset
  1167
912
ea13b02292c5 LuaAPI: Move non-gear related ammo functions to new section
Wuzzy
parents: 911
diff changeset
  1168
==== <tt>!SetAmmoDelay(ammoType, delay)</tt> ====
ea13b02292c5 LuaAPI: Move non-gear related ammo functions to new section
Wuzzy
parents: 911
diff changeset
  1169
Changes the delay of a specified [AmmoTypes Ammo Type].
ea13b02292c5 LuaAPI: Move non-gear related ammo functions to new section
Wuzzy
parents: 911
diff changeset
  1170
1643
2aa0735e0c32 LuaAPI: Add showExtra for SetAmmoTexts
Wuzzy
parents: 1642
diff changeset
  1171
==== <tt>!SetAmmoTexts(ammoType, name, caption, description [, showExtra])</tt> (0.9.23) ====
1006
160112dc2fcf LuaAPI: Clarify SetAmmoTexts usage: Must not be called before onGameStart was fired
Wuzzy
parents: 1004
diff changeset
  1172
Allows you to overwrite the displayed name and tooltip descriptions of a given ammo type. This function must only be called either inside the `onGameStart` callback function, or after the engine has called `onGameStart`.
918
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1173
919
47ff2b524869 LuaAPI: fix bullet points
Wuzzy
parents: 918
diff changeset
  1174
 * `ammoType`: The ammo type to set the text for
47ff2b524869 LuaAPI: fix bullet points
Wuzzy
parents: 918
diff changeset
  1175
 * `name`: Name of the ammo type (e.g. “Grenade” for `amGrenade`), affects both name in ammo menu and in the “ticker” message on the screen top.
47ff2b524869 LuaAPI: fix bullet points
Wuzzy
parents: 918
diff changeset
  1176
 * `caption`: The second line in the ammo menu (below the title). E.g. “Timed grenade” for `amGrenade`.
47ff2b524869 LuaAPI: fix bullet points
Wuzzy
parents: 918
diff changeset
  1177
 * `description`: Description text in ammo menu, below the caption.
1643
2aa0735e0c32 LuaAPI: Add showExtra for SetAmmoTexts
Wuzzy
parents: 1642
diff changeset
  1178
 * `showExtra`: If `false` the special “extra” text line like “Weapon is not yet available” or “Weapon does not end turn” will be suppressed
918
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1179
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1180
`title`, `caption`, `description` can be `nil`, in which case they will be reverted to the engine default value. This function returns `nil`.
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1181
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1182
Example:
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1183
<code language="lua">
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1184
-- Overwrites bazooka name and description
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1185
SetAmmoTexts(amBazooka, "Spoon Missile", "Crazy weapon", "This crazy weapon looks like a spoon and explodes on impact.|Attack: Hold to launch with more power")</code>
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1186
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1187
==== <tt>!SetAmmoDescriptionAppendix(ammoType, descAppend)</tt> (0.9.23) ====
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1188
Will set a string `descAppend` to be appended below the “core” description (ammo tooltip) of the specified `ammoType`, without changing the ordinary description.
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1189
Note that calling this function always sets the complete appended string, you can't use this function to append multiple texts in row.
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1190
920
657f3042209d LuaAPI: fix typo
Wuzzy
parents: 919
diff changeset
  1191
This function is recommended if you have tweaked an existing ammo type only a little and want to keep the original description intact as much as possible.
918
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1192
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1193
Example:
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1194
<code language="lua">
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1195
-- Appends a text to the ammo tooltip of the bazooka but leaves name and main description intact
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1196
SetAmmoTexts(amBazooka, "This weapon deals double the damage than usually.")</code>
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1197
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1198
==== <tt>!AddAmmo(gearUid, ammoType, ammoCount)</tt> ====
1704
09694f0d4e90 LuaAPI: fix some asterisks
Wuzzy
parents: 1703
diff changeset
  1199
Adds `ammoType` to the specified gear. The amount added is determined by the arguments passed via `SetAmmo()` in the `onAmmoStoreInit()` event handler. `ammoCount` is an optional parameter. If this is set, the ammo will *not* be added, but instead set to `ammoCount`. A value of `0` will remove the weapon, a value of `AMMO_INFINITE` will give infinite ammo.
912
ea13b02292c5 LuaAPI: Move non-gear related ammo functions to new section
Wuzzy
parents: 911
diff changeset
  1200
1700
ef1f9ddfe5e2 LuaAPI: AddAmmo per-team
Wuzzy
parents: 1699
diff changeset
  1201
Note: By default, ammo is per-team, so calling `AddAmmo` for a hedgehog will give the ammo for the whole team. The game flags `gfPerHogAmmo` and `gfSharedAmmo` change how ammo is managed in the game, so these game flags also affect `AddAmmo`.
ef1f9ddfe5e2 LuaAPI: AddAmmo per-team
Wuzzy
parents: 1699
diff changeset
  1202
918
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1203
==== <tt>!GetAmmoName(ammoType [, ignoreOverwrite ])</tt> (0.9.23) ====
87e1d0a11e99 LuaAPI: Add SetAmmoDescriptionAppendix, SetAmmoTexts and update GetAmmoName
Wuzzy
parents: 917
diff changeset
  1204
Returns the localized name for the specified `ammoType`, taking an ammo name overwritten by `SetAmmoTexts` into account. If `ignoreOverwrite` is `true`, this function will always return the original ammo name of the weapon and ignores names which may have been overwritten by `SetAmmoTexts`.
912
ea13b02292c5 LuaAPI: Move non-gear related ammo functions to new section
Wuzzy
parents: 911
diff changeset
  1205
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1206
=== Map ===
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1207
==== <tt>!MapHasBorder()</tt> ====
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1208
Returns `true`/`false` if the map has a border or not.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1209
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1210
==== <tt>!TestRectForObstacle(x1, y1, x2, y2, landOnly)</tt> ====
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1211
Checks the rectangle between the given coordinates for possible collisions. Set `landOnly` to `true` if you don’t want to check for collisions with gears (hedgehogs, etc.).
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1212
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1213
==== <tt>!PlaceGirder(x, y, frameIdx)</tt> ====
940
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1214
Attempts to place a girder with centre points `x`, `y` and a certain length and orientation, specified by `frameIdx`. The girder can only be placed in open space and must not collide with anything so this function may fail. It will return `true` on successful placement and `false` on failure.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1215
940
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1216
These are the accepted values for `frameIdx`:
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1217
940
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1218
|| *`frameIdx`* || *Length* || *Orientation* ||
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1219
|| 0 || short || horizontal ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1220
|| 1 || short || decreasing right ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1221
|| 2 || short || vertical ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1222
|| 3 || short || increasing right ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1223
|| 4 || long || horizontal ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1224
|| 5 || long || decreasing right ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1225
|| 6 || long || vertical ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1226
|| 7 || long || increasing right ||
412
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
  1227
940
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1228
==== <tt>!PlaceRubber(x, y, frameIdx)</tt> (0.9.23) ====
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1229
Attempts to place a rubber with centre points `x`, `y` and a certain orientation, specified by `frameIdx`. The rubber can only be placed in open space and must not collide with anything so this function may fail. It will return `true` on successful placement and `false` on failure.
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1230
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1231
These are the accepted values for `frameIdx`:
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1232
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1233
|| *`frameIdx`* || *Orientation* ||
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1234
|| 0 || horizontal ||
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1235
|| 1 || decreasing right ||
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1236
|| 2 || vertical ||
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1237
|| 3 || increasing right ||
8c4a529edddb LuaAPI: PlaceRubber
Wuzzy
parents: 936
diff changeset
  1238
688
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
  1239
==== <tt>!PlaceSprite(x, y, sprite, frameIdx, tint, behind, flipHoriz, flipVert, [, landFlag, ...])</tt> ====
869
a09b1abfe5e8 LuaAPI: return PlaceGirder and PlaceSprite tweaks
Wuzzy
parents: 866
diff changeset
  1240
Places a [Sprites sprite] at the specified position (`x`, `y`) on the map, it behaves like terrain then. Unlike `PlaceGirder`, this function does not check for collisions, so the sprite can be placed anywhere within map boundaries. The function returns `true` if the placement was successful, `false` otherwise. `frameIdx` is the frame index starting by 0. `frameIdx` is used if the sprite consists of several sub-images. Only a subset of the sprites is currently supported by this function:
539
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1241
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1242
 * `sprAmGirder`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1243
 * `sprAmRubber`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1244
 * `sprAMSlot`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1245
 * `sprAMAmmos`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1246
 * `sprAMAmmosBW`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1247
 * `sprAMCorners`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1248
 * `sprHHTelepMask`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1249
 * `sprTurnsLeft`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1250
 * `sprSpeechCorner`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1251
 * `sprSpeechEdge`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1252
 * `sprSpeechTail`
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1253
 * `sprTargetBee`
539
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1254
 * `sprThoughtCorner`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1255
 * `sprThoughtEdge`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1256
 * `sprThoughtTail`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1257
 * `sprShoutCorner`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1258
 * `sprShoutEdge`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1259
 * `sprShoutTail`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1260
 * `sprBotlevels`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1261
 * `sprIceTexture`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1262
 * `sprCustom1`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1263
 * `sprCustom2`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1264
1506
a1bfc81f6295 LuaAPI: Add tint explanation for PlaceSprite
Wuzzy
parents: 1505
diff changeset
  1265
`tint` is for an RGBA colouring to apply, this works about the same as `Tint` in gears. If `nil`, the original color is used.
a1bfc81f6295 LuaAPI: Add tint explanation for PlaceSprite
Wuzzy
parents: 1505
diff changeset
  1266
a1bfc81f6295 LuaAPI: Add tint explanation for PlaceSprite
Wuzzy
parents: 1505
diff changeset
  1267
`behind` indicates the sprite should not replace existing land.
a1bfc81f6295 LuaAPI: Add tint explanation for PlaceSprite
Wuzzy
parents: 1505
diff changeset
  1268
a1bfc81f6295 LuaAPI: Add tint explanation for PlaceSprite
Wuzzy
parents: 1505
diff changeset
  1269
`flipHoriz` and `flipVert` are for mirroring the sprite vertically and horizontally before placing, respectively.
a1bfc81f6295 LuaAPI: Add tint explanation for PlaceSprite
Wuzzy
parents: 1505
diff changeset
  1270
a1bfc81f6295 LuaAPI: Add tint explanation for PlaceSprite
Wuzzy
parents: 1505
diff changeset
  1271
The 9th and later arguments specify land flags (see the constants section) to be used for the newly created terrain. If omitted, `lfNormal` is assumed.
539
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1272
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1273
Example:
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1274
688
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
  1275
<code language="lua">PlaceSprite(2836, 634, sprAmGirder, 5)
539
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1276
-- Places the girder sprite as normal terrain at (2836, 634). The `frameIdx` 5 is for the long decreasing right girder.</code>
688
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
  1277
<code language="lua">PlaceSprite(1411, 625, sprAmRubber, 1, nil, nil, nil, nil, lfBouncy)
539
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1278
-- Places the rubber band sprite as bouncy terrain at (2836, 634). The `frameIdx` 1 is for the decreasing right rubber band.</code>
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
  1279
688
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
  1280
==== <tt>!EraseSprite(x, y, sprite, frameIdx, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert, [, landFlag, ...])</tt> ====
692
111f39408390 Clean up markup for PlaceSprite and EraseSprite and clarify some stuff
Wuzzy
parents: 691
diff changeset
  1281
Erases a [Sprites sprite] at the specified position (`x`, `y`) on the map. `frameIdx` is the frame index starting by 0. `sprite`, `frameIdx`, `flipHoriz` and `flipVert` behave the same as in `PlaceSprite`. For `sprite`, the same subset of sprites is permitted.
688
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
  1282
692
111f39408390 Clean up markup for PlaceSprite and EraseSprite and clarify some stuff
Wuzzy
parents: 691
diff changeset
  1283
Set `eraseOnLFMatch` to `true` to erase all land for a pixel that matches any of the passed in land flags.  This is useful if, for example, an `lfBouncy` sprite was placed “behind” land using `PlaceSprite` and you want to remove it without destroying the non-bouncy terrain.
688
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
  1284
692
111f39408390 Clean up markup for PlaceSprite and EraseSprite and clarify some stuff
Wuzzy
parents: 691
diff changeset
  1285
Set `onlyEraseLF` to `true` to only remove specific land flags. If for example a sprite consists of `lfIndestructible` and `lfBouncy`, and you call `EraseSprite` with `onlyEraseLF` and `lfIndestructible` set, the sprite will remain bouncy but can be destroyed.  You can use this to entirely remove all land flags from a sprite—at this point the sprite will be visual only, painted on the map but with no collision.
688
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
  1286
692
111f39408390 Clean up markup for PlaceSprite and EraseSprite and clarify some stuff
Wuzzy
parents: 691
diff changeset
  1287
Examples:
688
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
  1288
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
  1289
<code language="lua">EraseSprite(2836, 634, sprAmGirder, 5)
692
111f39408390 Clean up markup for PlaceSprite and EraseSprite and clarify some stuff
Wuzzy
parents: 691
diff changeset
  1290
-- Removes the girder sprite at (2836, 634). The frameIdx 5 is for the long decreasing right girder.</code>
688
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
  1291
<code language="lua">EraseSprite(1411, 625, sprAmRubber, 1, true, true, nil, nil, lfIndestructible)
692
111f39408390 Clean up markup for PlaceSprite and EraseSprite and clarify some stuff
Wuzzy
parents: 691
diff changeset
  1292
-- Removes indestructibility from a rubber band sprite at (2836, 634). The frameIdx 1 is for the decreasing right rubber band.</code>
688
d9fc58ac04f2 Update EraseSprite, PlaceSprite and Get/Set GearValues
nemo
parents: 685
diff changeset
  1293
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1294
==== <tt>!AddPoint(x, y [, width [, erase] ])</tt> ====
412
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
  1295
This function is used to draw your own maps using Lua. The maps drawn with this are of type “hand-drawn”.
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
  1296
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
  1297
The function takes a `x`,`y` location, a `width` (means start of a new line) and `erase` (if `false`, this function will draw normally, if `true`, this function will erase drawn stuff).
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
  1298
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
  1299
This function must be called within `onGameInit`, where `MapGen` has been set to `mgDrawn`. You also should call `FlushPoints` when you are finished with drawing.
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
  1300
1391
86bada04da8f LuaAPI: Add reference to LuaDrawing
Wuzzy
parents: 1381
diff changeset
  1301
See [LuaDrawning] for some examples.
86bada04da8f LuaAPI: Add reference to LuaDrawing
Wuzzy
parents: 1381
diff changeset
  1302
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1303
==== <tt>!FlushPoints()</tt> ====
412
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
  1304
Makes sure that all the points/lines specified using `AddPoint` are actually applied to the map. This function must be called within `onGameInit`.
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
  1305
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1306
=== Current hedgehog ===
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1307
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1308
==== <tt>!GetCurAmmoType()</tt> ====
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1309
Returns the currently selected [AmmoTypes Ammo Type].
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1310
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1311
==== <tt>!SwitchHog(gearUid)</tt> ====
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1312
This function will switch to the hedgehog with the specifiedd `gearUid`.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1313
1246
0f08b9671715 LuaAPI: fix header of SetWeapon and SetNextWeapon
Wuzzy
parents: 1245
diff changeset
  1314
==== <tt>!SetWeapon(ammoType)</tt> ====
1245
355898ec2631 LuaAPI: Move SetWeapon and SetNextWeapon
Wuzzy
parents: 1244
diff changeset
  1315
Sets the selected weapon of `CurrentHedgehog` to one of the [AmmoTypes Ammo Type].
355898ec2631 LuaAPI: Move SetWeapon and SetNextWeapon
Wuzzy
parents: 1244
diff changeset
  1316
1299
c0cade1e3676 LuaAPI: 0.9.24 updates
Wuzzy
parents: 1272
diff changeset
  1317
Examples:
1245
355898ec2631 LuaAPI: Move SetWeapon and SetNextWeapon
Wuzzy
parents: 1244
diff changeset
  1318
355898ec2631 LuaAPI: Move SetWeapon and SetNextWeapon
Wuzzy
parents: 1244
diff changeset
  1319
<code language="lua">
1299
c0cade1e3676 LuaAPI: 0.9.24 updates
Wuzzy
parents: 1272
diff changeset
  1320
  SetWeapon(amBazooka) -- select the bazooka (if hog has one)
c0cade1e3676 LuaAPI: 0.9.24 updates
Wuzzy
parents: 1272
diff changeset
  1321
</code>
c0cade1e3676 LuaAPI: 0.9.24 updates
Wuzzy
parents: 1272
diff changeset
  1322
<code language="lua">
c0cade1e3676 LuaAPI: 0.9.24 updates
Wuzzy
parents: 1272
diff changeset
  1323
  SetWeapon(amNothing) -- unselects the weapon.
c0cade1e3676 LuaAPI: 0.9.24 updates
Wuzzy
parents: 1272
diff changeset
  1324
</code>
1245
355898ec2631 LuaAPI: Move SetWeapon and SetNextWeapon
Wuzzy
parents: 1244
diff changeset
  1325
1246
0f08b9671715 LuaAPI: fix header of SetWeapon and SetNextWeapon
Wuzzy
parents: 1245
diff changeset
  1326
==== <tt>!SetNextWeapon()</tt> ====
1245
355898ec2631 LuaAPI: Move SetWeapon and SetNextWeapon
Wuzzy
parents: 1244
diff changeset
  1327
This function makes the current hedgehog switch to the next weapon in list of available weapons. It can be used for example in trainings to pre-select a weapon.
355898ec2631 LuaAPI: Move SetWeapon and SetNextWeapon
Wuzzy
parents: 1244
diff changeset
  1328
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1329
==== <tt>!SetInputMask(mask)</tt> ====
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1330
Masks specified player input. This means that Hedgewars ignores certain player inputs, such as walking or jumping.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1331
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1332
Example: 
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
  1333
<code language="lua">    -- masks the long and high jump commands
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1334
SetInputMask(band(0xFFFFFFFF, bnot(gmLJump + gmHJump))) 
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1335
    -- clears input mask, allowing player to take actions
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1336
    SetInputMask(0xFFFFFFFF) 
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1337
		</code>
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1338
*Note*: Using the input mask is an effective way to script uninterrupted cinematics, or create modes such as No Jumping.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1339
936
14d3c48a8913 LuaAPI: Warn about Animate (SetInputMask)
Wuzzy
parents: 932
diff changeset
  1340
*Note*: This function is used internally in the Animate [LuaLibraries library].
14d3c48a8913 LuaAPI: Warn about Animate (SetInputMask)
Wuzzy
parents: 932
diff changeset
  1341
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1342
See also [GearMessages].
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1343
405
4e1c166740b0 Add GetInputMask
almikes@aol.com
parents: 404
diff changeset
  1344
==== <tt>!GetInputMask()</tt> ====
4e1c166740b0 Add GetInputMask
almikes@aol.com
parents: 404
diff changeset
  1345
Returns the current input mask of the player.
4e1c166740b0 Add GetInputMask
almikes@aol.com
parents: 404
diff changeset
  1346
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1347
==== <tt>!SetVampiric(bool)</tt> (0.9.24) ====
1189
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1348
Toggles vampirism mode for this turn. Set `bool` to `true` to enable (same effect as if the hedgehog has used Vampirism), `false` to disable.
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1349
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1350
==== <tt>!GetVampiric()</tt> (0.9.25) ====
1498
17a55d9cc7b9 LuaAPI: GetVampirism, GetLaserSight, IsHogHidden
Wuzzy
parents: 1491
diff changeset
  1351
Returns true if vampirism mode is currently active.
17a55d9cc7b9 LuaAPI: GetVampirism, GetLaserSight, IsHogHidden
Wuzzy
parents: 1491
diff changeset
  1352
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1353
==== <tt>!SetLaserSight(bool)</tt> (0.9.24) ====
1189
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1354
Toggles laser sight for this turn. Set `bool` to `true` to enable (same effect as if the hedgehog has used Laser Sight), `false` to disable.
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1355
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1356
==== <tt>!GetLaserSight()</tt> (0.9.25) ====
1498
17a55d9cc7b9 LuaAPI: GetVampirism, GetLaserSight, IsHogHidden
Wuzzy
parents: 1491
diff changeset
  1357
Returns true if laser sight (as utility) is currently active. The sniper rifle's built-in laser sight does not count.
17a55d9cc7b9 LuaAPI: GetVampirism, GetLaserSight, IsHogHidden
Wuzzy
parents: 1491
diff changeset
  1358
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1359
==== <tt>!EnableSwitchHog()</tt> (0.9.25) ====
1411
7c5c8c620a9f LuaAPI: EnableSwitchHog()
Wuzzy
parents: 1410
diff changeset
  1360
Enable hog switching mode for the current hedgehog. This function should be called while the hedgehog is standing on solid ground (`GetFlightTime` returns 0).
7c5c8c620a9f LuaAPI: EnableSwitchHog()
Wuzzy
parents: 1410
diff changeset
  1361
7c5c8c620a9f LuaAPI: EnableSwitchHog()
Wuzzy
parents: 1410
diff changeset
  1362
Internally, this tries to spawn a `gtSwitcher` gear which, as long it exists, handles the hog switching. You can delete this gear to stop the hog switching prematurely. If there already is a `gtSwitcher` gear, no additional gear is spawned.
7c5c8c620a9f LuaAPI: EnableSwitchHog()
Wuzzy
parents: 1410
diff changeset
  1363
7c5c8c620a9f LuaAPI: EnableSwitchHog()
Wuzzy
parents: 1410
diff changeset
  1364
On success, returns the `gtSwitcher` gear being spawned or, if hog switching mode is already active, returns the exsting gear. On failure, returns `nil`.
7c5c8c620a9f LuaAPI: EnableSwitchHog()
Wuzzy
parents: 1410
diff changeset
  1365
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1366
=== Randomness ===
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1367
==== <tt>!GetRandom(number)</tt> ====
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1368
Returns a randomly generated number in the range of 0 to number - 1. This random number uses the game seed, so is synchronised, and thus safe for multiplayer and saved games. Use `GetRandom` for anything that could impact the engine state. For example, a visual gear could simply use Lua’s `math.random`, but adding a regular gear should use `GetRandom`.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1369
413
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
  1370
=== Clans and teams ===
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
  1371
==== <tt>!AddTeam(teamname, color, grave, fort, voicepack, flag)</tt> ====
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
  1372
1640
b91b4d97132d LuaAPI: AddTeam formatting
Wuzzy
parents: 1639
diff changeset
  1373
Adds a new team.
b91b4d97132d LuaAPI: AddTeam formatting
Wuzzy
parents: 1639
diff changeset
  1374
b91b4d97132d LuaAPI: AddTeam formatting
Wuzzy
parents: 1639
diff changeset
  1375
You *must* call it only in `onGameInit`.
476
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
  1376
You *must* add at least one hedgehog with `AddHog` after calling this. The engine does not support empty teams.
1640
b91b4d97132d LuaAPI: AddTeam formatting
Wuzzy
parents: 1639
diff changeset
  1377
`AddTeam` is only supported for singleplayer missions. You *must not* call this function in multiplayer.
476
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
  1378
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
  1379
Arguments:
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
  1380
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
  1381
 * `teamname`: The name of the team.
1638
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1382
 * `color`: Team color, usually a number from -9 to -1 (see below)
476
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
  1383
 * `grave`: The name of the team’s grave (equals file name without the suffix)
638
9f17dc37a141 some AddTeam clarifications
Wuzzy
parents: 637
diff changeset
  1384
 * `fort`: The name of the team’s fort (equals file name without the suffix and without the letter “L” or “R” before that suffix)
476
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
  1385
 * `voicepack`: The name of the team’s voice pack (equals the directory name)
638
9f17dc37a141 some AddTeam clarifications
Wuzzy
parents: 637
diff changeset
  1386
 * `flag`: Optional argument for the name of the team’s flag (equals file name without the suffix). If set to `nil`, the flag “hedgewars” is used.
476
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
  1387
1638
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1388
===== Clan color =====
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1389
Each team must have a color. The color also determines clan membership: Teams with equal color are in the same clan.
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1390
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1391
The team color is specified as a number from -9 to -1. This will select one of the 9 possible team colors as specified in the player's settings. As the actual colors are set by the player, you can't predict them, but you can usually trust these defaults:
413
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
  1392
1638
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1393
 * `-1`: red
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1394
 * `-2`: blue
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1395
 * `-3`: cyan
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1396
 * `-4`: purple
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1397
 * `-5`: magenta
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1398
 * `-6`: green
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1399
 * `-7`: orange
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1400
 * `-8`: brown
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1401
 * `-9`: yellow
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1402
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1403
An older (and now discouraged) method of specifying the color is by hardcoding it as an RGB color (i.e. `0xDD0000`). This practice is now strongly discouraged because it will ignore the player-chosen color (which is *bad* for players with color blindness) and in 99% of cases you don't need it anyway. It should be only used for testing and debugging. 
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1404
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1405
===== Example =====
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1406
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1407
<code language="lua">AddTeam("team 1", -1, "Simple", "Tank", "Default", "hedgewars")
0322ae59b027 LuaAPI: Update AddTeam
Wuzzy
parents: 1637
diff changeset
  1408
--[[ Adds a new team with name “team 1”, the first default color (usually red), the grave “Simple”,
476
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
  1409
the fort “Tank” the voicepack “Default” and the flag “hedgewars”. ]]</code>
413
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
  1410
1696
90dc2f42db2b LuaAPI: Fix AddMissionTeam header
Wuzzy
parents: 1695
diff changeset
  1411
==== <tt>!AddMissionTeam(color)</tt> (0.9.25) ====
1695
6bf2e6deedb0 LuaAPI: Fix some bugs
Wuzzy
parents: 1694
diff changeset
  1412
Adds a new team using the player-chosen team identity when playing a singleplayer mission. Does not work in multiplayer.
1694
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
  1413
1695
6bf2e6deedb0 LuaAPI: Fix some bugs
Wuzzy
parents: 1694
diff changeset
  1414
This function is very similar to `AddTeam`. Team settings like team name and flag will be taken from the player-chosen team.
6bf2e6deedb0 LuaAPI: Fix some bugs
Wuzzy
parents: 1694
diff changeset
  1415
You only need to specify the clan color, which has the same meaning as in `AddTeam`.
1694
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
  1416
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
  1417
Use `AddMissionHog` or `AddHog` afterwards to add hedgehogs for this team. You can mix `AddMissionHog` and `AddHog` as you wish.
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
  1418
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
  1419
Example:
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
  1420
<code language="lua">-- Add mission team with default clan color
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
  1421
AddMissionTeam(-1)</code>
d3bebda2cdfd LuaAPI: Add AddMissionTeam / AddMissionHog
Wuzzy
parents: 1693
diff changeset
  1422
1189
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1423
==== <tt>!GetTeamName(teamIdx)</tt> (0.9.24) ====
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1424
Returns the name of the team with the index `teamIdx`. `teamIdx` is a number between 0 and `TeamsCount-1`.
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1425
1218
344aa78491f6 LuaAPI: fix GetTeamIndex
Wuzzy
parents: 1217
diff changeset
  1426
==== <tt>!GetTeamIndex(teamname)</tt> (0.9.24) ====
1217
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1427
Returns the team index (number between 0 and `TeamsCount-1`) of the team with the name `teamName`.
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1428
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1429
==== <tt>!GetTeamClan(teamname)</tt> (0.9.24) ====
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1430
Returns the clan ID of the team with the given `teamName`.
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1431
413
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
  1432
==== <tt>!DismissTeam(teamname)</tt> ====
1217
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1433
Vaporizes all the hogs of the team with the given team name in a puff of smoke.
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1434
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1435
This function must not be called while it's the team's turn.
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1436
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1437
==== <tt>!SetTeamLabel(teamname[, label])</tt> (0.9.24) ====
1217
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1438
Set or remove a label for the team with the given team name. The label is a string and will be displayed next to the team's health bar.
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1439
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1440
If `label` is `nil`, the label will be removed.
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1441
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1442
There's a special case: If the AI Survival game modifier is active, the AI kill counter will be replaced by the custom team label if it has been set. If `label` is set to `nil`, the default AI counter is shown again.
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1443
dcd14c9ccd2f LuaAPI: Add 3 more 0.9.24 functions
Wuzzy
parents: 1216
diff changeset
  1444
Use this to display a score, power value or another important team attribute. There's no hard length limit, but please try to keep it as short as possible to avoid visual clutter.
413
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
  1445
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1446
==== <tt>!GetClanColor(clan)</tt> ====
858
2a562faa73fb LuaAPI: GetClanColor, SetClanColor: They use RGBA instead of RGB
Wuzzy
parents: 826
diff changeset
  1447
Returns the RGBA color of the chosen clan by its number. The color data type is described in [LuaAPI#Color].
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1448
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1449
==== <tt>!SetClanColor(clan, color)</tt> ====
1711
d2397947f3d7 LuaAPI: Add graph warning for SetClanColor
Wuzzy
parents: 1708
diff changeset
  1450
Sets the RGBA color of the chosen clan by its number. The color data type is described in [LuaAPI#Color]. The new clan color *must* be different from the color of all clans (you can't use this function to change clan memberships of teams).
d2397947f3d7 LuaAPI: Add graph warning for SetClanColor
Wuzzy
parents: 1708
diff changeset
  1451
d2397947f3d7 LuaAPI: Add graph warning for SetClanColor
Wuzzy
parents: 1708
diff changeset
  1452
Note: The stats graph does not support changing clan colors. If the clan colors change in mid-game, the graph might get confused and shows weird stuff. You may want to turn off the graph with if this is the case (see `SendHealthStatsOff`).
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1453
577
6e77c79a8457 Add GetCampaignVar and SaveCampaignVar
almikes@aol.com
parents: 576
diff changeset
  1454
=== Campaign management ===
6e77c79a8457 Add GetCampaignVar and SaveCampaignVar
almikes@aol.com
parents: 576
diff changeset
  1455
==== <tt>!SaveCampaignVar(varname, value)</tt> ====
6e77c79a8457 Add GetCampaignVar and SaveCampaignVar
almikes@aol.com
parents: 576
diff changeset
  1456
Stores the value `value` (a string) into the campaign variable `varname` (also a string). Campaign variables allow you to save progress of a team in a certain campaign. Campaign variables are saved on a per-team per-campaign basis. They are written into the team file (see [ConfigurationFiles#TeamName.hwt]).
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1457
579
9895045e9963 Updated SaveCampaignVar / GetCampaignVar links
almikes@aol.com
parents: 577
diff changeset
  1458
There are some special campaign variables which are used by Hedgewars to determine which missions to display in the campaign menu. This is described [ConfigurationFiles#%5BCampaign%20%3CCAMPAIGN_NAME%3E%5D here].
9895045e9963 Updated SaveCampaignVar / GetCampaignVar links
almikes@aol.com
parents: 577
diff changeset
  1459
577
6e77c79a8457 Add GetCampaignVar and SaveCampaignVar
almikes@aol.com
parents: 576
diff changeset
  1460
==== <tt>!GetCampaignVar(varname)</tt> ====
579
9895045e9963 Updated SaveCampaignVar / GetCampaignVar links
almikes@aol.com
parents: 577
diff changeset
  1461
Returns the value of the campaign variable `varname` as a string. See also `SaveCampaignVar`.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1462
1693
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
  1463
==== <tt>!SaveMissionVar(varname, value)</tt> (0.9.25) ====
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
  1464
Stores the value `value` (a string) into the mission variable `varname` (also a string). A mission variable is like a campaign variable, but it applies for singleplayer missions only (Training/Challenge/Scenario), excluding campaign missions.
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
  1465
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
  1466
==== <tt>!GetMissionVar(varname)</tt> (0.9.25) ====
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
  1467
Returns the value of the mission variable `varname` as a string. See also `SaveMissionVar`.
a1ff7cf0f55c LuaAPI: Add a few 0.9.25 functions
Wuzzy
parents: 1692
diff changeset
  1468
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1469
== Functions affecting the GUI ==
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1470
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1471
=== <tt>!AddCaption(text)</tt> ===
561
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
  1472
Display an event text in the upper part of the screen. The text will be white and the caption group will be `capgrpMessage`.
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
  1473
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
  1474
Example:
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
  1475
<code language="lua">
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
  1476
AddCaption("Hello, world!")
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
  1477
</code>
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
  1478
561
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
  1479
=== <tt>!AddCaption(text, color, captiongroup)</tt> ===
1649
c22e796992aa LuaAPI: Add capcol constants
Wuzzy
parents: 1648
diff changeset
  1480
Display an event text in the upper part of the screen with the specified RGBA text [LuaAPI#Color color] and caption group. Although an RBGA color is used, Hedgewars does not actually support transparent or semi-transparent captions, so the fourth byte is ignored. We recommend you to always specify a full opacity (`FF` in hexadecimal) for the caption.
561
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
  1481
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
  1482
|| *`captiongroup`* || *Meaning* ||
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
  1483
|| `capgrpGameState` || Used for important global game events, like Sudden Death ||
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
  1484
|| `capgrpAmmoinfo` || Used for new weapon crates and some other events ||
1502
c94cb3aa0b3b LuaAPI: update capgrpVolume
Wuzzy
parents: 1499
diff changeset
  1485
|| `capgrpVolume` || Used for “local” changes of client settings that don't affect gameplay, like volume change, auto camera on/off, etc. ||
561
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
  1486
|| `capgrpMessage` || Generic message ||
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
  1487
|| `capgrpMessage2` || Generic message ||
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
  1488
|| `capgrpAmmostate` || Used to show information about weapon state, i.e. bounce level, timer, remaining shots, etc. ||
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
  1489
1649
c22e796992aa LuaAPI: Add capcol constants
Wuzzy
parents: 1648
diff changeset
  1490
The color can be specified in RGBA format, but you can (but don't have to) use one of the following built-in text color.
c22e796992aa LuaAPI: Add capcol constants
Wuzzy
parents: 1648
diff changeset
  1491
c22e796992aa LuaAPI: Add capcol constants
Wuzzy
parents: 1648
diff changeset
  1492
|| *Built-in color* || *Meaning* ||
c22e796992aa LuaAPI: Add capcol constants
Wuzzy
parents: 1648
diff changeset
  1493
|| `capcolDefault` || Default caption color ||
c22e796992aa LuaAPI: Add capcol constants
Wuzzy
parents: 1648
diff changeset
  1494
|| `capcolSetting` || Notification related to a local client setting (audio volume, auto camera on/off) ||
c22e796992aa LuaAPI: Add capcol constants
Wuzzy
parents: 1648
diff changeset
  1495
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
  1496
Example:
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
  1497
<code language="lua">
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
  1498
AddCaption("Melon bomb rain in 2 rounds!", 0xFF0000FF, capgrpGameState)
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
  1499
-- Green example message.
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
  1500
</code>
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1501
1644
009208830d85 LuaAPI: Add forceDisplay to ShowMission
Wuzzy
parents: 1643
diff changeset
  1502
=== <tt>!ShowMission(caption, subcaption, text, icon, time [, forceDisplay])</tt> ===
894
aa3027b760bb LuaAPI: Better ShowMission/HideMission texts
Wuzzy
parents: 893
diff changeset
  1503
This function will open the mission panel and set the texts in it.
aa3027b760bb LuaAPI: Better ShowMission/HideMission texts
Wuzzy
parents: 893
diff changeset
  1504
aa3027b760bb LuaAPI: Better ShowMission/HideMission texts
Wuzzy
parents: 893
diff changeset
  1505
Use to tell the player what he/she is supposed to do. If you use this function, a mission panel is shown for the amount of time specified in `time` (in milliseconds). If `time` is set to 0, it will be displayed for a default amount of time.
aa3027b760bb LuaAPI: Better ShowMission/HideMission texts
Wuzzy
parents: 893
diff changeset
  1506
This function replaces the *entire* text of the mission panel. Compare this to the global `Goals` variable, which *adds* to the default text without replacing it.
645
f161ad0b976d Explain all arguments of ShowMission
Wuzzy
parents: 638
diff changeset
  1507
f161ad0b976d Explain all arguments of ShowMission
Wuzzy
parents: 638
diff changeset
  1508
`caption` is the text displayed in the first line, `subcaption` is displayed in the second line and `text` is the text displayed in the third and following lines.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
  1509
1715
5cac9aadcc27 LuaAPI: Update special escape characters for ShowMission
Wuzzy
parents: 1711
diff changeset
  1510
`text` uses some special characters for formatting:
5cac9aadcc27 LuaAPI: Update special escape characters for ShowMission
Wuzzy
parents: 1711
diff changeset
  1511
1716
029712a337ba LuaAPI: Header formatting
Wuzzy
parents: 1715
diff changeset
  1512
|| *Special character* || *Meaning* ||
1715
5cac9aadcc27 LuaAPI: Update special escape characters for ShowMission
Wuzzy
parents: 1711
diff changeset
  1513
|| `|` || Line break ||
5cac9aadcc27 LuaAPI: Update special escape characters for ShowMission
Wuzzy
parents: 1711
diff changeset
  1514
|| `:` || Highlight itself and all text before that character in this line. The colon itself will be written. ||
5cac9aadcc27 LuaAPI: Update special escape characters for ShowMission
Wuzzy
parents: 1711
diff changeset
  1515
|| `::` || Like above, except the two colons will not be written. ||
1717
e0911cd9bd82 LuaAPI: Fix wrong claims about escape sequences
Wuzzy
parents: 1716
diff changeset
  1516
|| `\|` || Will be replaced with “|” without triggering a line break (escape sequence) ||
e0911cd9bd82 LuaAPI: Fix wrong claims about escape sequences
Wuzzy
parents: 1716
diff changeset
  1517
|| `\:` || Will be replaced with “:” without triggering highlighting (escape sequence) ||
645
f161ad0b976d Explain all arguments of ShowMission
Wuzzy
parents: 638
diff changeset
  1518
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1519
`icon` accepts the following values:
79
64fc6cee4af7 Added a note on the new icons for ShowMission
RedGrinner
parents: 78
diff changeset
  1520
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1521
|| *`icon`* || *What is shown* ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1522
|| _negative number_ || Icon of an ammo type. It is specified as the negative of an ammo type constant (see [AmmoTypes]), i.e. `-amBazooka` for the bazooka icon. ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1523
|| `0` || Golden crown ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1524
|| `1` || Target ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1525
|| `2` || Exclamation mark ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1526
|| `3` || Question mark ||
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1527
|| `4` || Golden star ||
636
55b08e9ee152 Update ShowMission icons
Wuzzy
parents: 630
diff changeset
  1528
|| `5` || Utility crate ||
55b08e9ee152 Update ShowMission icons
Wuzzy
parents: 630
diff changeset
  1529
|| `6` || Health crate ||
55b08e9ee152 Update ShowMission icons
Wuzzy
parents: 630
diff changeset
  1530
|| `7` || Ammo crate ||
55b08e9ee152 Update ShowMission icons
Wuzzy
parents: 630
diff changeset
  1531
|| `8` || Barrel ||
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1532
|| `9` || Dud mine ||
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
  1533
1644
009208830d85 LuaAPI: Add forceDisplay to ShowMission
Wuzzy
parents: 1643
diff changeset
  1534
If the optional parameter `forceDisplay` is `true`, this mission panel cannot be removed manually by the player. It's `false` by default.
009208830d85 LuaAPI: Add forceDisplay to ShowMission
Wuzzy
parents: 1643
diff changeset
  1535
645
f161ad0b976d Explain all arguments of ShowMission
Wuzzy
parents: 638
diff changeset
  1536
Example:
f161ad0b976d Explain all arguments of ShowMission
Wuzzy
parents: 638
diff changeset
  1537
<code language="lua">
f161ad0b976d Explain all arguments of ShowMission
Wuzzy
parents: 638
diff changeset
  1538
ShowMission(loc("Nobody Laugh"), loc("User Challenge"), loc("Eliminate the enemy before the time runs out"), 0, 0)
f161ad0b976d Explain all arguments of ShowMission
Wuzzy
parents: 638
diff changeset
  1539
</code>
f161ad0b976d Explain all arguments of ShowMission
Wuzzy
parents: 638
diff changeset
  1540
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
  1541
=== <tt>!HideMission()</tt> ===
894
aa3027b760bb LuaAPI: Better ShowMission/HideMission texts
Wuzzy
parents: 893
diff changeset
  1542
Hides the mission panel if it is currently displayed, otherwise, this function does nothing.
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
  1543
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1544
=== <tt>!SetZoom(zoomLevel)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1545
Sets the zoom level. The value for maximum zoom is currently 1.0 and for minimum 3.0 The default zoom level is 2.0
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
  1546
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1547
=== <tt>!GetZoom()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1548
Returns the current zoom level.
147
379d7931ffc7 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 146
diff changeset
  1549
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1550
=== <tt>!SetCinematicMode(enable)</tt> (0.9.23) ===
775
3a8c1121cca7 LuaAPI: SetCinematicMode
Wuzzy
parents: 741
diff changeset
  1551
Turns on or off cinematic mode. Cinematic mode can be used for cutscenes etc.
3a8c1121cca7 LuaAPI: SetCinematicMode
Wuzzy
parents: 741
diff changeset
  1552
If `enable` is set to `true`, cinematic mode is enabled,
3a8c1121cca7 LuaAPI: SetCinematicMode
Wuzzy
parents: 741
diff changeset
  1553
if it is `false`, cinematic mode is disabled.
3a8c1121cca7 LuaAPI: SetCinematicMode
Wuzzy
parents: 741
diff changeset
  1554
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1555
== Sound functions ==
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1556
=== <tt>!PlaySound(soundId, [gearUid [, instaVoice]])</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1557
Plays the specified sound. Possible values for `soundId` are listed on the [Sounds] page.
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
  1558
1258
0eeb688dd1cc LuaAPI: fix bracket
Wuzzy
parents: 1257
diff changeset
  1559
To play a voice (see [Taunts] for a list), you must also set `gearUid`. `gearUid` is the hedgehog gear which is used to “talk”.
1256
141ed1f83d56 LuaAPI: Add SetSoundMask, update PlaySound
Wuzzy
parents: 1254
diff changeset
  1560
1257
75747cc55f41 LuaAPI: Update PlaySound
Wuzzy
parents: 1256
diff changeset
  1561
If you play a voice, by default the voice will respect an internal queue and might be played with an delay in order to prevent annoying voice overlapping. Since version 0.9.24, you can disable this behaviour and force Hedgewars to instantly play the voice by also setting `instaVoice` to `true`. Only use `instaVoice` when you really need it.
1256
141ed1f83d56 LuaAPI: Add SetSoundMask, update PlaySound
Wuzzy
parents: 1254
diff changeset
  1562
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1563
=== <tt>!PlayMusicSound(soundId)</tt> (0.9.25) ===
1592
9d79881c31b1 LuaAPI: PlayMusicSound, StopMusicSound
Wuzzy
parents: 1579
diff changeset
  1564
Plays a sound as replacement for the background music. The sound is played once. The main music is paused and the sound is played instead. The main background music does not resume automatically, so you should call `StopMusicSound` after a while.
9d79881c31b1 LuaAPI: PlayMusicSound, StopMusicSound
Wuzzy
parents: 1579
diff changeset
  1565
9d79881c31b1 LuaAPI: PlayMusicSound, StopMusicSound
Wuzzy
parents: 1579
diff changeset
  1566
Example:
9d79881c31b1 LuaAPI: PlayMusicSound, StopMusicSound
Wuzzy
parents: 1579
diff changeset
  1567
<code language="lua">
9d79881c31b1 LuaAPI: PlayMusicSound, StopMusicSound
Wuzzy
parents: 1579
diff changeset
  1568
PlayMusicSound(sndRideOfTheValkyries) -- Replace the background music the Ride of the Valkyries
9d79881c31b1 LuaAPI: PlayMusicSound, StopMusicSound
Wuzzy
parents: 1579
diff changeset
  1569
</code>
9d79881c31b1 LuaAPI: PlayMusicSound, StopMusicSound
Wuzzy
parents: 1579
diff changeset
  1570
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1571
=== <tt>!StopMusicSound(soundId)</tt> (0.9.25) ===
1592
9d79881c31b1 LuaAPI: PlayMusicSound, StopMusicSound
Wuzzy
parents: 1579
diff changeset
  1572
Stops the specified “music sound” (if it was still playing) and resumes the main background music.
9d79881c31b1 LuaAPI: PlayMusicSound, StopMusicSound
Wuzzy
parents: 1579
diff changeset
  1573
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1574
=== <tt>!SetSoundMask(soundId, isMasked)</tt> (0.9.24) ===
1256
141ed1f83d56 LuaAPI: Add SetSoundMask, update PlaySound
Wuzzy
parents: 1254
diff changeset
  1575
Disables a given sound (including taunts) from being played by the engine. `soundId` is a valid sound ID on [Sounds] or [Taunts]. `isMasked` is a boolean. If `true`, the sound will not be played by the engine anymore. If `false`, playing this sound is allowed again.
70
ff7d4c176303 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 69
diff changeset
  1576
1256
141ed1f83d56 LuaAPI: Add SetSoundMask, update PlaySound
Wuzzy
parents: 1254
diff changeset
  1577
Sounds played by the Lua function `PlaySound` will always work, however, and ignore the sound mask.
141ed1f83d56 LuaAPI: Add SetSoundMask, update PlaySound
Wuzzy
parents: 1254
diff changeset
  1578
141ed1f83d56 LuaAPI: Add SetSoundMask, update PlaySound
Wuzzy
parents: 1254
diff changeset
  1579
Note: Due to the way the voices work internally in Hedgewars, if you want to play a masked voice, you have to set `instaVoice` to `true` when you call `PlaySound`. Otherwise, it won't work.
141ed1f83d56 LuaAPI: Add SetSoundMask, update PlaySound
Wuzzy
parents: 1254
diff changeset
  1580
141ed1f83d56 LuaAPI: Add SetSoundMask, update PlaySound
Wuzzy
parents: 1254
diff changeset
  1581
Example:
141ed1f83d56 LuaAPI: Add SetSoundMask, update PlaySound
Wuzzy
parents: 1254
diff changeset
  1582
141ed1f83d56 LuaAPI: Add SetSoundMask, update PlaySound
Wuzzy
parents: 1254
diff changeset
  1583
<code language="lua">SetSoundMask(sndIncoming, true)
141ed1f83d56 LuaAPI: Add SetSoundMask, update PlaySound
Wuzzy
parents: 1254
diff changeset
  1584
-- Disable the “Incoming” sound from being played</code>
77
588f5dc682e2 Added SetInputMask function
RedGrinner
parents: 76
diff changeset
  1585
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1586
== File system functions ==
1699
4eea5f6707d9 LuaAPI: add space in header
Wuzzy
parents: 1697
diff changeset
  1587
=== <tt>!HedgewarsScriptLoad(scriptPath [, mustExist])</tt> ===
1641
e3ba8cad19d5 LuaAPI: Update HedgewarsScriptLoad
Wuzzy
parents: 1640
diff changeset
  1588
Loads a script (i.e. a [LuaLibraries library]) from the specified `scriptPath`. The root directory is here Hedgewars’ data directory. There will be a Lua error if the script does not exist.
e3ba8cad19d5 LuaAPI: Update HedgewarsScriptLoad
Wuzzy
parents: 1640
diff changeset
  1589
e3ba8cad19d5 LuaAPI: Update HedgewarsScriptLoad
Wuzzy
parents: 1640
diff changeset
  1590
If `mustExist` is `false`, no Lua error will happen even when the script does not exist.
e3ba8cad19d5 LuaAPI: Update HedgewarsScriptLoad
Wuzzy
parents: 1640
diff changeset
  1591
e3ba8cad19d5 LuaAPI: Update HedgewarsScriptLoad
Wuzzy
parents: 1640
diff changeset
  1592
Returns `true` if the script was loaded successfully, `false` otherwise.
407
36537eaf680c Add HedgewarsScriptLoad
almikes@aol.com
parents: 406
diff changeset
  1593
36537eaf680c Add HedgewarsScriptLoad
almikes@aol.com
parents: 406
diff changeset
  1594
Example:
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
  1595
<code language="lua">
407
36537eaf680c Add HedgewarsScriptLoad
almikes@aol.com
parents: 406
diff changeset
  1596
HedgewarsScriptLoad("/Scripts/Locale.lua")  -- loads locale library
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
  1597
</code>
407
36537eaf680c Add HedgewarsScriptLoad
almikes@aol.com
parents: 406
diff changeset
  1598
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1599
== Stats functions ==
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1600
=== <tt>!SendStat(TStatInfoType, statMessage[, teamName])</tt> ===
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1601
893
e8664c10f69b LuaAPI: Better description of SendStat
Wuzzy
parents: 892
diff changeset
  1602
This function allows to change the details of the stats screen seen after the end of a game.
418
a7d34a3e5786 Make documentation for SendStat much more readable: Add a table (still not perfect), added some basic parameter descriptions.
almikes@aol.com
parents: 417
diff changeset
  1603
a7d34a3e5786 Make documentation for SendStat much more readable: Add a table (still not perfect), added some basic parameter descriptions.
almikes@aol.com
parents: 417
diff changeset
  1604
`TStatInfoType` is the piece of information you want to manipulate. The result of this functions varies greatly for different `TStatInfoType`s. The parameter `statMessage` is mandatory and is a string used for the statistics, its meaning depends on the `TStatInfoType`. The parameter `teamName` contains the name of a team which is relevant to the chosen stat. This parameter is not always required, this also depends on `TStatInfoType`.
a7d34a3e5786 Make documentation for SendStat much more readable: Add a table (still not perfect), added some basic parameter descriptions.
almikes@aol.com
parents: 417
diff changeset
  1605
a7d34a3e5786 Make documentation for SendStat much more readable: Add a table (still not perfect), added some basic parameter descriptions.
almikes@aol.com
parents: 417
diff changeset
  1606
This tables explains the different behaviours of this function for different values of `TStatInfoType`:
a7d34a3e5786 Make documentation for SendStat much more readable: Add a table (still not perfect), added some basic parameter descriptions.
almikes@aol.com
parents: 417
diff changeset
  1607
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1608
|| *`TStatInfoType`* || *Meaning of `statMessage`* || *Team parameter used?* ||
418
a7d34a3e5786 Make documentation for SendStat much more readable: Add a table (still not perfect), added some basic parameter descriptions.
almikes@aol.com
parents: 417
diff changeset
  1609
|| `siGraphTitle` || Title of the graph. If you use this, the health icon changes into a star. || No ||
a7d34a3e5786 Make documentation for SendStat much more readable: Add a table (still not perfect), added some basic parameter descriptions.
almikes@aol.com
parents: 417
diff changeset
  1610
|| `siGameResult` || Title of the stats screen, used to show the result of the game, i.e. who won the game || No ||
a7d34a3e5786 Make documentation for SendStat much more readable: Add a table (still not perfect), added some basic parameter descriptions.
almikes@aol.com
parents: 417
diff changeset
  1611
|| `siCustomAchievement` || A freeform text for a single “bullet point” in the “bullet point” list in the details section. For each time you call `SendStat` with this `TStatInfoType`, a new “bullet point” gets added to the list. || No ||
685
06cd9e0842e4 Clarify siPointType usage
Wuzzy
parents: 650
diff changeset
  1612
|| `siPointType` || Replaces the word “kills” in the ranking list. You have to call this each time before you report the score or kills of a team with `siPlayerKills`. Sadly, grammatical number is currently not respected at all here. || No ||
1538
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1613
|| `siPlayerKills` || Adds a team into the ranking with the given number of kills. The order in which this is called for each team matters. Unless the word “kills” has been replaced by `siPointType`, then that word is used instead. Only integers (converted to string) are possible. || Yes ||
1265
06c10a954ff2 LuaAPI: Update siClanHealth help
Wuzzy
parents: 1260
diff changeset
  1614
|| `siClanHealth` || Value of a data point. This sets a single data point on the graph for the specified team. All teams will be converted to clans prior to drawing, there can only be one chart per clan. Subsequent calls will draw the next point along the horizontal axis; the frontend will then simply connect the dots in the final chart. Only whole numbers are supported. There must be at least 2 data points for any given clan, otherwise there won't be much to look at. ;-) You also should have called `SendHealthStatsOff` if to prevent the default health graphs to be drawn. || Yes ||
1534
38fa37ffb915 LuaAPI: Fix inconsistent vars for SendStat
Wuzzy
parents: 1533
diff changeset
  1615
|| `siMaxStepKills` || Most hedgehogs killed in a round. `statMessage` must be in format “`<kills> <name of killer hedgehog> (<team name of killer>)`”. || No ||
38fa37ffb915 LuaAPI: Fix inconsistent vars for SendStat
Wuzzy
parents: 1533
diff changeset
  1616
|| `siMaxTeamDamage` || Team with most damage inflicted to self. `statMessage` must be in the format “`<damage> <team name>`”. || No ||
418
a7d34a3e5786 Make documentation for SendStat much more readable: Add a table (still not perfect), added some basic parameter descriptions.
almikes@aol.com
parents: 417
diff changeset
  1617
|| `siKilledHHs` || Total number of killed hedgehogs (converted to string). || No ||
1537
9e6138eb93da LuaAPI: warn that siTeamStats is *really* useles
Wuzzy
parents: 1536
diff changeset
  1618
|| `siTeamStats` || This does not have an effect. || No ||
1534
38fa37ffb915 LuaAPI: Fix inconsistent vars for SendStat
Wuzzy
parents: 1533
diff changeset
  1619
|| `siMaxStepDamage` || Most damage in one turn for the “best shot award”. `statMessage` must be in format “`<damage> <hedgehog name> (<team name>)`”. || No ||
38fa37ffb915 LuaAPI: Fix inconsistent vars for SendStat
Wuzzy
parents: 1533
diff changeset
  1620
|| `siMaxTurnSkips` || Team with most skips. `statMessage` must be of format “`<number> <teamName>`”. || No ||
1702
e9a2b9e33060 LuaAPI: Fix minor typo
Wuzzy
parents: 1700
diff changeset
  1621
|| `siTeamRank` || Overwrite rank of team. `statMessage` is the rank of your choice. Must be sent before `siPlayerKills` of the team in question. || No ||
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1622
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1623
<b>Examples:</b>
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1624
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
  1625
<code language="lua">
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1626
-- will automatically change the health icon to a star
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1627
SendStat(siGraphTitle,'Custom Graph Title')
1533
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1628
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1629
SendStat(siGameResult,'Winner is Team A!')
1533
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1630
418
a7d34a3e5786 Make documentation for SendStat much more readable: Add a table (still not perfect), added some basic parameter descriptions.
almikes@aol.com
parents: 417
diff changeset
  1631
SendStat(siCustomAchievement,'This is a custom message posted in the Details section!')
1533
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1632
1538
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1633
-- Adds 3 teams into the ranking: First, Team A (with 3 kills), then Team B (1 kill) and then Team C (5 kills).
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1634
SendStat(siPlayerKills, "3", 'Team A')
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1635
SendStat(siPlayerKills, "1", 'Team B')
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1636
SendStat(siPlayerKills, "5", 'Team C')
1533
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1637
1538
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1638
-- In the next ranking, this changes the word “kills” to “points”,
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1639
-- call it just before sending kills/score for each team
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1640
-- in case you want to change the word i.e. print “point” or “points”
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1641
SendStat(siPointType, "points")
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1642
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1643
-- this will add Team D to the ranking and show “3 points“ in brackets (because of the siPointType above)
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1644
SendStat(siPlayerKills, "3", "Team D")
1533
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1645
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1646
-- call siClanHealth to send the "value" of a clan that will be used for the graph creation
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1647
-- a good idea is to call it always for every hog by using the runOnGears(function)
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1648
-- in normal mode "value" represents clan health
1538
1fa7f4048719 LuaAPI: Improve examples for siPlayerKills
Wuzzy
parents: 1537
diff changeset
  1649
SendStat(siClanHealth, "100", "teamName")
1533
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1650
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1651
-- most hedgehogs killed in a round (hedgehogName is who killed them)
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1652
SendStat(siMaxStepKills, "1 hedgehogName (teamName)")
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1653
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1654
-- team with most damage inflicted to self
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1655
SendStat(siMaxTeamDamage, "100 teamName")
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1656
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1657
-- total number of killed hedgehogs
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1658
SendStat(siKilledHHs, "1")
1533
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1659
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1660
-- best shot award
1533
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1661
SendStat(siMaxStepDamage, "30 hedgehogName (teamName)")
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1662
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1663
-- team with most kills of own hedgehogs
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1664
SendStat(siMaxStepDamage, "2 teamName")
1533
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1665
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1666
-- team with most skips
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1667
SendStat(siMaxTurnSkips, "3 teamName")
1533
9faad9be6e0e LuaAPI: Fix explanation of siMaxTeamDamage
Wuzzy
parents: 1532
diff changeset
  1668
1645
35f6bcebe525 LuaAPI: Add siTeamRank
Wuzzy
parents: 1644
diff changeset
  1669
-- set 15 kills for team "MyTeam" and overwrite its rank to 3
35f6bcebe525 LuaAPI: Add siTeamRank
Wuzzy
parents: 1644
diff changeset
  1670
SendStat(siPlayerKills, "15", "MyTeam")
35f6bcebe525 LuaAPI: Add siTeamRank
Wuzzy
parents: 1644
diff changeset
  1671
SendStat(siTeamRank, "3")
35f6bcebe525 LuaAPI: Add siTeamRank
Wuzzy
parents: 1644
diff changeset
  1672
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1673
</code>
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1674
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1675
<b>Important:</b>
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1676
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1677
  * As the game engine send stats to the frontend at the end of the game one should send her stats when the game is going to finish and right before the call of `EndGame()`. (Note: Stats are sent from the engine in `CheckForWin`. If conditions are met (win or draw) then `SendStats(uStats)` is called.)
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1678
  * Calling just `EndGame()` won’t produce any stats.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1679
  * If one would like to produce a custom graph see also `SendHealthStatsOff()`.
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1680
1232
4ac63a5c0184 LuaAPI: Remove most pre-0.9.23 version number mentions as very old
Wuzzy
parents: 1231
diff changeset
  1681
=== <tt>!SendHealthStatsOff()</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1682
Prevents the engine of sending health stats to the frontend. 
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1683
996
9d49deef533c LuaAPI: Add SendRankingStatsOff, SendAchievementsStatsOff, SendGameResultOff
Wuzzy
parents: 993
diff changeset
  1684
If any health stats haven’t been sent before this will cause the health graph to the stats page to be hidden. Use this function in the Lua scripts to produce custom graphs by calling it inside `onGameStart()` and using the `SendStat()` function.
1535
9f33e3eb9798 LuaAPI: Fix very misleading description of siTeamStats
Wuzzy
parents: 1534
diff changeset
  1685
f
996
9d49deef533c LuaAPI: Add SendRankingStatsOff, SendAchievementsStatsOff, SendGameResultOff
Wuzzy
parents: 993
diff changeset
  1686
=== <tt>!SendAchievementsStatsOff()</tt> (0.9.23) ===
9d49deef533c LuaAPI: Add SendRankingStatsOff, SendAchievementsStatsOff, SendGameResultOff
Wuzzy
parents: 993
diff changeset
  1687
Prevents the engine of populating the snarky comments in the “Details” section (internally known as “achievements”) of the stats screen, such as “best shot award”, etc. So you can start with a clean list when the game ends normally. This function needs to be called inside `onGameStart()`.
9d49deef533c LuaAPI: Add SendRankingStatsOff, SendAchievementsStatsOff, SendGameResultOff
Wuzzy
parents: 993
diff changeset
  1688
9d49deef533c LuaAPI: Add SendRankingStatsOff, SendAchievementsStatsOff, SendGameResultOff
Wuzzy
parents: 993
diff changeset
  1689
=== <tt>!SendRankingStatsOff()</tt> (0.9.23) ===
9d49deef533c LuaAPI: Add SendRankingStatsOff, SendAchievementsStatsOff, SendGameResultOff
Wuzzy
parents: 993
diff changeset
  1690
Prevents the engine of populating the team rankings in the stats screen, so you can start with a clean list when the game ends normally. This function needs to be called inside `onGameStart()`.
9d49deef533c LuaAPI: Add SendRankingStatsOff, SendAchievementsStatsOff, SendGameResultOff
Wuzzy
parents: 993
diff changeset
  1691
9d49deef533c LuaAPI: Add SendRankingStatsOff, SendAchievementsStatsOff, SendGameResultOff
Wuzzy
parents: 993
diff changeset
  1692
=== <tt>!SendGameResultOff()</tt> (0.9.23) ===
9d49deef533c LuaAPI: Add SendRankingStatsOff, SendAchievementsStatsOff, SendGameResultOff
Wuzzy
parents: 993
diff changeset
  1693
Prevents the engine of setting the game result text at the top of the stats screen, e.g. “Team 1 wins!” when the game ends normally. This function needs to be called inside `onGameStart()`.
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1694
1040
291ce8641578 LuaAPI: GetTeamStats
Wuzzy
parents: 1039
diff changeset
  1695
=== <tt>!GetTeamStats(teamname)</tt> (0.9.23) ===
291ce8641578 LuaAPI: GetTeamStats
Wuzzy
parents: 1039
diff changeset
  1696
Returns a table of internal stats of a team. This table has the following fields:
291ce8641578 LuaAPI: GetTeamStats
Wuzzy
parents: 1039
diff changeset
  1697
1211
b228006249f8 LuaAPI: fix typo in getteamstats
Wuzzy
parents: 1191
diff changeset
  1698
 * `Kills`: Number of kills
b228006249f8 LuaAPI: fix typo in getteamstats
Wuzzy
parents: 1191
diff changeset
  1699
 * `Suicides`: Number of suicides (not yet working)
b228006249f8 LuaAPI: fix typo in getteamstats
Wuzzy
parents: 1191
diff changeset
  1700
 * `AIKills`: Number of AI kills
b228006249f8 LuaAPI: fix typo in getteamstats
Wuzzy
parents: 1191
diff changeset
  1701
 * `TeamKills`: Number of hedgehogs killes in own team (excluding current hedghog)
b228006249f8 LuaAPI: fix typo in getteamstats
Wuzzy
parents: 1191
diff changeset
  1702
 * `TurnSkips`: Number of skipped turns
b228006249f8 LuaAPI: fix typo in getteamstats
Wuzzy
parents: 1191
diff changeset
  1703
 * `TeamDamage`: Damage inflicted to own team (excluding current hedgehog)
1040
291ce8641578 LuaAPI: GetTeamStats
Wuzzy
parents: 1039
diff changeset
  1704
382
5b90c6ef1f62 add div()
sheepyluva@gmail.com
parents: 381
diff changeset
  1705
== Math Functions ==
5b90c6ef1f62 add div()
sheepyluva@gmail.com
parents: 381
diff changeset
  1706
383
6679b75048c0 I really have to get used to using preview on google code wiki...
sheepyluva@gmail.com
parents: 382
diff changeset
  1707
=== <tt>div(dividend, divisor)</tt> ===
515
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1708
Performs an integer division and returns the result.
8e9d86efc07b Copy-editing of the entire page. Also a few updates to some fairly out-dated information while I’m at it.
almikes@aol.com
parents: 505
diff changeset
  1709
The result is an integer and has the value of the first parameter (an integer) divided by the second parameter (another integer), rounded towards zero.
382
5b90c6ef1f62 add div()
sheepyluva@gmail.com
parents: 381
diff changeset
  1710
401
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1711
=== <tt>band(value1, value2)</tt> ===
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1712
Returns the bitwise logical AND of `value1` and `value2`.
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1713
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1714
=== <tt>bor(value1, value2)</tt> ===
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1715
Returns the bitwise logical OR of `value1` and `value2`.
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1716
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1717
=== <tt>bnot(value)</tt> ===
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1718
Returns the bitwise logical NOT of `value`.
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1719
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1720
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
  1721
== Debugging Functions ==
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1722
=== <tt>WriteLnToConsole(string)</tt> ===
820
cf7f4be0c083 LuaAPI: DumpPoint
Wuzzy
parents: 819
diff changeset
  1723
Writes `string` to `Logs/game0.log`, found in the user data directory.
cf7f4be0c083 LuaAPI: DumpPoint
Wuzzy
parents: 819
diff changeset
  1724
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1725
=== <tt>WriteLnToChat(string)</tt> (0.9.24) ===
1189
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1726
Writes `string` into the chat.
e69155e475c8 LuaAPI: Add 0.9.24 functions
Wuzzy
parents: 1188
diff changeset
  1727
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1728
=== <tt>DumpPoint(x, y)</tt> (0.9.23) ===
821
2bf17581d46b LuaAPI: DumpPoint 2
Wuzzy
parents: 820
diff changeset
  1729
Converts the whole numbers `x` and `y` to strings and writes them to `Logs/game0.log`, one line each.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
  1730
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1731
=== <tt>StartGhostPoints(count)</tt> ===
1221
16391ff5e091 LuaAPI: Add StartGhostPoints
Wuzzy
parents: 1220
diff changeset
  1732
Just prints out “GHOST_POINTS” and the argument on the console. This function might change in later versions.
16391ff5e091 LuaAPI: Add StartGhostPoints
Wuzzy
parents: 1220
diff changeset
  1733
1656
a262e8d3380d LuaAPI: add more <tt> for function name captions
Wuzzy
parents: 1655
diff changeset
  1734
=== <tt>DeclareAchievement(id, teamname, location, value)</tt> ===
1225
64b95a681971 LuaAPI: Add onAchievementsDeclaration and DeclareAchievement
Wuzzy
parents: 1224
diff changeset
  1735
Declares an achievement with the identifier `id` achieved by the team `teamname` on the map `location` with an achievement value (e.g. score) of `value`. `value` must be an integer. You are supposed to call this function inside an `onAchievementsDeclaration` callback.
64b95a681971 LuaAPI: Add onAchievementsDeclaration and DeclareAchievement
Wuzzy
parents: 1224
diff changeset
  1736
64b95a681971 LuaAPI: Add onAchievementsDeclaration and DeclareAchievement
Wuzzy
parents: 1224
diff changeset
  1737
Currently, this actually just triggers a console output, but it might be changed later. The idea is to track multiplayer records.
64b95a681971 LuaAPI: Add onAchievementsDeclaration and DeclareAchievement
Wuzzy
parents: 1224
diff changeset
  1738
64b95a681971 LuaAPI: Add onAchievementsDeclaration and DeclareAchievement
Wuzzy
parents: 1224
diff changeset
  1739
Example:
64b95a681971 LuaAPI: Add onAchievementsDeclaration and DeclareAchievement
Wuzzy
parents: 1224
diff changeset
  1740
1231
550b1afc9300 LuaAPI: fix code syntax
Wuzzy
parents: 1230
diff changeset
  1741
<code language="lua">DeclareAchievement("height reached", teamname, "ClimbHome", -score)</code>
1225
64b95a681971 LuaAPI: Add onAchievementsDeclaration and DeclareAchievement
Wuzzy
parents: 1224
diff changeset
  1742
Records a team's best height in !ClimbHome.
64b95a681971 LuaAPI: Add onAchievementsDeclaration and DeclareAchievement
Wuzzy
parents: 1224
diff changeset
  1743
394
b2742eb19396 Edited wiki page LuaAPI through web abuser interface.
sheepyluva@gmail.com
parents: 384
diff changeset
  1744
=== <tt>!ParseCommand(string)</tt> ===
1046
1e19a1a5a450 LuaAPI: Update ParseCommand info
Wuzzy
parents: 1044
diff changeset
  1745
Makes the game client parse and execute the specified internal game engine command.
1e19a1a5a450 LuaAPI: Update ParseCommand info
Wuzzy
parents: 1044
diff changeset
  1746
1e19a1a5a450 LuaAPI: Update ParseCommand info
Wuzzy
parents: 1044
diff changeset
  1747
The available commands depend on the current engine protocol version. The *engine protocol can (and will) change* between releases.
1044
bc4dca5e6124 LuaAPI: Update ParseCommand help
Wuzzy
parents: 1043
diff changeset
  1748
1704
09694f0d4e90 LuaAPI: fix some asterisks
Wuzzy
parents: 1703
diff changeset
  1749
*Important*: If you use `ParseCommand` to overcome a shortcoming in our Lua API (e.g. a missing function), please make sure to [https://issues.hedgewars.org/enter_bug.cgi report the issue].
394
b2742eb19396 Edited wiki page LuaAPI through web abuser interface.
sheepyluva@gmail.com
parents: 384
diff changeset
  1750
1046
1e19a1a5a450 LuaAPI: Update ParseCommand info
Wuzzy
parents: 1044
diff changeset
  1751
With your report we can fix the shortcoming in future releases. We will try to remove the reliance on `ParseCommand` as good as possible. This will allow scripts to use the previously missing feature in a way that won’t break!
1e19a1a5a450 LuaAPI: Update ParseCommand info
Wuzzy
parents: 1044
diff changeset
  1752
1398
704301f9bd1d LuaAPI: Remove skip from ParseCommand
Wuzzy
parents: 1391
diff changeset
  1753
There are many available commands, but actual use in scripting is rare, and even then it's discouraged for long-term use. As of 0.9.24, the only command used in official scripts is:
394
b2742eb19396 Edited wiki page LuaAPI through web abuser interface.
sheepyluva@gmail.com
parents: 384
diff changeset
  1754
1074
98156a84cdd9 LuaAPI: fix typos
Wuzzy
parents: 1073
diff changeset
  1755
 * `"draw <map>"`: Draws a hand-drawn map. `MapGen` must be `mgDrawn` for this to work. `<map>` is a string which must follow the format specified in [DrawnMapFormat]
1044
bc4dca5e6124 LuaAPI: Update ParseCommand help
Wuzzy
parents: 1043
diff changeset
  1756
1057
19142f4d6fb4 LuaAPI: fix broken link
Wuzzy
parents: 1055
diff changeset
  1757
Moreover, the control action names as listed in [ConfigurationFiles] (under “Binds”) can be used. Note we will eventually try to remove all `ParseCommand`s in the official scripts.
1054
0de5837d0fc5 LuaAPI: Add EndLuaTest
Wuzzy
parents: 1046
diff changeset
  1758
0de5837d0fc5 LuaAPI: Add EndLuaTest
Wuzzy
parents: 1046
diff changeset
  1759
=== <tt>!EndLuaTest(success)</tt> ===
0de5837d0fc5 LuaAPI: Add EndLuaTest
Wuzzy
parents: 1046
diff changeset
  1760
This function is used by the Hedgewars developers in testing scripts in order to test the game engine. The testing scripts can be found in the Hedgewars source code under `tests/lua`. This function is useless for anything else.
0de5837d0fc5 LuaAPI: Add EndLuaTest
Wuzzy
parents: 1046
diff changeset
  1761
0de5837d0fc5 LuaAPI: Add EndLuaTest
Wuzzy
parents: 1046
diff changeset
  1762
Calling this function ends an engine test and reports a test result.
0de5837d0fc5 LuaAPI: Add EndLuaTest
Wuzzy
parents: 1046
diff changeset
  1763
1055
754e0a7bdd44 Explain briefly how engine testing works
Wuzzy <almikes@aol.com>
parents: 1054
diff changeset
  1764
`success` is either one of `TEST_SUCCESSFUL` to report a successful test or `TEST_FAILED` for a failed test.
754e0a7bdd44 Explain briefly how engine testing works
Wuzzy <almikes@aol.com>
parents: 1054
diff changeset
  1765
754e0a7bdd44 Explain briefly how engine testing works
Wuzzy <almikes@aol.com>
parents: 1054
diff changeset
  1766
See [EngineTestCases] to learn more about testing the engine.