217 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. |
217 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. |
218 |
218 |
219 === <tt>onNewTurn()</tt> === |
219 === <tt>onNewTurn()</tt> === |
220 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`) |
220 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`) |
221 |
221 |
|
222 === <tt>onEndTurn()</tt> (0.9.24) === |
|
223 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. |
|
224 |
|
225 `CurrentHedgehog` holds the gear ID of the hedgehog whose turn just ended. |
|
226 |
|
227 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. |
|
228 |
|
229 Because this function is called *before* victories are checked, this is useful to set up your victory conditions here. |
|
230 |
222 === <tt>onSuddenDeath()</tt> (0.9.22) === |
231 === <tt>onSuddenDeath()</tt> (0.9.22) === |
223 This function is called on the start of Sudden Death. |
232 This function is called on the start of Sudden Death. |
224 |
233 |
225 === <tt>onGearAdd(gearUid)</tt> === |
234 === <tt>onGearAdd(gearUid)</tt> === |
226 This function is called when a new gear is added. Useful in combination with `GetGearType(gearUid)`. |
235 This function is called when a new gear is added. Useful in combination with `GetGearType(gearUid)`. |
389 </code> |
398 </code> |
390 |
399 |
391 === <tt>!SpawnHealthCrate(x, y, [, health])</tt> === |
400 === <tt>!SpawnHealthCrate(x, y, [, health])</tt> === |
392 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. |
401 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. |
393 |
402 |
|
403 === <tt>!SpawnSupplyCrate(x, y, ammoType [, amount])</tt> (0.9.24) === |
|
404 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. |
|
405 Otherwise, this function behaves like `SpawnAmmoCrate`. |
|
406 |
394 === <tt>!SpawnAmmoCrate(x, y, ammoType [, amount])</tt> === |
407 === <tt>!SpawnAmmoCrate(x, y, ammoType [, amount])</tt> === |
395 Spawns an ammo crate at the specified position with content of ammoType (see [AmmoTypes Ammo Types]). 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 `100` or greater, the amount is infinite. |
408 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. |
|
409 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 `100` or greater, the amount is infinite. |
396 |
410 |
397 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: |
411 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: |
398 |
412 |
399 Example: |
413 Example: |
400 |
414 |
790 -- Turn mine into dud |
804 -- Turn mine into dud |
791 SetHealth(gear, 0) |
805 SetHealth(gear, 0) |
792 end |
806 end |
793 end</code> |
807 end</code> |
794 |
808 |
795 |
809 === `HealHog(gearUid, healthBoost[, showMessage[, tint]])` (0.9.24) === |
|
810 Convenience function to heal hedgehogs. |
|
811 |
|
812 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. |
|
813 |
|
814 If `showMessage` is false, no message is shown. With `tint` you can set the RGBA color of the particles (default: `0x00FF00FF`). |
796 |
815 |
797 === <tt>!SetEffect(gearUid, effect, effectState)</tt> === |
816 === <tt>!SetEffect(gearUid, effect, effectState)</tt> === |
798 Sets the state for one of the effects <tt>heInvulnerable, heResurrectable, hePoisoned, heResurrected, heFrozen</tt> for the specified hedgehog gear. |
817 Sets the state for one of the effects <tt>heInvulnerable, heResurrectable, hePoisoned, heResurrected, heFrozen</tt> for the specified hedgehog gear. |
799 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. |
818 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. |
800 |
819 |
921 |
940 |
922 ==== <tt>!SetWaterLine(waterline)</tt> ==== |
941 ==== <tt>!SetWaterLine(waterline)</tt> ==== |
923 Sets the water level (`WaterLine`) to the specified y-coordinate. |
942 Sets the water level (`WaterLine`) to the specified y-coordinate. |
924 |
943 |
925 ==== <tt>!SetWind(windSpeed)</tt> ==== |
944 ==== <tt>!SetWind(windSpeed)</tt> ==== |
926 Sets the current wind in the range of -100 to 100. Use together with `gfDisableWind` for full control. |
945 Sets the current wind in the range of -100 to 100 inclusive. Use together with `gfDisableWind` for full control. |
|
946 |
|
947 ==== <tt>!GetWind()</tt> (0.9.24) ==== |
|
948 Returns current wind, expressed as a floating point number between -100 to 100 inclusive. Note there may be rounding errors. |
927 |
949 |
928 ==== <tt>!SetMaxBuildDistance(distInPx)</tt> (0.9.22) ==== |
950 ==== <tt>!SetMaxBuildDistance(distInPx)</tt> (0.9.22) ==== |
929 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. |
951 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. |
930 |
952 |
931 ==== <tt>!EndTurn([noTaunts])</tt> (0.9.23) ==== |
953 ==== <tt>!EndTurn([noTaunts])</tt> (0.9.23) ==== |
1102 See also [GearMessages]. |
1124 See also [GearMessages]. |
1103 |
1125 |
1104 ==== <tt>!GetInputMask()</tt> ==== |
1126 ==== <tt>!GetInputMask()</tt> ==== |
1105 Returns the current input mask of the player. |
1127 Returns the current input mask of the player. |
1106 |
1128 |
|
1129 === `SetVampiric(bool)` (0.9.24) === |
|
1130 Toggles vampirism mode for this turn. Set `bool` to `true` to enable (same effect as if the hedgehog has used Vampirism), `false` to disable. |
|
1131 |
|
1132 === `SetLaserSight(bool)` (0.9.24) === |
|
1133 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. |
|
1134 |
1107 === Randomness === |
1135 === Randomness === |
1108 ==== <tt>!GetRandom(number)</tt> ==== |
1136 ==== <tt>!GetRandom(number)</tt> ==== |
1109 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`. |
1137 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`. |
1110 |
1138 |
1111 === Clans and teams === |
1139 === Clans and teams === |
1128 Example: |
1156 Example: |
1129 |
1157 |
1130 <code language="lua">AddTeam("team 1", 0xDD0000, "Simple", "Tank", "Default", "hedgewars") |
1158 <code language="lua">AddTeam("team 1", 0xDD0000, "Simple", "Tank", "Default", "hedgewars") |
1131 --[[ Adds a new team with name “team 1”, red color (hexadecimal notation), the grave “Simple”, |
1159 --[[ Adds a new team with name “team 1”, red color (hexadecimal notation), the grave “Simple”, |
1132 the fort “Tank” the voicepack “Default” and the flag “hedgewars”. ]]</code> |
1160 the fort “Tank” the voicepack “Default” and the flag “hedgewars”. ]]</code> |
|
1161 |
|
1162 ==== <tt>!GetTeamName(teamIdx)</tt> (0.9.24) ==== |
|
1163 Returns the name of the team with the index `teamIdx`. `teamIdx` is a number between 0 and `TeamsCount-1`. |
1133 |
1164 |
1134 ==== <tt>!DismissTeam(teamname)</tt> ==== |
1165 ==== <tt>!DismissTeam(teamname)</tt> ==== |
1135 Removes the team with the given team name from the game. |
1166 Removes the team with the given team name from the game. |
1136 |
1167 |
1137 ==== <tt>!GetClanColor(clan)</tt> ==== |
1168 ==== <tt>!GetClanColor(clan)</tt> ==== |
1353 |
1384 |
1354 == Debugging Functions == |
1385 == Debugging Functions == |
1355 === `WriteLnToConsole(string)` === |
1386 === `WriteLnToConsole(string)` === |
1356 Writes `string` to `Logs/game0.log`, found in the user data directory. |
1387 Writes `string` to `Logs/game0.log`, found in the user data directory. |
1357 |
1388 |
|
1389 === `WriteLnToChat(string)` (0.9.24) === |
|
1390 Writes `string` into the chat. |
|
1391 |
1358 === `DumpPoint(x, y)` (0.9.23) === |
1392 === `DumpPoint(x, y)` (0.9.23) === |
1359 Converts the whole numbers `x` and `y` to strings and writes them to `Logs/game0.log`, one line each. |
1393 Converts the whole numbers `x` and `y` to strings and writes them to `Logs/game0.log`, one line each. |
1360 |
1394 |
1361 === <tt>!ParseCommand(string)</tt> === |
1395 === <tt>!ParseCommand(string)</tt> === |
1362 Makes the game client parse and execute the specified internal game engine command. |
1396 Makes the game client parse and execute the specified internal game engine command. |