3011
|
1 |
-- Hedgewars Shotgun Training
|
|
2 |
-- Scripting Example
|
|
3 |
|
|
4 |
-- Lines such as this one are comments - they are ignored
|
|
5 |
-- by the game, no matter what kind of text is in there.
|
|
6 |
-- It's also possible to place a comment after some real
|
|
7 |
-- instruction as you see below. In short, everything
|
|
8 |
-- following "--" is ignored.
|
|
9 |
|
|
10 |
---------------------------------------------------------------
|
|
11 |
-- At first we put all text we'd like to use in some arrays.
|
|
12 |
-- This way we're able to localize the text to be shown without
|
|
13 |
-- modifying other files.
|
|
14 |
-- The language to be used is stored in the global variable
|
|
15 |
-- 'L' that is set by the game (string).
|
|
16 |
-- Text may then be accessed using "arrayname[L]".
|
|
17 |
|
|
18 |
local caption = {
|
|
19 |
["en"] = "Bazooka Training",
|
3013
|
20 |
["de"] = "Bazooka-Training",
|
|
21 |
["es"] = "Entrenamiento con escopeta"
|
3011
|
22 |
-- To add other languages, just add lines similar to the
|
|
23 |
-- existing ones - don't forget the trailing ","!
|
|
24 |
}
|
|
25 |
|
|
26 |
local subcaption = {
|
|
27 |
["en"] = "Aiming Practice",
|
3013
|
28 |
["de"] = "Zielübung",
|
|
29 |
["es"] = "Practica tu puntería"
|
3011
|
30 |
}
|
|
31 |
|
|
32 |
local goal = {
|
|
33 |
["en"] = "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.",
|
3013
|
34 |
["de"] = "Eliminiere alle Ziele bevor die Zeit ausläuft.|Du hast in dieser Mission unbegrenzte Munition.",
|
|
35 |
["es"] = "Destruye todos los objetivos antes de que se agote el tiempo.|La munición en esta misión es ilimitada."
|
3011
|
36 |
}
|
|
37 |
|
|
38 |
local timeout = {
|
|
39 |
["en"] = "Oh no! Time's up! Just try again.",
|
3013
|
40 |
["de"] = "Oh nein! Die Zeit ist um! Versuche es nochmal.",
|
|
41 |
["es"] = "¡Oh, no, se te acabó el tiempo! ¿Por qué no lo intentas de nuevo?"
|
3011
|
42 |
}
|
|
43 |
|
|
44 |
local success = {
|
|
45 |
["en"] = "Congratulations! You've eliminated all targets|within the allowed time frame.",
|
3013
|
46 |
["de"] = "Gratulation! Du hast alle Ziele innerhalb der|verfügbaren Zeit ausgeschaltet.",
|
|
47 |
["es"] = "¡Felicidades! Has destruido todos los objectivos|dentro del tiempo establecido."
|
3011
|
48 |
}
|
|
49 |
|
|
50 |
local teamname = {
|
|
51 |
["en"] = "Shotgun Team",
|
3013
|
52 |
["de"] = "Die Knalltüten",
|
|
53 |
["es"] = "Escopeteros"
|
3011
|
54 |
}
|
|
55 |
|
|
56 |
local hogname = {
|
|
57 |
["en"] = "Hunter",
|
3013
|
58 |
["de"] = "Jäger",
|
|
59 |
["es"] = "Cazador"
|
3011
|
60 |
}
|
|
61 |
|
|
62 |
-- To handle missing texts we define a small wrapper function that
|
|
63 |
-- we'll use to retrieve text.
|
|
64 |
local function loc(text)
|
|
65 |
if text == nil then return "**missing**"
|
|
66 |
elseif text[L] == nil then return text["en"]
|
|
67 |
else return text[L]
|
|
68 |
end
|
|
69 |
end
|
|
70 |
|
|
71 |
---------------------------------------------------------------
|
|
72 |
|
|
73 |
-- This variable will hold the number of destroyed targets.
|
|
74 |
local score = 0
|
|
75 |
-- This variable represents the number of targets to destroy.
|
|
76 |
local score_goal = 5
|
|
77 |
-- This variable controls how many milliseconds/ticks we'd
|
|
78 |
-- like to wait before we end the round once all targets
|
|
79 |
-- have been destroyed.
|
|
80 |
local end_timer = 5000 -- 5000 ms = 5 s
|
|
81 |
-- This variable is set to true if the game is lost (i.e.
|
|
82 |
-- time runs out).
|
|
83 |
local game_lost = false
|
|
84 |
-- This variable will point to the hog's gear
|
|
85 |
local player = nil
|
|
86 |
-- This variable will grab the time left at the end of the round
|
|
87 |
local time_goal = 0
|
|
88 |
|
|
89 |
-- This is a custom function to make it easier to
|
|
90 |
-- spawn more targets with just one line of code
|
|
91 |
-- You may define as many custom functions as you
|
|
92 |
-- like.
|
|
93 |
function spawnTarget()
|
|
94 |
-- add a new target gear
|
|
95 |
gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
|
|
96 |
|
|
97 |
-- move it to a random position within 0 and
|
|
98 |
-- LAND_WIDTH - the width of the map
|
|
99 |
FindPlace(gear, true, 0, LAND_WIDTH)
|
|
100 |
|
|
101 |
-- move the target to a higher vertical position
|
|
102 |
-- to ensure it's not somewhere down below
|
|
103 |
x, y = GetGearPosition(gear)
|
|
104 |
SetGearPosition(gear, x, 500)
|
|
105 |
end
|
|
106 |
|
|
107 |
-- This function is called before the game loads its
|
|
108 |
-- resources.
|
|
109 |
-- It's one of the predefined function names that will
|
|
110 |
-- be called by the game. They give you entry points
|
|
111 |
-- where you're able to call your own code using either
|
|
112 |
-- provided instructions or custom functions.
|
|
113 |
function onGameInit()
|
|
114 |
-- At first we have to overwrite/set some global variables
|
|
115 |
-- that define the map, the game has to load, as well as
|
|
116 |
-- other things such as the game rules to use, etc.
|
|
117 |
-- Things we don't modify here will use their default values.
|
|
118 |
|
|
119 |
-- The base number for the random number generator
|
|
120 |
Seed = 0
|
|
121 |
-- Game settings and rules
|
|
122 |
GameFlags = gfMultiWeapon + gfOneClanMode
|
|
123 |
-- The time the player has to move each round (in ms)
|
|
124 |
TurnTime = 25000
|
|
125 |
-- The frequency of crate drops
|
|
126 |
CaseFreq = 0
|
|
127 |
-- The number of mines being placed
|
|
128 |
LandAdds = 0
|
|
129 |
-- The number of explosives being placed
|
|
130 |
Explosives = 0
|
|
131 |
-- The delay between each round
|
|
132 |
Delay = 0
|
|
133 |
-- The map to be played
|
3080
|
134 |
Map = "Mushrooms"
|
3011
|
135 |
-- The theme to be used
|
3080
|
136 |
Theme = "Nature"
|
3011
|
137 |
|
|
138 |
-- Create the player team
|
|
139 |
AddTeam(loc(teamname), 14483456, "Simple", "Island", "Default")
|
|
140 |
-- And add a hog to it
|
|
141 |
player = AddHog(loc(hogname), 0, 1, "NoHat")
|
|
142 |
SetGearPosition(player, 2334, 1254);
|
|
143 |
end
|
|
144 |
|
|
145 |
-- This function is called when the round starts
|
|
146 |
-- it spawns the first target that has to be destroyed.
|
|
147 |
-- In addition it shows the scenario goal(s).
|
|
148 |
function onGameStart()
|
|
149 |
-- Spawn the first target.
|
|
150 |
spawnTarget()
|
|
151 |
|
|
152 |
-- Show some nice mission goals.
|
|
153 |
-- Parameters are: caption, sub caption, description,
|
|
154 |
-- extra text, icon and time to show.
|
|
155 |
-- A negative icon parameter (-n) represents the n-th weapon icon
|
|
156 |
-- A positive icon paramter (n) represents the (n+1)-th mission icon
|
|
157 |
-- A timeframe of 0 is replaced with the default time to show.
|
|
158 |
ShowMission(loc(caption), loc(subcaption), loc(goal), -amShotgun, 0);
|
|
159 |
end
|
|
160 |
|
|
161 |
-- This function is called every game tick.
|
|
162 |
-- Note that there are 1000 ticks within one second.
|
|
163 |
-- You shouldn't try to calculate too complicated
|
|
164 |
-- code here as this might slow down your game.
|
|
165 |
function onGameTick()
|
|
166 |
-- If time's up, set the game to be lost.
|
|
167 |
-- We actually check the time to be "1 ms" as it
|
|
168 |
-- will be at "0 ms" right at the start of the game.
|
|
169 |
if TurnTimeLeft == 1 and score < score_goal then
|
|
170 |
game_lost = true
|
|
171 |
-- ... and show a short message.
|
|
172 |
ShowMission(loc(caption), loc(subcaption), loc(timeout), -amSkip, 0);
|
|
173 |
-- How about killing our poor hog due to his poor performance?
|
|
174 |
SetHealth(player, 0);
|
|
175 |
-- Just to be sure set the goal time to 1 ms
|
|
176 |
time_goal = 1
|
|
177 |
end
|
|
178 |
-- If the goal is reached or we've lost ...
|
|
179 |
if score == score_goal or game_lost then
|
|
180 |
-- ... check to see if the time we'd like to
|
|
181 |
-- wait has passed and then ...
|
|
182 |
if end_timer == 0 then
|
|
183 |
-- ... end the game ...
|
|
184 |
EndGame()
|
|
185 |
else
|
|
186 |
-- ... or just lower the timer by 1.
|
|
187 |
end_timer = end_timer - 1
|
|
188 |
-- Reset the time left to stop the timer
|
|
189 |
TurnTimeLeft = time_goal
|
|
190 |
end
|
|
191 |
end
|
|
192 |
end
|
|
193 |
|
|
194 |
-- This function is called when the game is initialized
|
|
195 |
-- to request the available ammo and probabilities
|
|
196 |
function onAmmoStoreInit()
|
|
197 |
-- add an unlimited supply of shotgun ammo
|
|
198 |
SetAmmo(amShotgun, 9, 0, 0)
|
|
199 |
end
|
|
200 |
|
|
201 |
-- This function is called when a new gear is added.
|
|
202 |
-- We don't need it for this training, so we can
|
|
203 |
-- keep it empty.
|
|
204 |
function onGearAdd(gear)
|
|
205 |
end
|
|
206 |
|
|
207 |
-- This function is called before a gear is destroyed.
|
|
208 |
-- We use it to count the number of targets destroyed.
|
|
209 |
function onGearDelete(gear)
|
|
210 |
-- We're only interested in target gears.
|
|
211 |
if GetGearType(gear) == gtTarget then
|
|
212 |
-- Add one point to our score/counter
|
|
213 |
score = score + 1
|
|
214 |
-- If we haven't reached the goal ...
|
|
215 |
if score < score_goal then
|
|
216 |
-- ... spawn another target.
|
|
217 |
spawnTarget()
|
|
218 |
else
|
|
219 |
if not game_lost then
|
|
220 |
-- Otherwise show that the goal was accomplished
|
|
221 |
ShowMission(loc(caption), loc(subcaption), loc(success), 0, 0);
|
|
222 |
-- Also let the hogs shout "victory!"
|
|
223 |
PlaySound(sndVictory)
|
|
224 |
-- Save the time left so we may keep it.
|
|
225 |
time_goal = TurnTimeLeft
|
|
226 |
end
|
|
227 |
end
|
|
228 |
end
|
|
229 |
end |