LuaAPI.wiki
author Wuzzy
Thu, 10 Sep 2015 00:13:51 +0000
changeset 610 b5b545b29e6a
parent 608 9a49d69316f2
child 611 a1d30b3b866c
permissions -rw-r--r--
GetHogFlag, GetHogGrave, GetHogVoicepack
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
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
     4
== Introduction ==
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
     5
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
     6
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.
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
     7
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
     8
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
     9
519
b757c990bd5c Moved TOC a little bit further down.
almikes@aol.com
parents: 515
diff changeset
    10
=== About this wiki page ===
b757c990bd5c Moved TOC a little bit further down.
almikes@aol.com
parents: 515
diff changeset
    11
This page tends to 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
    12
519
b757c990bd5c Moved TOC a little bit further down.
almikes@aol.com
parents: 515
diff changeset
    13
<wiki:toc max_depth="4" />
b757c990bd5c Moved TOC a little bit further down.
almikes@aol.com
parents: 515
diff changeset
    14
b757c990bd5c Moved TOC a little bit further down.
almikes@aol.com
parents: 515
diff changeset
    15
== 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
    16
=== 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
    17
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
    18
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    19
=== 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
    20
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
    21
567
17cf8a0c007f Link to [Missions].
almikes@aol.com
parents: 564
diff changeset
    22
See [Missions] for details.
17cf8a0c007f Link to [Missions].
almikes@aol.com
parents: 564
diff changeset
    23
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    24
=== 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
    25
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
    26
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
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
    28
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    29
=== 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
    30
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
    31
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    32
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    33
=== 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
    34
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
    35
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
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
    37
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    38
=== 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
    39
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
    40
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    41
  	  	 
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
    42
=== 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
    43
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
    44
478
7b95addbe9fc Move “color” into new data types section.
almikes@aol.com
parents: 477
diff changeset
    45
== 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
    46
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
    47
478
7b95addbe9fc Move “color” into new data types section.
almikes@aol.com
parents: 477
diff changeset
    48
=== Color ===
477
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    49
Some functions take a `color` parameter.
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    50
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
    51
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
    52
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
    53
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
    54
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
    55
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    56
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
    57
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
    58
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
    59
<code language="lua">
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    60
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
    61
c = 0xFF0000 -- red
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    62
c = 0x00FF00 -- green
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    63
c = 0x0000FF -- blue
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    64
c = 0xFFFFFF -- white
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    65
c = 0x808080 -- gray (50%)</code>
8c326a00ead3 Add information about the “color” parameter found in some functions.
almikes@aol.com
parents: 476
diff changeset
    66
312
6c0397400a9b Add Smaxx' nice lua API introduction from the hedgewars.org wiki
sheepyluva@gmail.com
parents: 295
diff changeset
    67
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
    68
== 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
    69
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
    70
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    71
=== General 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
    72
Here are some unsorted variables or constants which are available in Lua. You shouldn’t write to most of them.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
    73
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
    74
|| *Identifier* || *Description* ||
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
|| `LAND_WIDTH` || The width of the landscape in pixels ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    76
|| `LAND_HEIGHT` || The height of the landscape in pixels ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    77
|| `WaterLine` || The y position of the water, used to determine at which position stuff drowns. Use `SetWaterLine` to change. ||
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
|| `ClansCount` || Number of clans in the game (teams with the same color belong to one clan) ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    79
|| `TeamsCount` || Number of teams in the game ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    80
|| `TurnTimeLeft` || Number of game ticks (milliseconds) left until the current turn ends. You can change this variable directly. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    81
|| `GameTime` || Number of total game ticks ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    82
|| `TotalRounds` || Number of rounds that have passed ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    83
|| `CurrentHedgehog` || The hedgehog gear that is currently in play ||
125
b0b7654c6de6 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 123
diff changeset
    84
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
    85
=== !GameFlags ===
557
7a25067aa32c fix link to gameflag functions
sheepyluva@gmail.com
parents: 556
diff changeset
    86
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
    87
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
    88
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
    89
|| *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
    90
|| `gfOneClanMode` || Used when only one clan is in the game. This game flag is primarily used for training missions. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    91
|| `gfMultiWeapon` || TODO (Used in training missions.) ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    92
|| `gfForts` || Fort Mode ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    93
|| `gfDivideTeams` || The teams will start at opposite sites of the terrain. Two clans maximum. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    94
|| `gfBorder` || An indestrctible border is active around the map. ||
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
|| `gfBottomBorder` || There is an indestructable border at the bottom of the map. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
    96
|| `gfShoppaBorder` || TODO ||
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
|| `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
    98
|| `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
    99
|| `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
   100
|| `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
   101
|| `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
   102
|| `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
   103
|| `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
   104
|| `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
   105
|| `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
   106
|| `gfKing` || King Mode: One hedgehog per team becomes their king, if the king dies, the team loses. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   107
|| `gfSharedAmmo` || Teams in the same clan share their ammo. ||
9079444264ae Update section “Global available constants”: Use tables, fix gameflags section (was outdated, some gameflags were missing).
almikes@aol.com
parents: 478
diff changeset
   108
|| `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
   109
|| `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
   110
|| `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
   111
|| `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
   112
|| `gfResetWeps` || The weapons will be reset to the initial state 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
   113
|| `gfPerHogAmmo` || Each hedgehog has its own weapon stash. ||
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
|| `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
   115
|| `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
   116
|| `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
   117
|| `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
   118
540
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   119
=== Land flags ===
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   120
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
   121
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   122
|| *Identifier* || *Meaning* ||
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   123
|| `lfIce` || Slippery terrain, hogs will slide on it. ||
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   124
|| `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
   125
|| `lfIndestructible` || Almost indestructible terrain, most weapons will not destroy it. ||
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   126
|| `lfNormal` || Normal destroyable terrain. Note that this is only actually the case when no other land flag is set. ||
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   127
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
   128
=== 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
   129
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
   130
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
   131
== Event handlers ==
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
   132
Lua scripts are supposed to _define_ these functions to do something. The functions are then _called_ by Hedgewars when a certain even has occoured.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   133
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   134
=== <tt>onGameInit()</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
   135
This function is called before the game loads its resources. One can modify various game variables here:
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   136
 * <tt>Seed = 0</tt> - sets the seed of the random number generator
410
c0367902bea7 Small formatting fixes.
almikes@aol.com
parents: 408
diff changeset
   137
 * <tt>!EnableGameFlags(gfSolidLand, gfArtillery)</tt> - sets the !GameFlags (just 2 of them in this example), see above for the available flags/
572
dd27ba1f54a6 Add GetAwayTime
almikes@aol.com
parents: 567
diff changeset
   138
 * <tt>Ready = 5000</tt> - the ready timer at the start of the round (in milliseconds)
dd27ba1f54a6 Add GetAwayTime
almikes@aol.com
parents: 567
diff changeset
   139
 * <tt>Delay = 0</tt> - delay between each round in ms
dd27ba1f54a6 Add GetAwayTime
almikes@aol.com
parents: 567
diff changeset
   140
 * <tt>!GetAwayTime = 100</tt> set the retreat time in percent
563
83ede97a33c6 Update MinesTime variable
almikes@aol.com
parents: 562
diff changeset
   141
 * <tt>!TurnTime = 60000</tt> - set the turn time in ms
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   142
 * <tt>!CaseFreq = 0</tt> - frequency of crate drops
22
af151755fd72 fix for auto-links
henrik.rostedt
parents: 21
diff changeset
   143
 * <tt>!HealthCaseProb = 35</tt> - chance of receiving a health crate
af151755fd72 fix for auto-links
henrik.rostedt
parents: 21
diff changeset
   144
 * <tt>!HealthCaseAmount = 25</tt> - amount of health in a health crate
21
e8bcd7c1ba3c updated with more options and flags
henrik.rostedt
parents: 17
diff changeset
   145
 * <tt>!DamagePercent = 100</tt> - percent of damage to inforce
23
5800c5aef9ca one more
henrik.rostedt
parents: 22
diff changeset
   146
 * <tt>!MinesNum = 0</tt> - number of mines being placed (before 0.9.14 !LandAdds)
