Back to homepage
LuaLibraryTargetPractice
History
Lua library documentation of TargetPractice; for creating simple target practice missions
LuaLibrary
Updated Fri, 21 Jun 2019 23:47:15 +0100 by Wuzzy

Lua library: TargetPractice

Starting with 0.9.21, this library provides a function to create an entire target practice mission which follows some basic properties.

Here is a brief description of the generated missions:

  • The player will get a team with a single hedgehog.
  • The team gets a single predefined weapon infinitely times.
  • A fixed sequence of targets will spawn at predefined positions.
  • When a target has been destroyed, the next target of the target sequence appears
  • The mission ends successfully when all targets have been destroyed
  • The mission ends unsuccessfully when the time runs out or the hedgehog dies
  • 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.

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.

TargetPracticeMission(params)

This function sets up the entire training mission and needs one argument: params . params is a table containing fields which describe the training mission.

There are mandatory and optional fields. The optional fields have default values.

Mandatory fields:

Field name Description
missionTitle The name of the mission
map The name of the image map to be used
theme The name of the theme (can be background theme, too)
time The time limit in milliseconds
ammoType The ammo type of the weapon to be used
gearType The gear type of the gear which is fired by the weapon (used to count shots)
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.

Optional fields:

Field name Description
wind The initial wind ( -100 to 100 ) (default: 0 (no wind))
solidLand Weather the terrain is indestructible (default: false )
artillery If true , the hog can’t move (default: false )
clanColor Color of the (only) clan (default: 0xFF0204 , which is a red tone)
goalText A short string explaining the goal of the mission (default: "Destroy all targets within the time!" )
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." )
faceLeft If true , hedgehog faces left (default: false )

Example

Below is the complete source code of the mission “Target Practice: Cluster Bomb”:

HedgewarsScriptLoad("/Scripts/TargetPractice.lua") local params = { ammoType = amClusterBomb, gearType = gtClusterBomb, missionTitle = "Cluster Bomb Training", solidLand = false, map = "Trash", theme = "Golf", hog_x = 756, hog_y = 370, targets = { { x = 628, y = 0 }, { x = 891, y = 0 }, { x = 1309, y = 0 }, { x = 1128, y = 0 }, { x = 410, y = 0 }, { x = 1564, y = 0 }, { x = 1248, y = 476 }, { x = 169, y = 0 }, { x = 1720, y = 0 }, { x = 1441, y = 0 }, { x = 599, y = 0 }, { x = 1638, y = 0 }, }, time = 180000, shootText = loc("You have thrown %d cluster bombs."), } TargetPracticeMission(params)