LuaAPI.wiki
changeset 860 a7ddaecf54f3
parent 859 16f26a7c87d9
child 861 ccbc115e68ad
equal deleted inserted replaced
859:16f26a7c87d9 860:a7ddaecf54f3
   137 
   137 
   138 == Event handlers ==
   138 == Event handlers ==
   139 Lua scripts are supposed to _define_ these functions to do something. The functions are then _called_ by Hedgewars when a certain even has occoured.
   139 Lua scripts are supposed to _define_ these functions to do something. The functions are then _called_ by Hedgewars when a certain even has occoured.
   140 
   140 
   141 === <tt>onGameInit()</tt> ===
   141 === <tt>onGameInit()</tt> ===
   142 This function is called before the game loads its resources. One can modify various game variables here:
   142 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`.
   143  * <tt>Seed = 0</tt> - seed of the random number generator
   143 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.
   144  * <tt>!GameFlags</tt> - all !GameFlags combined as a bitmask. See [LuaAPI#GameFlags_functions] for easier manipulation of !GameFlags
   144 
   145  * <tt>Ready = 5000</tt> - the ready timer at the start of the round (in milliseconds)
   145 List of game variables:
   146  * <tt>Delay = 0</tt> - delay between each round in ms
   146 || *Variable name* || *Default* || *Description ||
   147  * <tt>!GetAwayTime = 100</tt> set the retreat time in percent
   147 || `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 ||
   148  * <tt>!TurnTime = 60000</tt> - set the turn time in ms
   148 || `Map` || `""` || The image map being played or `""` if no image map is used ||
   149  * <tt>!CaseFreq = 0</tt> - frequency of crate drops
   149 || `Seed` || `0` || Seed of the random number generator ||
   150  * <tt>!HealthCaseProb = 35</tt> - chance of receiving a health crate
   150 || `MapGen` || `mgRandom` || Type of map generator. One of `mgRandom`, `mgMaze`, `mgPerlin`, `mgDrawn`. ||
   151  * <tt>!HealthCaseAmount = 25</tt> - amount of health in a health crate
   151 || `TemplateFilter` || `0` || _unknown meaning_ ||
   152  * <tt>!DamagePercent = 100</tt> - percent of damage to inforce
   152 || `TemplateNumber` || `0` || _unknown meaning_ ||
   153  * <tt>!RopePercent = 100</tt> - rope length in percent
   153 || `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). ||
   154  * <tt>!MinesNum = 0</tt> - number of mines being placed (before 0.9.14 !LandAdds)
   154 || `GameFlags` || `0` || All `GameFlags` combined as a bitmask. See [LuaAPI#GameFlags_functions] for easier manipulation of `GameFlags` ||
   155  * <tt>!MinesTime = 3000</tt> - time for a mine to explode from activated (in milliseconds), -1000 for random
   155 || `Ready` || `5000` || Ready timer at the start of the turn (in milliseconds) ||
   156  * <tt>!MineDudPercent = 0</tt> - chance of mine being a dud
   156 || `Delay` || `100` || Delay between each turn in milliseconds ||
   157  * <tt>Explosives = 0</tt> - number of explosives being placed
   157 || `TurnTime` || `45000` || Turn time in milliseconds ||
   158  * <tt>!SuddenDeathTurns = 30</tt> - turns until sudden death begins
   158 || `GetAwayTime` || `100` || Retreat time in percent ||
   159  * <tt>!WaterRise = 47</tt> - height of water rise at sudden death in pixels
   159 || `CaseFreq` || `5` || Probability that a crate drops in a turn. 0: never, >0: probability = `1/CaseFreq` ||
   160  * <tt>!HealthDecrease = 5</tt> - amount of health decreased on sudden death
   160 || `HealthCaseProb` || `35` || Chance that a crate drop is a health crate, in percent (other crates are ammo or utility crates) ||
   161  * <tt>Map = "Bamboo"</tt> - the map being played
   161 || `HealthCaseAmount` || `25` || Amount of health in a health crate ||
   162  * <tt>Theme = "Bamboo"</tt> - the theme to be used
   162 || `DamagePercent` || `100` || Global damage in percent, affects damage and knockback ||
   163  * <tt>!MapGen</tt> - type of map generator. One of `mgRandom`, `mgMaze`, `mgPerlin`, `mgDrawn`.
   163 || `RopePercent` || `100` || Rope length in percent ||
   164  * <tt>Goals = "Jumping is disabled"</tt> - 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.
   164 || `MinesNum` || `4` || Number of mines being placed on a medium-sized map ||
   165  * <tt>!TemplateFilter</tt> - _unknown meaning_
   165 || `MinesTime` || `3000` || Time for a mine to explode from activated (in milliseconds), `-1000` for random ||
   166  * <tt>!TemplateNumber</tt> - _unknown meaning_
   166 || `MineDudPercent` || `0` || Chance of mine being a dud, in percent ||
   167  * <tt>!MapFeatureSize</tt> - 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).
   167 || `Explosives` || `2` || Number of barrels being placed on a medium-sized map ||
   168  * <tt>!ScreenWidth</tt> - width of the Hedgewars window
   168 || `SuddenDeathTurns` || `15` || Turns until Sudden Death begins ||
   169  * <tt>!ScreenHeight</tt> - heigtht of the Hedgewars window
   169 || `WaterRise` || `47` || Height of water rise each turn in Sudden Death, in pixels ||
   170 
   170 || `HealthDecrease || `5` || Amount of health decreased on each turn in Sudden Death ||
   171 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.
   171 || `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`. ||
       
   172 || `ScreenWidth` || _N/A_ || Width of the Hedgewars window or screen ||
       
   173 || `ScreenHeigth` || _N/A_ || Heigth of the Hedgewars window or screen ||
       
   174 
       
   175 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.
   172 
   176 
   173 === <tt>onGameStart()</tt> ===
   177 === <tt>onGameStart()</tt> ===
   174 This function is called when the first round starts.
   178 This function is called when the first round starts.
   175 
   179 
   176 Can be used to show the mission and for more setup, for example initial target spawning.
   180 Can be used to show the mission and for more setup, for example initial target spawning.