563
83ede97a33c6 Update MinesTime variable
almikes@aol.com
parents: 562
diff changeset
   147
 * <tt>!MinesTime = 3000</tt> - time for a mine to explode from activated (in milliseconds), -1000 for random
21
e8bcd7c1ba3c updated with more options and flags
henrik.rostedt
parents: 17
diff changeset
   148
 * <tt>!MineDudPercent = 0</tt> - chance of mine being a dud
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   149
 * <tt>Explosives = 0</tt> - number of explosives being placed
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   150
 * <tt>!SuddenDeathTurns = 30</tt> - turns until sudden death begins
22
af151755fd72 fix for auto-links
henrik.rostedt
parents: 21
diff changeset
   151
 * <tt>!WaterRise = 47</tt> - height of water rise at sudden death in pixels
af151755fd72 fix for auto-links
henrik.rostedt
parents: 21
diff changeset
   152
 * <tt>!HealthDecrease = 5</tt> - amount of health decreased on sudden death
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   153
 * <tt>Map = "Bamboo"</tt> - the map being played
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   154
 * <tt>Theme = "Bamboo"</tt> - the theme to be used
412
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
   155
 * <tt>!MapGen</tt> - type of map generator. One of `mgRandom`, `mgMaze`, `mgPerlin`, `mgDrawn`.
87
315a93b441d4 Edited wiki page LuaAPI through web user interface.
henrik.rostedt@gmail.com
parents: 82
diff changeset
   156
 * <tt>Goals = "Jumping is disabled"</tt> - if you want to add info to the game mode dialog, use "|" to separate lines
573
aa505738aff0 TemplateFilter and TemplateNumber
almikes@aol.com
parents: 572
diff changeset
   157
 * <tt>!TemplateFilter</tt> - _unknown meaning_
aa505738aff0 TemplateFilter and TemplateNumber
almikes@aol.com
parents: 572
diff changeset
   158
 * <tt>!TemplateNumber</tt> - _unknown meaning_
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   159
412
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
   160
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
   161
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   162
=== <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
   163
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
   164
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   165
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
   166
505
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   167
=== <tt>onPreviewInit()</tt> (0.9.21) ===
461
168508caf60d Add onPreviewInit
almikes@aol.com
parents: 421
diff changeset
   168
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
   169
168508caf60d Add onPreviewInit
almikes@aol.com
parents: 421
diff changeset
   170
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
   171
505
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   172
=== <tt>onParameters()</tt> (0.9.21) ===
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   173
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
   174
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   175
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
   176
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   177
*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
   178
a79631e03c84 Add onParameters and ScriptParam
almikes@aol.com
parents: 503
diff changeset
   179
*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
   180
64
a651a8ab85d5 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 63
diff changeset
   181
=== <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
   182
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
   183
5f322c85c0e0 toss in onGameTick20 - this page needs more updating tho
kyberneticist@gmail.com
parents: 328
diff changeset
   184
=== <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
   185
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
   186
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   187
=== <tt>onNewTurn()</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
   188
This function calls at the start of every turn.
63
24004a9003ec Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 62
diff changeset
   189
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   190
=== <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
   191
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
   192
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   193
=== <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
   194
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
   195
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   196
=== <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
   197
This function is called when a gear is damaged.
55
ef26ff619aea Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 54
diff changeset
   198
ef26ff619aea Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 54
diff changeset
   199
Example:
ef26ff619aea Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 54
diff changeset
   200
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   201
<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
   202
        if (GetGearType(gear) == gtHedgehog) then
55
ef26ff619aea Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 54
diff changeset
   203
            -- 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
   204
            AddCaption(GetHogName(gear) .. ' took ' .. damage .. ' points of damage')
55
ef26ff619aea Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 54
diff changeset
   205
        end
