# HG changeset patch
# User Wuzzy
# Date 1555503350 -3600
# Node ID 729bef6b40da844bfe40ba801c6eb4394cb6e781
# Parent bae9bae61cda3dcb3853336574ce10a8babd9aef
LuaEvents: Restructure events into sections
diff -r bae9bae61cda -r 729bef6b40da LuaEvents.wiki
--- a/LuaEvents.wiki Wed Apr 17 13:09:05 2019 +0100
+++ b/LuaEvents.wiki Wed Apr 17 13:15:50 2019 +0100
@@ -5,27 +5,28 @@
This page is a list of all supported event handlers in Hedgewars.
-
+
-== onGameInit() ==
+== Initialization ==
+=== onGameInit() ===
This function is called before the game loads its resources. One can read and modify various [LuaGlobals#Game_variables game variables] here. These variables will become globally available after `onGameInit` has been invoked, but changing them has only an effect in `onGameInit`.
Most game 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.
For a list of game variables that can be set here, see [LuaGlobals#Game_variables].
-== onGameStart() ==
+=== onGameStart() ===
This function is called when the first round starts.
Can be used to show the mission and for more setup, for example initial target spawning.
At this stage, the global variables `LeftX`, `RightX`, `TopY`, `LAND_WIDTH` and `LAND_HEIGHT` become available.
-== onPreviewInit() ==
+=== onPreviewInit() ===
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.
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.
-== onParameters() ==
+=== onParameters() ===
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`.
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.
@@ -34,23 +35,29 @@
*Tip*: If you use this callback, make sure to document the interpretation of the parameters so others know how to set the parameters properly.
-== onGameTick() ==
+=== onAmmoStoreInit() ===
+This function is called when the game is initialized to request the available ammo and ammo probabilities. Use `SetAmmo` here.
+
+=== onNewAmmoStore(team/clan index, hog index) ===
+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.
+If `gfSharedAmmo` is set, the parameters passed are the clan index, and `-1`, and the function will be called once for each clan.
+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.
+If neither is set, the parameters passed are the team index and `-1`, and the function will be called once for each team.
+
+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.
+If you add this hook, the expectation is that you will call SetAmmo appropriately. Any values from `onAmmoStoreInit` are ignored.
+
+== Game events ==
+=== onGameTick() ===
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`.
-== onGameTick20() ==
+=== onGameTick20() ===
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.
-== onNewTurn() ==
+=== onNewTurn() ===
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`)
-== onCaseDrop(gear) (1.0.0) ==
-This function calls between two turns right after the moment at which the game *might* drop a crate according to the game scheme settings. It does not matter if it actually wants to drop a crate.
-
-If a crate was dropped, `gear` is the crate gear that was dropped, if no crate was dropped, `gear` is `nil`.
-
-This function is useful to add custom crate drops as well.
-
-== onEndTurn() (0.9.24) ==
+=== onEndTurn() (0.9.24) ===
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.
`CurrentHedgehog` holds the gear ID of the hedgehog whose turn just ended.
@@ -59,119 +66,88 @@
Because this function is called *before* victories are checked, this is useful to set up your victory conditions here.
-== onSkipTurn() (0.9.24) ==
+=== onSkipTurn() (0.9.24) ===
This function calls when a hog skips its turn.
-== onGameResult(winningClan) (0.9.25) ==
+=== onCaseDrop(gear) (1.0.0) ===
+This function calls between two turns right after the moment at which the game *might* drop a crate according to the game scheme settings. It does not matter if it actually wants to drop a crate.
+
+If a crate was dropped, `gear` is the crate gear that was dropped, if no crate was dropped, `gear` is `nil`.
+
+This function is useful to add custom crate drops as well.
+
+=== onGameResult(winningClan) (0.9.25) ===
This function calls when the game ends with a winner or in a draw. If a clan wins, `winningClan` is the clan ID of the winning clan. If the game ends in a draw, `winningClan` is set to -1.
-== onSuddenDeath() ==
+=== onSuddenDeath() ===
This function is called on the start of Sudden Death.
-== onGearAdd(gearUid) ==
-This function is called when a new gear is added. Useful in combination with `GetGearType(gearUid)`.
-
-== onGearDelete(gearUid) ==
-This function is called when a new gear is deleted. Useful in combination with `GetGearType(gearUid)`.
+=== onUsedAmmo(ammoType) ===
+Called after a weapon has been used completely, with `ammoType` as the used ammo type.
-== onVisualGearAdd(vgUid) ==
-This function is called when a new visual gear is added. Useful in combination with `GetVisualGearType(vgUid)`.
-
-== onVisualGearDelete(vgUid) ==
-This function is called when a new visual gear is deleted. Useful in combination with `GetVisualGearType(vgUid)`.
-
-== onGearDamage(gearUid, damage) ==
-This function is called when a gear is damaged.
-
-Example:
+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.
- function onGearDamage(gear, damage)
- if (GetGearType(gear) == gtHedgehog) then
- -- adds a message saying, e.g. "Hoggy H took 25 points of damage"
- AddCaption(GetHogName(gear) .. ' took ' .. damage .. ' points of damage')
- end
- end
-== onGearResurrect(gearUid, spawnedVGear) ==
-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.
-
-`spawnedVGear` is a visual gear handle of the “resurrection effect”. You can use this handle to modify or delete the resurrection animation.
-
-== onAmmoStoreInit() ==
-This function is called when the game is initialized to request the available ammo and ammo probabilities. Use `SetAmmo` here.
+*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.
-== onNewAmmoStore(team/clan index, hog index) ==
-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.
-If `gfSharedAmmo` is set, the parameters passed are the clan index, and `-1`, and the function will be called once for each clan.
-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.
-If neither is set, the parameters passed are the team index and `-1`, and the function will be called once for each team.
-
-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.
-If you add this hook, the expectation is that you will call SetAmmo appropriately. Any values from `onAmmoStoreInit` are ignored.
-
-== onGearWaterSkip(gear) ==
-This function is called when the gear `gear` skips over water.
-
-== onScreenResize() ==
-This function is called when you resize the screen. Useful place to put a redraw function for any `vgtHealthTags` you're using.
-
-== onAttack() ==
+== Controls ==
+=== onAttack() ===
This function is called when your Hedgehog attacks.
-== onHJump() ==
+=== onHJump() ===
This function is called when you press the high jump key.
-== onLJump() ==
+=== onLJump() ===
This function is called when you press the long jump key.
-== onPrecise() ==
+=== onPrecise() ===
This function is called when you press the precise key.
-== onLeft() ==
+=== onLeft() ===
This function is called when you press the left key.
-== onRight() ==
+=== onRight() ===
This function is called when you press the right key.
-== onUp() ==
+=== onUp() ===
This function is called when you press the up key.
-== onDown() ==
+=== onDown() ===
This function is called when you press the down key.
-== onAttackUp() ==
+=== onAttackUp() ===
This function is called when you release the attack key.
-== onDownUp() ==
+=== onDownUp() ===
This function is called when you release the down key.
-== onHogAttack(ammoType) ==
+=== onHogAttack(ammoType) ===
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.
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.
-== onLeftUp() ==
+=== onLeftUp() ===
This function is called when you release the left key.
-== onPreciseUp() ==
+=== onPreciseUp() ===
This function is called when you release the precise key.
-== onRightUp() ==
+=== onRightUp() ===
This function is called when you release the right key.
-== onSetWeapon(msgParam) ==
+=== onSetWeapon(msgParam) ===
It is get called when a weapon is selected or switched.
`msgParam` tells you which ammo type was selected.
-== onSlot(msgParam) ==
+=== onSlot(msgParam) ===
This function is called when one of the weapon slot keys has been pressed.
`msgParam` tells the slot number minus 1 (i.e. `0` is for slot number 1, `1` is for slot number 2, etc.).
-== onSwitch() ==
+=== onSwitch() ===
This function is called when a hog is switched to another.
-== onTaunt(msgParam) ==
+=== onTaunt(msgParam) ===
This function is called when the player uses an animated emote for example by using the chat commands `/wave`, `/juggle`, etc.
`msgParam` tells you which animation was played:
@@ -185,48 +161,77 @@
|| 5 || Shrug || `/shrug` ||
|| 6 || Juggling || `/juggle` ||
-== onTimer(msgParam) ==
+=== onTimer(msgParam) ===
This function is called when one of the timer keys is pressed.
`msgParams` tells the set timer in seconds (i.e. `3` for the 3 seconds timer key).
-== onUpUp() ==
+=== onUpUp() ===
This function is called when you release the up key.
-== onUsedAmmo(ammoType) ==
-Called after a weapon has been used completely, with `ammoType` as the used ammo type.
+=== onScreenResize() ===
+This function is called when you resize the screen. Useful place to put a redraw function for any `vgtHealthTags` you're using.
+
+== Gears ==
+=== onGearAdd(gearUid) ===
+This function is called when a new gear is added. Useful in combination with `GetGearType(gearUid)`.
+
+=== onGearDelete(gearUid) ===
+This function is called when a new gear is deleted. Useful in combination with `GetGearType(gearUid)`.
+
+=== onVisualGearAdd(vgUid) ===
+This function is called when a new visual gear is added. Useful in combination with `GetVisualGearType(vgUid)`.
+
+=== onVisualGearDelete(vgUid) ===
+This function is called when a new visual gear is deleted. Useful in combination with `GetVisualGearType(vgUid)`.
-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.
+=== onGearDamage(gearUid, damage) ===
+This function is called when a gear is damaged.
+
+Example:
-*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.
+ function onGearDamage(gear, damage)
+ if (GetGearType(gear) === gtHedgehog) then
+ -- adds a message saying, e.g. "Hoggy H took 25 points of damage"
+ AddCaption(GetHogName(gear) .. ' took ' .. damage .. ' points of damage')
+ end
+ end
+=== onGearResurrect(gearUid, spawnedVGear) ===
+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.
-== onHogHide(gearUid) ==
+`spawnedVGear` is a visual gear handle of the “resurrection effect”. You can use this handle to modify or delete the resurrection animation.
+
+=== onGearWaterSkip(gear) ===
+This function is called when the gear `gear` skips over water.
+
+=== onHogHide(gearUid) ===
This function is called when a hedgehog with the gear ID `gearUid` is hidden (removed from the map).
-== onHogRestore(gearUid) ==
+=== onHogRestore(gearUid) ===
This function is called when a hedgehog with the specified gear ID `gearUid` is restored (unhidden).
-== onSpritePlacement(spriteId, centerX, centerY) ==
+== Map changes ==
+=== onSpritePlacement(spriteId, centerX, centerY) ===
This function is called when a [Sprites Sprite] has been placed.
`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.
-== onGirderPlacement(frameIdx, centerX, centerY) ==
+=== onGirderPlacement(frameIdx, centerX, centerY) ===
This function is called when a girder has been placed.
`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.
-== onRubberPlacement(frameIdx, centerX, centerY) ==
+=== onRubberPlacement(frameIdx, centerX, centerY) ===
This function is called when a rubber has been placed.
`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.
-== onSpecialPoint(x, y, flags) ==
+=== onSpecialPoint(x, y, flags) ===
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.
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.
This function is used in Racer and !TechRacer to define waypoints.
-== onAchievementsDeclaration() ==
-This function is called after the stats for the stats screen (after the game) have been generated. You are supposed to call `DeclareAchievement` here.
-
+== Achievements ==
+=== onAchievementsDeclaration() ===
+This function is called after the stats for the stats screen (after the game) have been generated. You are supposed to call `DeclareAchievement` here.
\ No newline at end of file