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