LuaGuide.wiki
changeset 1805 d18970cf6ca2
parent 1747 8269ec3e5bfc
child 1810 886f6f056e42
equal deleted inserted replaced
1804:396f8204b9fb 1805:d18970cf6ca2
    61 
    61 
    62 == The initiation events ==
    62 == The initiation events ==
    63 
    63 
    64 The two most important event handlers are `onGameInit` and `onAmmoStoreInit`. They are used instead of loading a game scheme and weapon scheme and in campaign missions or standalone missions `onGameInit` is also used to add teams and hogs.
    64 The two most important event handlers are `onGameInit` and `onAmmoStoreInit`. They are used instead of loading a game scheme and weapon scheme and in campaign missions or standalone missions `onGameInit` is also used to add teams and hogs.
    65 
    65 
    66 First we have `onGameInit`. On this event we should add all game modifiers and team setup. If you are making a mission you only need to specify the things you want to change on this event, everything not changed will be set to default. The available game modifiers can be found here: [LuaAPI#onGameInit()]
    66 First we have `onGameInit`. On this event we should add all game modifiers and team setup. If you are making a mission you only need to specify the things you want to change on this event, everything not changed will be set to default. The available game modifiers can be found here: [LuaEvents#onGameInit()]
    67 
    67 
    68 An example of setting up Barrel Mayhem in a style:
    68 An example of setting up Barrel Mayhem in a style:
    69 {{{
    69 {{{
    70 function onGameInit()
    70 function onGameInit()
    71     GameFlags = gfRandomOrder + gfSharedAmmo
    71     GameFlags = gfRandomOrder + gfSharedAmmo
    80 If you are doing a training or campaign mission you should also set `Seed`, `Map` and `Theme`. But you must also add teams and hogs on this event. This is done by using `AddTeam` and `AddHog`. An example of adding one team with one hog (these functions may only be used here):
    80 If you are doing a training or campaign mission you should also set `Seed`, `Map` and `Theme`. But you must also add teams and hogs on this event. This is done by using `AddTeam` and `AddHog`. An example of adding one team with one hog (these functions may only be used here):
    81 {{{
    81 {{{
    82 AddTeam("Team", 0xFF0002, "Simple", "Island", "Default", "hedgewars")
    82 AddTeam("Team", 0xFF0002, "Simple", "Island", "Default", "hedgewars")
    83 AddHog("Hedgehog", 0, 1, "NoHat")
    83 AddHog("Hedgehog", 0, 1, "NoHat")
    84 }}}
    84 }}}
    85 To be able to play you must add another team and hog that should have another team color (this team has `0xFF0002`) or if you only want one team add the game flag `gfOneClanMode`. Look into [LuaAPI] to see what the other parameters of `AddTeam` and `AddHog` are.
    85 To be able to play you must add another team and hog that should have another team color (this team has `0xFF0002`) or if you only want one team add the game flag `gfOneClanMode`. Look into [LuaGameplay] and [LuaGears] to see what the other parameters of `AddTeam` and `AddHog` are.
    86 
    86 
    87 In `onAmmoStoreInit` you set what weapons is available in the game. For every weapon run [LuaAPI#SetAmmo_(ammoType,_count,_probability,_delay,_numberInCrate) SetAmmo].
    87 In `onAmmoStoreInit` you set what weapons is available in the game. For every weapon, run `SetAmmo` (see [LuaGameplay]).
    88 This is used to set both starting weapons and weapons found in crates.
    88 This is used to set both starting weapons and weapons found in crates.
    89 
    89 
    90 Here is an example of the initiation of a training mission:
    90 Here is an example of the initiation of a training mission:
    91 {{{
    91 {{{
    92 function onGameInit()
    92 function onGameInit()
   116 The hogs are gears, too and when you shoot with bazooka the bazooka shell will be created and explode when it hits the ground. When the shell is created the `onGearAdd` event is called and the `gear` parameter will be the bazooka.
   116 The hogs are gears, too and when you shoot with bazooka the bazooka shell will be created and explode when it hits the ground. When the shell is created the `onGearAdd` event is called and the `gear` parameter will be the bazooka.
   117 And when it hits the ground, before the gear has been deleted, `onGearDelete` is invoked with the shell as parameter, after that it is removed.
   117 And when it hits the ground, before the gear has been deleted, `onGearDelete` is invoked with the shell as parameter, after that it is removed.
   118 
   118 
   119 Each gear has a [GearTypes gear type], for instance, a bazooka shell has the gear type of `gtShell`, a grenade has a gear type of `gtGrenade`, and so on. You will almost always need to check for the gear type with `GetGearType` in the `onGearAdd` function in order to do anything meaningful.
   119 Each gear has a [GearTypes gear type], for instance, a bazooka shell has the gear type of `gtShell`, a grenade has a gear type of `gtGrenade`, and so on. You will almost always need to check for the gear type with `GetGearType` in the `onGearAdd` function in order to do anything meaningful.
   120 
   120 
   121 Gears also have a lot of various values to track their position, state, etc. These can be accessed and written to with several “getter” and “setter” functions like `GetPos`, `GetHealth`, `SetTag`, etc. See [LuaAPI] for a full list. In Hedgewars, the gear values and some variable names do not always really mean what they seem to be, their concrete meaning often depends on the actual gear type. For instance, using `GetHealth(h)` on a hedgehog gear (gear type: `gtHedgehog`) will return its health (obviously). Less obviously, using `GetHealth` on a flying saucer gear (gear type: `gtJetpack`) will return its amount of fuel.
   121 Gears also have a lot of various values to track their position, state, etc. These can be accessed and written to with several “getter” and “setter” functions like `GetPos`, `GetHealth`, `SetTag`, etc. See [LuaGears] for a full list. In Hedgewars, the gear values and some variable names do not always really mean what they seem to be, their concrete meaning often depends on the actual gear type. For instance, using `GetHealth(h)` on a hedgehog gear (gear type: `gtHedgehog`) will return its health (obviously). Less obviously, using `GetHealth` on a flying saucer gear (gear type: `gtJetpack`) will return its amount of fuel.
   122 
   122 
   123 To learn all the gory detaily about gears, see [GearTypes].
   123 To learn all the gory detaily about gears, see [GearTypes].
   124 
   124 
   125 == Other important event handlers ==
   125 == Other important event handlers ==
   126 
   126 
   136 
   136 
   137 A good way to learn Lua scripting in Hedgewars is to read existing scripts. We recommend to take a look into `Data/Missions/Training/Basic_Training_-_Sniper_Rifle.lua` which is the Lua script for the Sniper Rifle target practice training mission. It should give you a rough “feeling” of how a script is supposed to look and is heavily commented.
   137 A good way to learn Lua scripting in Hedgewars is to read existing scripts. We recommend to take a look into `Data/Missions/Training/Basic_Training_-_Sniper_Rifle.lua` which is the Lua script for the Sniper Rifle target practice training mission. It should give you a rough “feeling” of how a script is supposed to look and is heavily commented.
   138 
   138 
   139 Continue with the following pages to learn more:
   139 Continue with the following pages to learn more:
   140 
   140 
   141  * [LuaAPI] contains a reference of most available functions and global variables
   141  * [LuaAPI] is the central landing page for everything about the Lua API
   142  * [Missions] for a more in-depth guide on how to create missions
   142  * [Missions] for a more in-depth guide on how to create missions
   143  * [LuaLibraries] contains information about “libraries”, that is, extra scripts you can include for even more functions. One common library is `Locale` for making a mission translatable
   143  * [LuaLibraries] contains information about “libraries”, that is, extra scripts you can include for even more functions. One common library is `Locale` for making a mission translatable
   144  * [GearTypes] contains the list of all gear types, along with an explanation of how the gears and their values work
   144  * [GearTypes] contains the list of all gear types, along with an explanation of how the gears and their values work