ef26ff619aea Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 54
diff changeset
   206
    end</code>
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   207
=== <tt>onGearResurrect(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
   208
This function is called when a gear is resurrected. CPU Hogs will resurrect if the !GameFlag `gfAISurvival` is enabled. Alternatively, specific gears can have `heResurrectable` set to true via `SetEffect`.
44
bf53e635a2ac Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 43
diff changeset
   209
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   210
=== <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
   211
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
   212
203
08cc35ba4d34 Edited wiki page LuaAPI through web user interface.
kyberneticist@gmail.com
parents: 202
diff changeset
   213
=== <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
   214
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
   215
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
   216
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
   217
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
   218
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
   219
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
   220
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
   221
502
7bd6701bb077 Add onGearWaterSkip
almikes@aol.com
parents: 491
diff changeset
   222
=== <tt>onGearWaterSkip(gear)</tt> (0.9.21) ===
7bd6701bb077 Add onGearWaterSkip
almikes@aol.com
parents: 491
diff changeset
   223
This function is called when the gear `gear` skips over water.
7bd6701bb077 Add onGearWaterSkip
almikes@aol.com
parents: 491
diff changeset
   224
7bd6701bb077 Add onGearWaterSkip
almikes@aol.com
parents: 491
diff changeset
   225
=== <tt>onScreenResize()</tt> (0.9.16) ===
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
   226
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
   227
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
   228
=== <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
   229
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
   230
107
kyberneticist
parents: 102
diff changeset
   231
=== <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
   232
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
   233
107
kyberneticist
parents: 102
diff changeset
   234
=== <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
   235
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
   236
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
   237
=== <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
   238
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
   239
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
   240
=== <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
   241
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
   242
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
   243
=== <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
   244
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
   245
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
   246
=== <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
   247
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
   248
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
   249
=== <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
   250
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
   251
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   252
=== <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
   253
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
   254
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   255
=== <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
   256
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
   257
 
535
5cb76f048bd9 Update onHogAttack
almikes@aol.com
parents: 533
diff changeset
   258
=== <tt>onHogAttack(ammoType)</tt> ===
5cb76f048bd9 Update onHogAttack
almikes@aol.com
parents: 533
diff changeset
   259
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.
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   260
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   261
=== <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
   262
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
   263
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   264
=== <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
   265
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
   266
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   267
=== <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
   268
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
   269
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   270
=== <tt>onSetWeapon()</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
   271
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
   272
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   273
=== <tt>onSlot()</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
   274
This function is called when a weapon slot (row in the weapon menu) is selected.
175
2455fbbab5e8 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 174
diff changeset
   275
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   276
=== <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
   277
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
   278
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   279
=== <tt>onTaunt()</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 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
   281
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   282
=== <tt>onTimer()</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
   283
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
   284
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   285
=== <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
   286
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
   287
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   288
=== <tt>onHogHide()</tt> (0.9.16) ===
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
   289
This function is called when a hedgehog is hidden (removed from the map).
179
156e5fba2e2c Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 178
diff changeset
   290
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   291
=== <tt>onHogRestore()</tt> (0.9.16) ===
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 a hedgehog is restored (unhidden).
173
ef246592a16e Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 172
diff changeset
   293
411
dbb7937903a4 Add onSpritePlacement.
almikes@aol.com
parents: 410
diff changeset
   294
=== <tt>onSpritePlacement(spriteId, centerX, centerY)</tt> (0.9.21) ===
dbb7937903a4 Add onSpritePlacement.
almikes@aol.com
parents: 410
diff changeset
   295
This function is called when a [Sprites Sprite] has been placed.
dbb7937903a4 Add onSpritePlacement.
almikes@aol.com
parents: 410
diff changeset
   296
dbb7937903a4 Add onSpritePlacement.
almikes@aol.com
parents: 410
diff changeset
   297
`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
   298
402
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   299
=== <tt>onGirderPlacement(frameIdx, centerX, centerY)</tt> (0.9.21) ===
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   300
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
   301
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   302
`frameIdx` is an integer and declares the length and orientation of the girder:
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
   303
|| *`frameIdx`* || *Length* || *Orientation* ||
402
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   304
|| 0 || short || horizontal ||
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   305
|| 1 || short || decreasing right ||
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   306
|| 2 || short || vertical ||
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   307
|| 3 || short || increasing right ||
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   308
|| 4 || long || horizontal ||
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   309
|| 5 || long || decreasing right ||
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   310
|| 6 || long || vertical ||
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   311
|| 7 || long || increasing right ||
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   312
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   313
`centerX` and `centerY` are the coordinates of the girder’s center.
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   314
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   315
=== <tt>onRubberPlacement(frameIdx, centerX, centerY)</tt> (0.9.21) ===
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   316
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
   317
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   318
`frameIdx` is an integer which stands for the orientation of the rubber.
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   319
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
   320
|| *`frameIdx`* || *Orientation* ||
402
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   321
|| 0 || horizontal ||
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   322
|| 1 || decreasing right ||
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   323
|| 2 || vertical ||
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   324
|| 3 || increasing right ||
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   325
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   326
`centerX` and `centerY` are the coordinates of the rubber’s center.
1e7586c110f6 Documented 0.9.21 functions onGirderPlacement and onRubberPlacement.
almikes@aol.com
parents: 401
diff changeset
   327
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   328
== Functions for creating gears ==
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   329
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   330
=== <tt>!AddGear(x, y, gearType, state, dx, dy, timer)</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
   331
This creates a new gear at position x,y (measured from top left) of kind `gearType` (see [GearTypes Gear Types]). 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
   332
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   333
Example:
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   334
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   335
<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
   336
    FindPlace(gear, true, 0, LAND_WIDTH)</code>
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   337
359
pntanasis@gmail.com
parents: 347
diff changeset
   338
=== <tt>!AddVisualGear(x, y, visualGearType, state, critical)</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
This creates a new visual gear at position x,y (measured from top left) of kind `visualGearType` (see [VisualGearTypes Visual Gear Types]). The function returns the `uid` of the visual gear created.  Set `critical` to `true` if the visual gear is crucial to game play. Use `false` if it is just an effect, and can be skipped when in fast-forward mode (such as when joining a room). A critical visual gear will always be created, a non-critical one may fail. Most visual gears delete themselves. 
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   340
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   341
Example:
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   342
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   343
<code language="lua">  -- adds an non-critical explosion at position 1000,1000. Returns 0 if it was not created.
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   344
    vgear = AddVisualGear(1000, 1000, vgtExplosion, 0, false) 
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   345
</code>
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   346
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   347
=== <tt>!SpawnHealthCrate(x, y)</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
   348
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).
f4b7962d39cd Better documentation about the special coordinates x=0, y=0 for the crate spawn functions.
almikes@aol.com
parents: 416
diff changeset
   349
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   350
=== <tt>!SpawnAmmoCrate(x, y, ammoType)</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
   351
Spawns an ammo crate at the specified position with content of ammoType (see [AmmoTypes Ammo Types]). If `x` and `y` are set to 0, the crate will spawn on a random position (but always on land).
564
c002f49283c6 Add SetAmmoDelay
almikes@aol.com
parents: 563
diff changeset
   352
Because by default settings the number of ammo in crates is zero it has to be increased to at least one 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
   353
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   354
Example:
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   355
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   356
<code language="lua">    SetAmmo(amGrenade, 0, 0, 0, 1) -- see below
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   357
    SpawnAmmoCrate(0, 0, amGrenade) -- x=y=0 means random position on map</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
   358
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   359
=== <tt>!SpawnUtilityCrate(x, y, ammoType)</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
   360
Spawns an utility crate at specified position with content of ammoType. If `x` and `y` are set to 0, the crate will spawn on a random position (but always on land).
f4b7962d39cd Better documentation about the special coordinates x=0, y=0 for the crate spawn functions.
almikes@aol.com
parents: 416
diff changeset
   361
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   362
Example:
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   363
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   364
<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
   365
    SpawnUtilityCrate(0, 0, amLaserSight)</code>
400
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   366
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   367
=== <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
   368
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
   369
`explode` and `poison` are booleans.
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   370
If `explode` is `true`, the crate will explode when collected.
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   371
If `poison` is `true`, the collector will be poisoned.
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   372
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   373
Example:
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   374
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   375
<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
   376
</code>
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   377
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   378
=== <tt>!SpawnFakeHealthCrate(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
   379
Spawns a crate at the specified coordinates which looks exactly like a real health crate but it will not heal the player. 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
   380
`explode` and `poison` are booleans.
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   381
If `explode` is `true`, the crate will explode when collected.
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   382
If `poison` is `true`, the collector will be poisoned.
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   383
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   384
=== <tt>!SpawnFakeUtilityCrate(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
   385
Spawns a crate at the specified coordinates which looks exactly like a real utility 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
   386
`explode` and `poison` are booleans.
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   387
If `explode` is `true`, the crate will explode when collected.
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   388
If `poison` is `true`, the collector will be poisoned.
0b7f8aed3c5e Documented the following functions:
almikes@aol.com
parents: 398
diff changeset
   389
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   390
=== <tt>!AddHog(hogname, botlevel, health, hat)</tt> ===
413
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
   391
Adds a new hedgehog for current team (last created one with the `AddTeam` function), with bot level and specified health, also hat.
556
e57188e7bc3b Better explanation of botlevel (AddHog argument).
almikes@aol.com
parents: 555
diff changeset
   392
`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.
413
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
   393
556
e57188e7bc3b Better explanation of botlevel (AddHog argument).
almikes@aol.com
parents: 555
diff changeset
   394
*Warning*: This works only for singleplayers training missions for now and will desync multiplayer games.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   395
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   396
Example:
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   397
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   398
<code language="lua">    local player = AddHog("HH 1", 0, 100, "NoHat") -- botlevel 0 means human player
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   399
    SetGearPosition(player, 1500, 1000)</code>
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   400
== Functions to get gear properties ==
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   401
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   402
=== <tt>!GetGearType(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
   403
This function returns one of [GearTypes Gear Types] for the specified gear.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   404
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   405
=== <tt>!GetGearPosition(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
   406
Returns x,y coordinates for the specified gear.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   407
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   408
=== <tt>!GetGearRadius(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
   409
Returns radius for the specified gear.
148
f343b50d5619 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 147
diff changeset
   410
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   411
=== <tt>!GetGearVelocity(gearUid)</tt> ===
555
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   412
Returns a tuple of dx,dy values for the specified gear.
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   413
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   414
=== <tt>!GetFlightTime(gearUid)</tt> ===
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   415
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
   416
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   417
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
   418
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   419
=== <tt>!GetGearElasticity(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
   420
Returns the elasticity of the specified gear. 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 non-zero.
74
6130cad02b02 Added GetGearElasticity
RedGrinner
parents: 73
diff changeset
   421
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   422
=== <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
   423
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
   424
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
   425
=== <tt>!GetHogTeamName(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
   426
Returns the name of the specified hedgehog gear’s team.
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
   427
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   428
=== <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
   429
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
   430
140
04d82b673bc4 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 139
diff changeset
   431
=== <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
   432
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
   433
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
   434
See `SetEffect` for further details.
373
0f9322acd00a update GetEffect/SetEffect info
sheepyluva@gmail.com
parents: 369
diff changeset
   435
133
b737ccb5b49a Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 132
diff changeset
   436
=== <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
   437
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
   438
610
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   439
=== <tt>!GetHogFlag(gearUid)</tt> (0.9.22) ===
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   440
Returns the name of the flag of the team of the specified hedgehog gear.
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   441
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   442
=== <tt>!GetHogGrave(gearUid)</tt> (0.9.22) ===
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   443
Returns the name of the grave of the team of the specified hedgehog gear.
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   444
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   445
=== <tt>!GetHogVoicepack(gearUid)</tt> (0.9.22) ===
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   446
Returns the name of the voicepack of the team of the specified hedgehog gear.
b5b545b29e6a GetHogFlag, GetHogGrave, GetHogVoicepack
Wuzzy
parents: 608
diff changeset
   447
141
b10bef9ac535 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 140
diff changeset
   448
=== <tt>!GetAmmoCount(gearUid, ammoType) (0.9.16)</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
   449
Returns the ammo count of the specified ammo type for the specified hedgehog gear.
133
b737ccb5b49a Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 132
diff changeset
   450
138
9ca80a93aae0 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 137
diff changeset
   451
=== <tt>!GetGearTarget(gearUid, x, y)  (0.9.16)</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
   452
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
   453
<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
   454
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
   455
=== <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
   456
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
   457
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
   458
=== <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
   459
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
   460
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   461
=== <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
   462
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
   463
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   464
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
   465
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   466
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
   467
<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
   468
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
   469
--[[ 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
   470
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
   471
</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
   472
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   473
<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
   474
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
   475
--[[ 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
   476
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
   477
“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
   478
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
   479
</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
   480
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   481
<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
   482
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
   483
--[[ 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
   484
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
   485
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
   486
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
   487
</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
   488
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   489
114
e311af715b57 Edited wiki page LuaAPI through web user interface.
henrik.rostedt@gmail.com
parents: 107
diff changeset
   490
=== <tt>!GetGearMessage(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
   491
Returns the message of the gear.
419
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   492
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   493
=== <tt>!GetTag(gearUid)</tt> ===
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   494
Returns the tag of the specified gear (by `gearUid`). 
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   495
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   496
A “tag” 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. `tag` has to be an integer.
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   497
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   498
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
   499
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   500
<code language="lua">
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   501
-- This adds a ball (the one from the ballgun) at (123, 456):
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   502
ball = AddGear(123, 456, gtBall, 0, 0, 0, 0)
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   503
-- 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
   504
colorTag = GetTag(ball)
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   505
-- 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
   506
</code>
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   507
421
d584704354ad Add link to GearTypes for SetTag and GetTag.
almikes@aol.com
parents: 419
diff changeset
   508
The meaning of tags are described in [GearTypes].
419
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   509
209
26805ae2a319 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 203
diff changeset
   510
=== <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
   511
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
   512
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   513
=== <tt>!GetTimer(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
   514
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 rcplane time.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   515
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   516
=== <tt>!GetHealth(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
   517
Returns the health of the gear.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   518
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   519
=== <tt>!GetHogLevel(gearUid)</tt> ===
576
dff03a98693a Clarified bot levels in GetHogLevel
almikes@aol.com
parents: 573
diff changeset
   520
Returns the bot level ranging from `0` to `5`. `1` is the strongest bot level and `5` is the weakest one. `0` is for human player.
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   521
503
87a36ae53518 Add GetGearPos
almikes@aol.com
parents: 502
diff changeset
   522
=== <tt>!GetGearPos(gearUid)</tt> ===
87a36ae53518 Add GetGearPos
almikes@aol.com
parents: 502
diff changeset
   523
Get pos of specified gear.
87a36ae53518 Add GetGearPos
almikes@aol.com
parents: 502
diff changeset
   524
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   525
=== <tt>!GetVisualGearValues(vgUid)</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
   526
This returns the typically set visual gear values, useful if manipulating things like smoke or bubbles or circles. It returns the following values:
552
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   527
X, Y, dX, dY, Angle, Frame, !FrameTicks, State, Timer, Tint 
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   528
X, Y typically position, dX, dY typically speed, Angle is usually the rotation angle, Frame is typically the animation frame, !FrameTicks is usually an animation counter.  State can have a variety of values, but is typically bit packed, Timer is usually the gear lifetime and Tint is the colour.
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   529
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
   530
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   531
Example:
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   532
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   533
<code language="lua">    GetVisualGearValues(vgUid) -- return visual gear values
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   534
</code>
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   535
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   536
== Functions to modify gears ==
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   537
243
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   538
=== <tt>!HideHog(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
   539
Removes a hedgehog from the map. The hidden hedgehog can be restored with `RestoreHog(gearUid)`. The current hedgehog cannot be hidden!
243
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   540
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   541
Example: 
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   542
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   543
<code language="lua">    gear = AddGear(...)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   544
     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
   545
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   546
=== <tt>!RestoreHog(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
   547
Restores a previously hidden hedgehog.
243
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   548
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   549
Example: 
ac34d3763a17 Edited wiki page LuaAPI through web user interface.
szabibibi@gmail.com
parents: 209
diff changeset
   550
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   551
<code language="lua">    gear = AddGear(...)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   552
     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
   553
     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
   554
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   555
=== <tt>!DeleteGear(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
Deletes a gear.
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   557
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   558
Example:
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   559
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   560
<code language="lua">    gear = AddGear(...)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   561
    DeleteGear(gear) -- Delete the newly created gear.</code>
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   562
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   563
=== <tt>!DeleteVisualGear(vgUid)</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
   564
Deletes a visual gear. Note, most visual gears delete themselves.
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   565
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   566
Example:
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   567
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   568
<code language="lua">    vgear = AddVisualGear(...)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   569
    DeleteVisualGear(vgear) -- Delete the newly created visual gear.</code>
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   570
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   571
554
b77ffc789732 Escape “FrameTicks” once again
almikes@aol.com
parents: 553
diff changeset
   572
=== <tt>!SetVisualGearValues(vgUid, X, Y, dX, dY, Angle, Frame, !FrameTicks, State, Timer, Tint)</tt> ===
553
5faf837d73e5 Escape “FrameTicks”
almikes@aol.com
parents: 552
diff changeset
   573
This allows manipulation of many of the visual gear values. Calling `GetVisualGearValues` first is recommended on most visual gears unless you are controlling all the key values. In the case of `vgtCircle`, the visual gear values are mapped as follows.  X, Y: position.  State: radius. Timer: Thickness.  !FrameTicks: pulsation speed (0 to disable).  dX, dY: min/max pulsation opacity (0-255). Tint: colour, RGBA.
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
   574
Most visual gears require little to no modification of parameters.
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   575
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   576
Example:
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   577
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   578
<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
   579
    SetVisualGearValues(circleUid, 1000,1000, 20, 200, 0, 0, 100, 50, 3, 0xff0000ff)</code>
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   580
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   581
Beginning from 0.9.21-dev, the 2nd to 11th arguments are optional. Any such argument which is declared as `nil` will not overwrite the corresponding value of the visual gear. With this change, it is not required anymore to call `GetVisualGearValues` beforehand.
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   582
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   583
Examples:
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   584
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   585
<code language="lua">  -- set a circle to position 1000,1000
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   586
    SetVisualGearValues(circleUid, 1000, 1000)</code>
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   587
<code language="lua">  -- set the color of a circle to bright red.
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   588
    SetVisualGearValues(circleUid, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xff0000ff)</code>
27add396065d Update SetVisualGearValues
almikes@aol.com
parents: 549
diff changeset
   589
39
45a576e56425 Updating with visual gear functions and delete gear
kyberneticist
parents: 38
diff changeset
   590
136
538adf2596b5 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 135
diff changeset
   591
=== <tt>!FindPlace(gearUid, fall, left, right, tryHarder) (0.9.16)</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
   592
Finds a place for the specified gear between x=`left` and x=`right` and places it there. 0.9.16 adds an optional fifth parameter, `tryHarder`. Setting 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
   593
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   594
Example:
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   595
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   596
<code language="lua">    gear = AddGear(...)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   597
    FindPlace(gear, true, 0, LAND_WIDTH) -- places the gear randomly between 0 and LAND_WIDTH</code>
533
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   598
=== <tt>!HogSay(gearUid, text, manner [,vgState])</tt> ===
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   599
Makes the specified gear say, think, or shout some text in a comic-style speech or thought bubble. In 0.9.21 `gearUid` is _not_ limited to hedgehogs, altough the function name suggests otherwise.
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   600
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   601
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
   602
533
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   603
|| *Value of `manner`* || *Looks* ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   604
|| `SAY_THINK` || Thought bubble ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   605
|| `SAY_SAY` || Speech bubble ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   606
|| `SAY_SHOUT` || Exclamatory bubble (denotes shouting) ||
59
233360620ae2 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 58
diff changeset
   607
533
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   608
As of 0.9.21, 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.
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   609
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   610
|| *Value of `vgState`* || *Effect* ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   611
|| `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
   612
|| `1` || The bubble is drawn translucent. ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   613
|| `2` || The bubble is drawn fully opaque. ||
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   614
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   615
Examples:
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   616
f33a741d9057 Update HogSay for 0.9.21
almikes@aol.com
parents: 519
diff changeset
   617
<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
   618
<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
   619
<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
   620
=== <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
   621
Faces the specified hog left or right.
52
714b56de5ea1 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 51
diff changeset
   622
714b56de5ea1 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 51
diff changeset
   623
Example:
714b56de5ea1 Edited wiki page LuaAPI through web user interface.
RedGrinner
parents: 51
diff changeset
   624
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   625
<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
   626
    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
   627
=== <tt>!SetGearPosition(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
   628
Places the specified gear exactly at the position (`x`,`y`).
71
2dcbebb06088 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 70
diff changeset
   629
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
   630
=== <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
   631
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
   632
555
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   633
=== <tt>!SetFlightTime(gearUid, flighttime)</tt> ===
b7dd77a7d356 Add GetFlightTime and SetFlightTime
almikes@aol.com
parents: 554
diff changeset
   634
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
   635
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   636
=== <tt>!SetAmmo(ammoType, count, probability, delay, numberInCrate)</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
   637
This updates the settings for a specified [AmmoTypes Ammo Type] as of count available for players, spawn probability, availability delay in turns, and the number available in crates. This is supposed to be used in the `onAmmoStoreInit()` event handler.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   638
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   639
Example:
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   640
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   641
<code language="lua">    SetAmmo(amShotgun, 9, 0, 0, 0) -- unlimited amount of shotgun ammo for players
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   642
    SetAmmo(amGrenade, 0, 0, 0, 3) -- crates should contain always three grenade</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
   643
564
c002f49283c6 Add SetAmmoDelay
almikes@aol.com
parents: 563
diff changeset
   644
=== <tt>!SetAmmoDelay(ammoType, delay)</tt> ===
c002f49283c6 Add SetAmmoDelay
almikes@aol.com
parents: 563
diff changeset
   645
Changes the delay of a specified [AmmoTypes Ammo Type].
c002f49283c6 Add SetAmmoDelay
almikes@aol.com
parents: 563
diff changeset
   646
135
124b11219537 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 134
diff changeset
   647
=== <tt>!AddAmmo(gearUid, ammoType, ammoCount) (0.9.16) </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
   648
Adds `ammoType` to the specified gear. The amount added is determined by the arguments passed via `SetAmmo()` in the `onAmmoStoreInit()` event handler. In 0.9.16 ammo can be set directly via the optional third parameter, `ammoCount`. A value of 0 will remove the weapon, a value of 100 will give infinite ammo.
101
174650a7ce20 Added entry for AddAmmo()
RedGrinner@gmail.com
parents: 100
diff changeset
   649
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
   650
*Note:* The effectiveness of this function may be limited due to problems with `gfPerHogAmmo` in Lua scripting.
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
   651
101
174650a7ce20 Added entry for AddAmmo()
RedGrinner@gmail.com
parents: 100
diff changeset
   652
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   653
=== <tt>!SetHealth(gearUid, health)</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
   654
Sets the health of the specified gear.
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   655
This can be used for purposes other than killing hedgehogs.
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   656
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   657
For example:
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   658
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   659
  * Starting the RC Plane 10 shots
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
   660
  * Starting Flying Saucer (`gtJetpack`) with only 50% fuel.
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   661
  * Setting all the mines to duds.
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   662
  * (And more!)
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   663
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   664
<code language="lua">    function onGearAdd(gear)
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   665
       if (GetGearType(gear) == gtRCPlaane) then
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   666
            SetHealth(gear, 10)
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   667
       end
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   668
       if (GetGearType(gear) == gtJetpack) then
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   669
            SetHealth(gear, 1000)
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   670
       end
361
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   671
       if (GetGearType(gear) == gtMine) then
315e9db1f458 no need to prevent linking of names in code blocks
sheepyluva@gmail.com
parents: 360
diff changeset
   672
            SetHealth(gear, 0)
99
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   673
       end
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   674
    end</code>
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   675
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   676
983ec9ac63c7 Added a non-exhaustive list of examples for further applications of SetHealth()
RedGrinner@gmail.com
parents: 98
diff changeset
   677
373
0f9322acd00a update GetEffect/SetEffect info
sheepyluva@gmail.com
parents: 369
diff changeset
   678
=== <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
   679
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
   680
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
   681
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
   682
Example (sets all bots poisoned):
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   683
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   684
<code language="lua">    function onGearAdd(gear)
558
e9a42aa9e4c2 GetHogLevel, not GetBotLevel
nemo
parents: 557
diff changeset
   685
        if (GetGearType(gear) == gtHedgehog) and (GetHogLevel(gear) > 0) then
373
0f9322acd00a update GetEffect/SetEffect info
sheepyluva@gmail.com
parents: 369
diff changeset
   686
            SetEffect(gear, hePoisoned, 1)
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   687
        end
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   688
    end</code>
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   689
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
   690
*Note*: prior to the ice-gun release, 0.9.19 (commit r10a0a31804f3) `effectState` was of boolean type (`true` = effect enabled, `false` = effect disabled)
373
0f9322acd00a update GetEffect/SetEffect info
sheepyluva@gmail.com
parents: 369
diff changeset
   691
17
2893bd461cc7 LuaAPI: minor improvement
tobias.neumann
parents: 16
diff changeset
   692
=== <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
   693
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
   694
71
2dcbebb06088 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 70
diff changeset
   695
=== <tt>CopyPV2(gearUid, gearUid)</tt> (deprecated) ===
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
   696
This sets the position of the second gear to that of the first one, but makes its velocity twice the one of the first.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   697
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
   698
*Notice*: This function is no longer used, use `GetGearVelocity` and `SetGearVelocity` instead.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   699
=== <tt>!FollowGear(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
   700
Makes the game client follow the specifiec gear.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   701
139
6bf231a611a7 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 138
diff changeset
   702
=== <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
   703
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
   704
398
1f9f7fb00be3 Added entries for SetHogTeamName, SetWeapon
RedGrinner@gmail.com
parents: 394
diff changeset
   705
=== <tt>!SetHogTeamName(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
   706
Sets the team name of the specified hedgehog gear.
398
1f9f7fb00be3 Added entries for SetHogTeamName, SetWeapon
RedGrinner@gmail.com
parents: 394
diff changeset
   707
1f9f7fb00be3 Added entries for SetHogTeamName, SetWeapon
RedGrinner@gmail.com
parents: 394
diff changeset
   708
=== <tt>!SetWeapon(ammoType)</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
   709
Sets the selected weapon of `CurrentHedgehog` to one of the [AmmoTypes Ammo Type].
398
1f9f7fb00be3 Added entries for SetHogTeamName, SetWeapon
RedGrinner@gmail.com
parents: 394
diff changeset
   710
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
   711
Example:
398
1f9f7fb00be3 Added entries for SetHogTeamName, SetWeapon
RedGrinner@gmail.com
parents: 394
diff changeset
   712
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   713
<code language="lua">
398
1f9f7fb00be3 Added entries for SetHogTeamName, SetWeapon
RedGrinner@gmail.com
parents: 394
diff changeset
   714
  AddAmmo(CurrentHedgehog, amBazooka, 1) -- give the CurrentHedgehog a bazooka
1f9f7fb00be3 Added entries for SetHogTeamName, SetWeapon
RedGrinner@gmail.com
parents: 394
diff changeset
   715
  SetWeapon(amBazooka) -- select the Bazooka.</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
   716
408
e9b65daecbcf Move SetNextWeapon in text
almikes@aol.com
parents: 407
diff changeset
   717
410
c0367902bea7 Small formatting fixes.
almikes@aol.com
parents: 408
diff changeset
   718
=== <tt>!SetNextWeapon()</tt> (0.9.21) ===
408
e9b65daecbcf Move SetNextWeapon in text
almikes@aol.com
parents: 407
diff changeset
   719
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.
e9b65daecbcf Move SetNextWeapon in text
almikes@aol.com
parents: 407
diff changeset
   720
e9b65daecbcf Move SetNextWeapon in text
almikes@aol.com
parents: 407
diff changeset
   721
139
6bf231a611a7 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 138
diff changeset
   722
=== <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
   723
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
   724
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
   725
=== <tt>!SetGearTarget(gearUid, x, y) (0.9.16)</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
   726
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
   727
*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
   728
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   729
=== <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
   730
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
   731
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   732
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
   733
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   734
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
   735
<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
   736
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
   737
--[[ 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
   738
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
   739
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
   740
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
   741
</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
   742
70961d4eef05 Fixed misleading descriptions of GetState and SetState (use of bitmasks were not mentioned). Added commented examples.
almikes@aol.com
parents: 414
diff changeset
   743
<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
   744
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
   745
--[[ 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
   746
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
   747
</code>
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
   748
114
e311af715b57 Edited wiki page LuaAPI through web user interface.
henrik.rostedt@gmail.com
parents: 107
diff changeset
   749
=== <tt>!SetGearMessage(gearUid, message)</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
   750
>Sets the message of the specified gear.
114
e311af715b57 Edited wiki page LuaAPI through web user interface.
henrik.rostedt@gmail.com
parents: 107
diff changeset
   751
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   752
=== <tt>!SetTag(gearUid, tag)</tt> ===
419
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   753
Sets the tag of the specified gear (by `gearUid`). A “tag” 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. `tag` has to be an integer.
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   754
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   755
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
   756
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   757
<code language="lua">
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   758
-- This adds a ball (the one from the ballgun) at (123, 456):
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   759
ball = AddGear(123, 456, gtBall, 0, 0, 0, 0)
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   760
-- 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
   761
SetTag(ball, 8) -- 
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   762
</code>
861e9e89e19c Update SetTag, add GetTag.
almikes@aol.com
parents: 418
diff changeset
   763
421
d584704354ad Add link to GearTypes for SetTag and GetTag.
almikes@aol.com
parents: 419
diff changeset
   764
The meaning of tags are described in [GearTypes].
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
   765
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
   766
=== <tt>!SetTimer(gearUid, timer)</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
   767
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
   768
360
2fcb523f0cc4 small fixes
sheepyluva@gmail.com
parents: 359
diff changeset
   769
=== <tt>!SetHogLevel(gearUid, level)</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
   770
Sets the bot level from 0 to 5. `0` means human player.
69
48f6e6c0076d Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 68
diff changeset
   771
360
2fcb523f0cc4 small fixes
sheepyluva@gmail.com
parents: 359
diff changeset
   772
=== <tt>!SetGearPos(gearUid, value) (0.9.18-dev)</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
   773
Set pos of specified gear to specified value.
183
72b2bac582e2 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 182
diff changeset
   774
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   775
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   776
== Gameplay functions ==
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   777
549
fdff535292e4 Minor fix.
almikes@aol.com
parents: 540
diff changeset
   778
=== `GameFlags` functions ===
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   779
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   780
==== <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
   781
Disables *all* !GameFlags.
380
b9bd613524ca adding gameflag api documentation
sheepyluva@gmail.com
parents: 379
diff changeset
   782
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   783
==== <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
   784
Disables the listed !GameFlags, without changing the status of other !GameFlags.
380
b9bd613524ca adding gameflag api documentation
sheepyluva@gmail.com
parents: 379
diff changeset
   785
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   786
==== <tt>!EnableGameFlags(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
   787
Enables the listed !GameFlags, without changing the status of other !GameFlags.
380
b9bd613524ca adding gameflag api documentation
sheepyluva@gmail.com
parents: 379
diff changeset
   788
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   789
==== <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
   790
Returns `true` if the specified gameflag is enabled, otherwise `false`.
380
b9bd613524ca adding gameflag api documentation
sheepyluva@gmail.com
parents: 379
diff changeset
   791
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   792
=== Environment ===
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   793
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   794
==== <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
   795
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
   796
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
   797
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   798
==== <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
   799
Returns the current gravity in percent.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   800
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   801
==== <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
   802
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
   803
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   804
==== <tt>!SetWind(windSpeed)</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
   805
Sets the current wind in the range of -100 to 100. Use together with `gfDisableWind` for full control.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   806
608
9a49d69316f2 SetMaxBuildDistance
Wuzzy
parents: 583
diff changeset
   807
==== <tt>!SetMaxBuildDistance(distInPx)</tt> (0.9.22) ====
9a49d69316f2 SetMaxBuildDistance
Wuzzy
parents: 583
diff changeset
   808
Sets the maximum building distance for of girders and rubber bands in pixels to `distInPx`. If `distInPx` is `0`, the limit is disabled. If `distInPx` is `nil`, the distance will be reset to the default value.
9a49d69316f2 SetMaxBuildDistance
Wuzzy
parents: 583
diff changeset
   809
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   810
==== <tt>!EndGame()</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
   811
Makes the game end.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   812
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   813
=== Map ===
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   814
==== <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
   815
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
   816
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   817
==== <tt>!TestRectForObstacle(x1, y1, x2, y2, landOnly) (0.9.16) </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
   818
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
   819
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   820
==== <tt>!PlaceGirder(x, y, state)</tt> (0.9.16) ====
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
   821
Places a girder with centre points `x`, `y` and a certain length and orientation, specified by `state`.
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   822
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   823
These are the accepted states:
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   824
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
   825
|| *`state`* || *Length* || *Orientation* ||
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
   826
|| 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
   827
|| 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
   828
|| 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
   829
|| 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
   830
|| 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
   831
|| 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
   832
|| 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
   833
|| 7 || long || increasing right ||
412
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
   834
539
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   835
==== <tt>!PlaceSprite(x, y, sprite, frameIdx, ...)</tt> ====
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   836
Places a [Sprites sprite] at the specified position (`x`, `y`) on the map, it behaves like terrain then. `frameIdx` is the frame index starting by 0. This is used if the sprite consists of several sub-images. Only a subset of the sprites is currently supported by this function:
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   837
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   838
 * `sprAmGirder`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   839
 * `sprAmRubber`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   840
 * `sprAMSlot`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   841
 * `sprAMAmmos`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   842
 * `sprAMAmmosBW`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   843
 * `sprAMCorners`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   844
 * `sprHHTelepMask`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   845
 * `sprTurnsLeft`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   846
 * `sprSpeechCorner`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   847
 * `sprSpeechEdge`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   848
 * `sprSpeechTail`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   849
 * `sprThoughtCorner`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   850
 * `sprThoughtEdge`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   851
 * `sprThoughtTail`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   852
 * `sprShoutCorner`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   853
 * `sprShoutEdge`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   854
 * `sprShoutTail`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   855
 * `sprSnow`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   856
 * `sprBotlevels`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   857
 * `sprIceTexture`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   858
 * `sprCustom1`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   859
 * `sprCustom2`
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   860
540
b41b9305be9f Add land flags
almikes@aol.com
parents: 539
diff changeset
   861
The 5th and later arguments specify land flags (see the constants section) to be used for the newly created terrain. If omited, `lfNormal` is assumed.
539
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   862
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   863
Example:
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   864
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   865
<code language="lua">PlaceSprite(2836, 634, sprAmGirder, 5, lfNormal)
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   866
-- Places the girder sprite as normal terrain at (2836, 634). The `frameIdx` 5 is for the long decreasing right girder.</code>
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   867
<code language="lua">PlaceSprite(1411, 625, sprAmRubber, 1, lfBouncy)
7173ac8996f9 Add PlaceSprite
almikes@aol.com
parents: 538
diff changeset
   868
-- 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
   869
412
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
   870
==== <tt>!AddPoint(x, y [, width [, erase] ])</tt> (0.9.21) ====
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
   871
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
   872
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
   873
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
   874
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
   875
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
   876
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
   877
==== <tt>!FlushPoints()</tt> (0.9.21) ====
d2f4b5b9b77c Add AddPoint and FlushPoints.
almikes@aol.com
parents: 411
diff changeset
   878
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
   879
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   880
=== Current hedgehog ===
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   881
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   882
==== <tt>!GetCurAmmoType()</tt> (0.9.16) ====
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
   883
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
   884
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   885
==== <tt>!SwitchHog(gearUid)</tt> (0.9.16) ====
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
   886
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
   887
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   888
==== <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
   889
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
   890
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   891
Example: 
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
   892
<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
   893
SetInputMask(band(0xFFFFFFFF, bnot(gmLJump + gmHJump))) 
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   894
    -- 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
   895
    SetInputMask(0xFFFFFFFF) 
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   896
		</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
   897
*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
   898
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
   899
See also [GearMessages].
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   900
405
4e1c166740b0 Add GetInputMask
almikes@aol.com
parents: 404
diff changeset
   901
==== <tt>!GetInputMask()</tt> ====
4e1c166740b0 Add GetInputMask
almikes@aol.com
parents: 404
diff changeset
   902
Returns the current input mask of the player.
4e1c166740b0 Add GetInputMask
almikes@aol.com
parents: 404
diff changeset
   903
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   904
=== Randomness ===
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   905
==== <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
   906
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
   907
413
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
   908
=== Clans and teams ===
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
   909
==== <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
   910
476
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   911
Adds a new team. Note that this can only be done in `onGameInit`, not at a later time.
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   912
You *must* add at least one hedgehog with `AddHog` after calling this. The engine does not support empty teams.
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   913
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   914
Arguments:
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   915
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   916
 * `teamname`: The name of the team.
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   917
 * `color`: The RGB color of the team as defined in [LuaAPI#Color]
476
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   918
 * `grave`: The name of the team’s grave (equals file name without the suffix)
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   919
 * `fort`: The name of the team’s fort
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   920
 * `voicepack`: The name of the team’s voice pack (equals the directory name)
560
d0c74d14c7b6 Updated AddTeam
almikes@aol.com
parents: 558
diff changeset
   921
 * `flag`: Optional argument for the name of the team’s flag (equals file name without the suffix)
476
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   922
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
   923
*Note: This works only for singleplayer training missions for now and will desync multiplayer games.
413
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
   924
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
   925
Example:
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
   926
476
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   927
<code language="lua">AddTeam("team 1", 0xDD0000, "Simple", "Tank", "Default", "hedgewars")
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   928
--[[ Adds a new team with name “team 1”, red color (hexadecimal notation), the grave “Simple”,
dd4470df66ad Restructure information about AddTeam, add info that Hedgewars does not support empty teams.
almikes@aol.com
parents: 461
diff changeset
   929
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
   930
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
   931
==== <tt>!DismissTeam(teamname)</tt> ====
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
   932
Removes the team with the given team name from the game.
6d90d6994e95 Add DismissTeam, move AddTeam to new “Clans and teams” section.
almikes@aol.com
parents: 412
diff changeset
   933
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   934
==== <tt>!GetClanColor(clan)</tt> ====
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   935
Returns the RGB 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
   936
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   937
==== <tt>!SetClanColor(clan, color)</tt> ====
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   938
Sets the RGB 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
   939
577
6e77c79a8457 Add GetCampaignVar and SaveCampaignVar
almikes@aol.com
parents: 576
diff changeset
   940
=== Campaign management ===
6e77c79a8457 Add GetCampaignVar and SaveCampaignVar
almikes@aol.com
parents: 576
diff changeset
   941
==== <tt>!SaveCampaignVar(varname, value)</tt> ====
6e77c79a8457 Add GetCampaignVar and SaveCampaignVar
almikes@aol.com
parents: 576
diff changeset
   942
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
   943
579
9895045e9963 Updated SaveCampaignVar / GetCampaignVar links
almikes@aol.com
parents: 577
diff changeset
   944
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
   945
577
6e77c79a8457 Add GetCampaignVar and SaveCampaignVar
almikes@aol.com
parents: 576
diff changeset
   946
==== <tt>!GetCampaignVar(varname)</tt> ====
579
9895045e9963 Updated SaveCampaignVar / GetCampaignVar links
almikes@aol.com
parents: 577
diff changeset
   947
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
   948
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   949
== Functions affecting the GUI ==
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   950
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   951
=== <tt>!AddCaption(text)</tt> ===
561
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
   952
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
   953
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   954
Example:
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   955
<code language="lua">
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   956
AddCaption("Hello, world!")
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   957
</code>
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   958
561
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
   959
=== <tt>!AddCaption(text, color, captiongroup)</tt> ===
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   960
Display an event text in the upper part of the screen with the specified RGBA [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
   961
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
   962
|| *`captiongroup`* || *Meaning* ||
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
   963
|| `capgrpGameState` || Used for important global game events, like Sudden Death ||
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
   964
|| `capgrpAmmoinfo` || Used for new weapon crates and some other events ||
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
   965
|| `capgrpVolume` || Used when adjusting volume ||
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
   966
|| `capgrpMessage` || Generic message ||
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
   967
|| `capgrpMessage2` || Generic message ||
814f54a83d06 Update AddCaption
almikes@aol.com
parents: 560
diff changeset
   968
|| `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
   969
583
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   970
Example:
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   971
<code language="lua">
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   972
AddCaption("Melon bomb rain in 2 rounds!", 0xFF0000FF, capgrpGameState)
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   973
-- Green example message.
0818d57c392f Clarifications on differences of RGB vs RGBA.
almikes@aol.com
parents: 579
diff changeset
   974
</code>
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   975
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   976
=== <tt>!ShowMission(caption, subcaption, text, icon, time)</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
   977
Use to tell the player what he is supposed to do.
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   978
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
   979
As of version 0.9.15, `icon` currently accepts the following values:
79
64fc6cee4af7 Added a note on the new icons for ShowMission
RedGrinner
parents: 78
diff changeset
   980
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
   981
|| *`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
   982
|| _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
   983
|| `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
   984
|| `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
   985
|| `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
   986
|| `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
   987
|| `4` || Golden star ||
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
   988
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   989
=== <tt>!HideMission()</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
   990
Hides the mission. This function is currently bugged somehow and will completely ruin your life, and your script should you happen to use it.
28
026591d95ac6 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 24
diff changeset
   991
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   992
=== <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
   993
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
   994
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   995
=== <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
   996
Returns the current zoom level.
147
379d7931ffc7 Edited wiki page LuaAPI through web user interface.
RedGrinner@gmail.com
parents: 146
diff changeset
   997
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
   998
== Sound functions ==
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
   999
=== <tt>!PlaySound(soundId)</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
  1000
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
  1001
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
  1002
=== <tt>!PlaySound(soundId, 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
  1003
Plays the specified sound for the chosen hedgehog gear. This can be used to play a taunt with the voicepack of the hedgehog’s team.
70
ff7d4c176303 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 69
diff changeset
  1004
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
  1005
Possible values for `soundId` are listed on the [Sounds] page. See also [Taunts].
77
588f5dc682e2 Added SetInputMask function
RedGrinner
parents: 76
diff changeset
  1006
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1007
== File system functions ==
410
c0367902bea7 Small formatting fixes.
almikes@aol.com
parents: 408
diff changeset
  1008
=== <tt>!HedgewarsScriptLoad(scriptPath)</tt> ===
407
36537eaf680c Add HedgewarsScriptLoad
almikes@aol.com
parents: 406
diff changeset
  1009
Loads a script (i.e. a [LuaLibraries library]) from the specified `scriptPath`. The root directory is here Hedgewars’ data directory.
36537eaf680c Add HedgewarsScriptLoad
almikes@aol.com
parents: 406
diff changeset
  1010
36537eaf680c Add HedgewarsScriptLoad
almikes@aol.com
parents: 406
diff changeset
  1011
Example:
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
  1012
<code language="lua">
407
36537eaf680c Add HedgewarsScriptLoad
almikes@aol.com
parents: 406
diff changeset
  1013
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
  1014
</code>
407
36537eaf680c Add HedgewarsScriptLoad
almikes@aol.com
parents: 406
diff changeset
  1015
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
  1016
=== <tt>!GetDataPath()</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
  1017
Returns the path to the data directory, used when adding libraries.
68
fd230628d72c Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 67
diff changeset
  1018
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
  1019
=== <tt>!GetUserDataPath()</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
  1020
Returns the path to the user data directory, used when adding libraries.
180
96e6b405bcf6 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 179
diff changeset
  1021
96e6b405bcf6 Edited wiki page LuaAPI through web user interface.
azizi.054@gmail.com
parents: 179
diff changeset
  1022
73
c6623486d077 Edited wiki page LuaAPI through web user interface.
henrik.rostedt
parents: 72
diff changeset
  1023
89
caf6544f767a Edited wiki page LuaAPI through web user interface.
henrik.rostedt@gmail.com
parents: 87
diff changeset
  1024
caf6544f767a Edited wiki page LuaAPI through web user interface.
henrik.rostedt@gmail.com
parents: 87
diff changeset
  1025
404
37d44392ad2b Reorganize the section “other functions” into several logical subunits.
almikes@aol.com
parents: 403
diff changeset
  1026
== Stats functions ==
360
2fcb523f0cc4 small fixes
sheepyluva@gmail.com
parents: 359
diff changeset
  1027
=== <tt>!SendStat(TStatInfoType, statMessage[, teamName])</tt> (0.9.20) ===
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1028
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
  1029
This function exposes the uIO SendStat to the Lua scripts. Use it to produce custom stat pages.
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
  1030
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
  1031
`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
  1032
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
  1033
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
  1034
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
|| *`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
  1036
|| `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
  1037
|| `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
  1038
|| `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 ||
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
  1039
|| `siPointType` || Replaces the word “kills” in the ranking list. Sadly, grammatical number is currently not respected at all here. || 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
  1040
|| `siPlayerKills` || The number of kills for the specified team (converted to a string), as shown in the ranking list. Unless the word “kills” has been replaced by `siPointType`, then that word is used instead. Only integers (converted to string) are possible. || Yes ||
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
  1041
|| `siClanHealth` || Value of a data point (converted to a string). This sets a single data point on the graph for the specified team. Subsequent calls will draw the next point along the horizontal axis; the frontend will then simply connect the dots in the final graph. The graphs are treated independently for each other. Currently the graph only can display positive values. You also should have called `SendHealthStatsOff` if you use this to prevent the default health graphs to be drawn. || Yes ||
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
  1042
|| `siMaxStepKills` || Most hedgehogs killed in a round. `statText` must be in format “`<kills> <name of killer hedgehog> (<team name of killer>)`”. || 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
  1043
|| `siMaxTeamDamage` || Hedgehog with most damage inflicted to his own team. `statText` must be in the format “`<damage> <hedgehog name>`”. || 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
  1044
|| `siKilledHHs` || Total number of killed hedgehogs (converted to string). || 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
  1045
|| `siTeamStats` || Increases the wins of local teams in case the given number is greater than 0. || 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
  1046
|| `siMaxStepDamage` || Best shot award (most damage in one turn). `statText` must be in format “`<damage> <hedgehog name> (<team name>)`”. || 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
  1047
|| `siMaxTurnSkips` || Team with most skips. `statText` must be of format “`<number> <teamName>`”. || 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
  1048
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1049
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1050
<b>Examples:</b>
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1051
416
5aa55bbe4b73 Fixed faulty syntax highlighting in code block (was: “<code lang=…” instead of “<code language=…”)
almikes@aol.com
parents: 415
diff changeset
  1052
<code language="lua">
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1053
-- will automatically change the health icon to a star
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1054
SendStat(siGraphTitle,'Custom Graph Title')
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1055
SendStat(siGameResult,'Winner is Team A!')
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
  1056
SendStat(siCustomAchievement,'This is a custom message posted in the Details section!')
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1057
-- Changes the word kill to Point, call it just before sending kills/score for each hog
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1058
-- in case you want to change the word i.e. print Point or Points
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1059
SendStat(siPointType,'Point')
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1060
-- if above function call was not used it will print 3 kills for teamName in Ranking section.
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1061
-- if it was used it will print 3 Point for teamName in Ranking section.
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1062
SendStat(siPlayerKills,'3',teamName)
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1063
-- 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
  1064
-- 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
  1065
-- in normal mode "value" represents clan health
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1066
SendStat(siClanHealth, "100",teamName)
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1067
-- most hedgehogs killed in a round (hedgeHogName is who killed them)
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1068
SendStat(siMaxStepKills, "1 hedgeHogName (teamName)")
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1069
-- hog with most damage inflicted to his own team
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1070
SendStat(siMaxTeamDamage, "100 hedgeHogName")
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1071
-- total number of killed hedgehogs
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1072
SendStat(siKilledHHs, "1")
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1073
-- increases the wins of local teams in case the given number is greater than 0
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1074
SendStat(siTeamStats, "teamName:0:")
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1075
-- best shot award
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1076
SendStat(siMaxStepDamage, "30 hedgeHogName (teamName)")
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1077
-- team with most kills of own hedgehogs
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1078
SendStat(siMaxStepDamage, "2 teamName")
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1079
-- team with most skips
347
edc8d322d02d Edited wiki page LuaAPI, fixing SendStat
pntanasis@gmail.com
parents: 346
diff changeset
  1080
SendStat(siMaxTurnSkips, "3 teamName")
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1081
</code>
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1082
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1083
<b>Important:</b>
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1084
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
  * 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
  1086
  * 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
  1087
  * 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
  1088
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1089
=== <tt>!SendHealthStatsOff()</tt> (0.9.20) ===
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
  1090
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
  1091
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
  1092
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()`.
328
fdc71ac8db83 Updated wiki page LuaAPI with the SendStat() and SendHealthStatsOff() functions.
pntanasis@gmail.com
parents: 313
diff changeset
  1093
382
5b90c6ef1f62 add div()
sheepyluva@gmail.com
parents: 381
diff changeset
  1094
== Math Functions ==
5b90c6ef1f62 add div()
sheepyluva@gmail.com
parents: 381
diff changeset
  1095
383
6679b75048c0 I really have to get used to using preview on google code wiki...
sheepyluva@gmail.com
parents: 382
diff changeset
  1096
=== <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
  1097
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
  1098
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
  1099
401
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1100
=== <tt>band(value1, value2)</tt> ===
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1101
Returns the bitwise logical AND of `value1` and `value2`.
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1102
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1103
=== <tt>bor(value1, value2)</tt> ===
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1104
Returns the bitwise logical OR of `value1` and `value2`.
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1105
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1106
=== <tt>bnot(value)</tt> ===
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1107
Returns the bitwise logical NOT of `value`.
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1108
aee281298267 Documented the following functions: band, bnot, bor.
almikes@aol.com
parents: 400
diff changeset
  1109
12
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
  1110
== Debugging Functions ==
74ead59b6c64 LuaAPI page + GearTypes,AmmoTypes,Sounds,States listing pages
Tobias Neumann <mail@tobias-neumann.eu>
parents:
diff changeset
  1111
394
b2742eb19396 Edited wiki page LuaAPI through web abuser interface.
sheepyluva@gmail.com
parents: 384
diff changeset
  1112
=== <tt>!ParseCommand(string)</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
  1113
Makes the game client parse the specified custom command.
394
b2742eb19396 Edited wiki page LuaAPI through web abuser interface.
sheepyluva@gmail.com
parents: 384
diff changeset
  1114
b2742eb19396 Edited wiki page LuaAPI through web abuser interface.
sheepyluva@gmail.com
parents: 384
diff changeset
  1115
*Note*: Please be aware that the *engine protocol can (and will) change* between releases.
b2742eb19396 Edited wiki page LuaAPI through web abuser interface.
sheepyluva@gmail.com
parents: 384
diff changeset
  1116
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
  1117
If you use `ParseCommand` to overcome a shortcoming in our Lua API (e.g. a missing function), please make sure to [https://code.google.com/p/hedgewars/issues/entry report the issue].
394
b2742eb19396 Edited wiki page LuaAPI through web abuser interface.
sheepyluva@gmail.com
parents: 384
diff changeset
  1118
b2742eb19396 Edited wiki page LuaAPI through web abuser interface.
sheepyluva@gmail.com
parents: 384
diff changeset
  1119
With your report we can fix the shortcoming in future releases.
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
  1120
This will allow scripts to use the previously missing feature in a way that won’t break!
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
  1121
394
b2742eb19396 Edited wiki page LuaAPI through web abuser interface.
sheepyluva@gmail.com
parents: 384
diff changeset
  1122
181
714a208397bd version number fixes
sheepyluva@gmail.com
parents: 180
diff changeset
  1123
=== <tt>!WriteLnToConsole(string)</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
  1124
Writes `string` to the `Logs/game0.log`, found in the user data directory.