LuaLibraries.wiki
changeset 532 8b7a9c032722
parent 531 5628b472ab0d
child 587 8105e95297e3
equal deleted inserted replaced
531:5628b472ab0d 532:8b7a9c032722
   345 If the key-value pair `myparam1=hello` is present, this script writes “Hello World!” in the console. All these inputs would trigger the event:
   345 If the key-value pair `myparam1=hello` is present, this script writes “Hello World!” in the console. All these inputs would trigger the event:
   346 
   346 
   347 <code>myparam1=hello</code>
   347 <code>myparam1=hello</code>
   348 <code>myparam2=whatever, myparam1=hello</code>
   348 <code>myparam2=whatever, myparam1=hello</code>
   349 <code>g=4, f=56, m=56, myparam1=hello</code>
   349 <code>g=4, f=56, m=56, myparam1=hello</code>
       
   350 
       
   351 
       
   352 
       
   353 = !TargetPractice =
       
   354 Starting with 0.9.21, this library provides a function to create an entire target practice mission which follows some basic properties.
       
   355 
       
   356 Here is a brief description of the generated missions:
       
   357  * The player will get a team with a single hedgehog.
       
   358  * The team gets a single predefined weapon infinitely times.
       
   359  * A fixed sequence of targets will spawn at predefined positions.
       
   360  * When a target has been destroyed, the next target of the target sequence appears
       
   361  * The mission ends successfully when all targets have been destroyed
       
   362  * The mission ends unsuccessfully when the time runs out or the hedgehog dies
       
   363  * When the mission ends, a score is awarded, based on the performance (hit targets, accuracy and remaining time) of the hedgehog. When not all targets are hit, there will be no accuracy and time bonuses.
       
   364 
       
   365 If you want to create a more sophisticated training mission, use your own code instead. The main motivation to write this library was to reduce redundancy in existing target practice missions.
       
   366 
       
   367 Thos library also loads the Locale library for its own purposes. If you use !TargetPractice, you do not have to explicitly load Locale anymore.
       
   368 
       
   369 === `TargetPracticeMission(params)` ===
       
   370 This function sets up the *entire* training mission and needs one argument: `params`.
       
   371 `params` is a table containing fields which describe the training mission.
       
   372 
       
   373 There are mandatory and optional fields. The optional fields have default values.
       
   374 
       
   375 Mandatory fields:
       
   376 || *Field name* || *Description* ||
       
   377 || `missionTitle` || The name of the mission ||
       
   378 || `map` || The name of the image map to be used ||
       
   379 || `theme` || The name of the theme (can be background theme, too) ||
       
   380 || `time` || The time limit in milliseconds ||
       
   381 || `ammoType` || The [AmmoTypes ammo type] of the weapon to be used ||
       
   382 || `gearType` || The [GearTypes gear type] of the gear which is fired by the weapon (used to count shots) ||
       
   383 || `targets` || The coordinates of where the targets will be spawned. It is a table containing tables containing coordinates of format `{ x=value, y=value }`. The targets will be spawned in the same order as specified the coordinate tables appear. There must be at least 1 target. ||
       
   384 
       
   385 Optional fields:
       
   386 || *Field name* || *Description * ||
       
   387 || `wind` || The initial wind (`-100` to `100`) (default: `0` (no wind)) ||
       
   388 || `solidLand` || Weather the terrain is indestructible (default: `false`) ||
       
   389 || `artillery` || If `true`, the hog can’t move (default: `false`) ||
       
   390 || `hogHat` || Hat of the hedgehog (default: `"NoHat"`) ||
       
   391 || `hogName` || Name of the hedgehog (default: `"Trainee"`) ||
       
   392 || `teamName` || Name of the hedgehog’s team (default: `"Training Team"`) ||
       
   393 || `teamGrave` || Name of the hedgehog’s grave ||
       
   394 || `clanColor` || Color of the (only) clan (default: `0xFF0204`, which is a red tone) ||
       
   395 || `goalText` || A short string explaining the goal of the mission (default: `"Destroy all targets within the time!"`) ||
       
   396 || `shootText`: || A string which says how many times the player shot, “`%d`” is replaced by the number of shots. (default: `"You have shot %d times."`) ||
       
   397 
       
   398 
       
   399 ==== Example ====
       
   400 Below is the complete source code of the mission “Target Practice: Cluster Bomb”:
       
   401 
       
   402 <code language="lua">HedgewarsScriptLoad("/Scripts/TargetPractice.lua")
       
   403 
       
   404 local params = {
       
   405 	ammoType = amClusterBomb,
       
   406 	gearType = gtClusterBomb,
       
   407 	missionTitle = "Cluster Bomb Training",
       
   408 	solidLand = false,
       
   409 	map = "Trash",
       
   410 	theme = "Golf",
       
   411 	hog_x = 756,
       
   412 	hog_y = 370,
       
   413 	hogName = loc("Private Nolak"),
       
   414 	hogHat = "war_desertgrenadier1",
       
   415 	teamName = loc("The Hogies"),
       
   416 	targets = {
       
   417 		{ x = 628, y = 0 },
       
   418 		{ x = 891, y = 0 },
       
   419 		{ x = 1309, y = 0 },
       
   420 		{ x = 1128, y = 0 },
       
   421 		{ x = 410, y = 0 },
       
   422 		{ x = 1564, y = 0 },
       
   423 		{ x = 1248, y = 476 },
       
   424 		{ x = 169, y = 0 },
       
   425 		{ x = 1720, y = 0 },
       
   426 		{ x = 1441, y = 0 },
       
   427 		{ x = 599, y = 0 },
       
   428 		{ x = 1638, y = 0 },
       
   429 	},
       
   430 	time = 180000,
       
   431 	shootText = loc("You have thrown %d cluster bombs."),
       
   432 }
       
   433 
       
   434 TargetPracticeMission(params)</code>