3271
|
1 |
-- Hedgewars SniperRifle 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"] = "Sniper Training",
|
3273
|
20 |
["de"] = "Scharfschützen-Training",
|
3284
|
21 |
["es"] = "Entrenamiento con rifle francotirador",
|
3274
|
22 |
["pl"] = "Trening Snajperski",
|
3273
|
23 |
["pt_PT"] = "Treino com Sniper"
|
3271
|
24 |
-- To add other languages, just add lines similar to the
|
|
25 |
-- existing ones - don't forget the trailing ","!
|
|
26 |
}
|
|
27 |
|
|
28 |
local subcaption = {
|
|
29 |
["en"] = "Aiming Practice",
|
|
30 |
["de"] = "Zielübung",
|
|
31 |
["es"] = "Practica tu puntería",
|
|
32 |
["pl"] = "Potrenuj celność",
|
|
33 |
["pt_PT"] = "Pratica a tua pontaria"
|
|
34 |
}
|
|
35 |
|
|
36 |
local goal = {
|
|
37 |
["en"] = "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.",
|
|
38 |
["de"] = "Eliminiere alle Ziele bevor die Zeit ausläuft.|Du hast in dieser Mission unbegrenzte Munition.",
|
|
39 |
["es"] = "Destruye todos los objetivos antes de que se agote el tiempo.|La munición en esta misión es ilimitada.",
|
|
40 |
["pl"] = "Zniszcz wszystkie cele zanim upłynie czas.|W tej misji masz nieskończoną ilość amunicji.",
|
|
41 |
["pt_PT"] = "Destrói todos os alvos antes do tempo terminar.|Tens munições infinitas para esta missão."
|
|
42 |
}
|
|
43 |
|
|
44 |
local timeout = {
|
|
45 |
["en"] = "Oh no! Time's up! Just try again.",
|
|
46 |
["de"] = "Oh nein! Die Zeit ist um! Versuche es nochmal.",
|
|
47 |
["es"] = "¡Oh, no, se te acabó el tiempo! ¿Por qué no lo intentas de nuevo?",
|
|
48 |
["pl"] = "Ajajaj! Koniec czasu! Spróbuj jeszcze raz.",
|
|
49 |
["pt_PT"] = "Oh não! Acabou o tempo! Tenta novamente."
|
|
50 |
}
|
|
51 |
|
|
52 |
local success = {
|
|
53 |
["en"] = "Congratulations! You've eliminated all targets|within the allowed time frame.",
|
|
54 |
["de"] = "Gratulation! Du hast alle Ziele innerhalb der|verfügbaren Zeit ausgeschaltet.",
|
|
55 |
["es"] = "¡Felicidades! Has destruido todos los objectivos|dentro del tiempo establecido.",
|
|
56 |
["pl"] = "Gratulacje! Zniszczyłeś wszystkie cele przed upłynięciem czasu.",
|
|
57 |
["pt_PT"] = "Parabéns! Eliminaste todos os alvos|dentro do tempo limite."
|
|
58 |
}
|
|
59 |
|
|
60 |
local teamname = {
|
|
61 |
["en"] = "Sniperz",
|
3274
|
62 |
["de"] = "Heckenschützen",
|
3284
|
63 |
["es"] = "Fusileros",
|
3274
|
64 |
["pl"] = "Snajperzy"
|
3271
|
65 |
}
|
|
66 |
|
|
67 |
local hogname = {
|
|
68 |
["en"] = "Hunter",
|
|
69 |
["de"] = "Jäger",
|
3284
|
70 |
["es"] = "Francotirador",
|
3271
|
71 |
["pl"] = "Strzelec",
|
|
72 |
["pt_PT"] = "Comando"
|
|
73 |
}
|
|
74 |
|
|
75 |
-- To handle missing texts we define a small wrapper function that
|
|
76 |
-- we'll use to retrieve text.
|
|
77 |
local function loc(text)
|
|
78 |
if text == nil then return "**missing**"
|
|
79 |
elseif text[L] == nil then return text["en"]
|
|
80 |
else return text[L]
|
|
81 |
end
|
|
82 |
end
|
|
83 |
|
|
84 |
---------------------------------------------------------------
|
|
85 |
|
|
86 |
-- This variable will hold the number of destroyed targets.
|
|
87 |
local score = 0
|
|
88 |
-- This variable represents the number of targets to destroy.
|
|
89 |
local score_goal = 31
|
|
90 |
-- This variable controls how many milliseconds/ticks we'd
|
|
91 |
-- like to wait before we end the round once all targets
|
|
92 |
-- have been destroyed.
|
|
93 |
local end_timer = 5000 -- 5000 ms = 5 s
|
|
94 |
-- This variable is set to true if the game is lost (i.e.
|
|
95 |
-- time runs out).
|
|
96 |
local game_lost = false
|
|
97 |
-- This variable will point to the hog's gear
|
|
98 |
local player = nil
|
|
99 |
-- This variable will grab the time left at the end of the round
|
|
100 |
local time_goal = 0
|
|
101 |
|
|
102 |
local target = nil
|
|
103 |
|
|
104 |
local last_hit_time = 0
|
|
105 |
-- This is a custom function to make it easier to
|
|
106 |
-- spawn more targets with just one line of code
|
|
107 |
-- You may define as many custom functions as you
|
|
108 |
-- like.
|
|
109 |
function spawnTarget(x, y)
|
|
110 |
-- add a new target gear
|
|
111 |
target = AddGear(x, y, gtTarget, 0, 0, 0, 0)
|
3284
|
112 |
-- have the camera move to the target so the player knows where it is
|
|
113 |
FollowGear(target)
|
3271
|
114 |
end
|
|
115 |
|
|
116 |
function blowUp(x, y)
|
|
117 |
-- adds some TNT
|
|
118 |
gear = AddGear(x, y, gtDynamite, 0, 0, 0, 0)
|
|
119 |
end
|
|
120 |
|
|
121 |
-- This function is called before the game loads its
|
|
122 |
-- resources.
|
|
123 |
-- It's one of the predefined function names that will
|
|
124 |
-- be called by the game. They give you entry points
|
|
125 |
-- where you're able to call your own code using either
|
|
126 |
-- provided instructions or custom functions.
|
|
127 |
function onGameInit()
|
|
128 |
-- At first we have to overwrite/set some global variables
|
|
129 |
-- that define the map, the game has to load, as well as
|
|
130 |
-- other things such as the game rules to use, etc.
|
|
131 |
-- Things we don't modify here will use their default values.
|
|
132 |
|
|
133 |
-- The base number for the random number generator
|
|
134 |
Seed = 0
|
|
135 |
-- Game settings and rules
|
|
136 |
GameFlags = gfMultiWeapon + gfOneClanMode + gfArtillery
|
|
137 |
-- The time the player has to move each round (in ms)
|
|
138 |
TurnTime = 150000
|
|
139 |
-- The frequency of crate drops
|
|
140 |
CaseFreq = 0
|
|
141 |
-- The number of mines being placed
|
|
142 |
LandAdds = 0
|
|
143 |
-- The number of explosives being placed
|
|
144 |
Explosives = 0
|
|
145 |
-- The delay between each round
|
|
146 |
Delay = 0
|
|
147 |
-- The map to be played
|
|
148 |
Map = "Ropes"
|
|
149 |
-- The theme to be used
|
|
150 |
Theme = "City"
|
|
151 |
|
|
152 |
-- Create the player team
|
|
153 |
AddTeam(loc(teamname), 14483456, "Simple", "Island", "Default")
|
|
154 |
-- And add a hog to it
|
|
155 |
player = AddHog(loc(hogname), 0, 1, "Sniper")
|
|
156 |
SetGearPosition(player, 602, 1465);
|
|
157 |
end
|
|
158 |
|
|
159 |
-- This function is called when the round starts
|
|
160 |
-- it spawns the first target that has to be destroyed.
|
|
161 |
-- In addition it shows the scenario goal(s).
|
|
162 |
function onGameStart()
|
|
163 |
-- Spawn the first target.
|
|
164 |
spawnTarget(860,1020)
|
|
165 |
|
|
166 |
-- Show some nice mission goals.
|
|
167 |
-- Parameters are: caption, sub caption, description,
|
|
168 |
-- extra text, icon and time to show.
|
|
169 |
-- A negative icon parameter (-n) represents the n-th weapon icon
|
|
170 |
-- A positive icon paramter (n) represents the (n+1)-th mission icon
|
|
171 |
-- A timeframe of 0 is replaced with the default time to show.
|
|
172 |
ShowMission(loc(caption), loc(subcaption), loc(goal), -amSniperRifle, 0);
|
|
173 |
end
|
|
174 |
|
|
175 |
-- This function is called every game tick.
|
|
176 |
-- Note that there are 1000 ticks within one second.
|
|
177 |
-- You shouldn't try to calculate too complicated
|
|
178 |
-- code here as this might slow down your game.
|
|
179 |
function onGameTick()
|
3284
|
180 |
if game_lost then
|
|
181 |
return
|
|
182 |
end
|
|
183 |
-- after a target is destroyed, show hog, then target
|
|
184 |
if (target ~= nil) and (TurnTimeLeft + 1300 < last_hit_time) then
|
|
185 |
-- move camera to the target
|
|
186 |
FollowGear(target)
|
|
187 |
elseif TurnTimeLeft + 300 < last_hit_time then
|
|
188 |
-- move camera to the hog
|
|
189 |
FollowGear(player)
|
|
190 |
end
|
3271
|
191 |
-- If time's up, set the game to be lost.
|
|
192 |
-- We actually check the time to be "1 ms" as it
|
|
193 |
-- will be at "0 ms" right at the start of the game.
|
|
194 |
if TurnTimeLeft == 1 and score < score_goal then
|
|
195 |
game_lost = true
|
|
196 |
-- ... and show a short message.
|
|
197 |
ShowMission(loc(caption), loc(subcaption), loc(timeout), -amSkip, 0);
|
|
198 |
-- How about killing our poor hog due to his poor performance?
|
|
199 |
SetHealth(player, 0);
|
|
200 |
-- Just to be sure set the goal time to 1 ms
|
|
201 |
time_goal = 1
|
|
202 |
end
|
|
203 |
-- If the goal is reached or we've lost ...
|
|
204 |
if score == score_goal or game_lost then
|
|
205 |
-- ... check to see if the time we'd like to
|
|
206 |
-- wait has passed and then ...
|
|
207 |
if end_timer == 0 then
|
|
208 |
-- ... end the game ...
|
|
209 |
EndGame()
|
|
210 |
else
|
|
211 |
-- ... or just lower the timer by 1.
|
|
212 |
end_timer = end_timer - 1
|
|
213 |
-- Reset the time left to stop the timer
|
|
214 |
TurnTimeLeft = time_goal
|
|
215 |
end
|
|
216 |
end
|
|
217 |
end
|
|
218 |
|
|
219 |
-- This function is called when the game is initialized
|
|
220 |
-- to request the available ammo and probabilities
|
|
221 |
function onAmmoStoreInit()
|
|
222 |
-- add an unlimited supply of shotgun ammo
|
3346
|
223 |
SetAmmo(amSniperRifle, 9, 0, 0, 0)
|
3271
|
224 |
end
|
|
225 |
|
|
226 |
-- This function is called when a new gear is added.
|
|
227 |
-- We don't need it for this training, so we can
|
|
228 |
-- keep it empty.
|
|
229 |
function onGearAdd(gear)
|
|
230 |
end
|
|
231 |
|
|
232 |
-- This function is called before a gear is destroyed.
|
|
233 |
-- We use it to count the number of targets destroyed.
|
|
234 |
function onGearDelete(gear)
|
|
235 |
|
3284
|
236 |
if GetGearType(gear) == gtCase then
|
|
237 |
game_lost = true
|
|
238 |
return
|
|
239 |
end
|
3271
|
240 |
|
|
241 |
if (GetGearType(gear) == gtTarget) then
|
3284
|
242 |
-- remember when the target was hit for adjusting the camera
|
|
243 |
last_hit_time = TurnTimeLeft
|
3271
|
244 |
-- Add one point to our score/counter
|
|
245 |
score = score + 1
|
|
246 |
-- If we haven't reached the goal ...
|
|
247 |
if score < score_goal then
|
|
248 |
-- ... spawn another target.
|
3284
|
249 |
if score == 1 then
|
|
250 |
spawnTarget(1520,1350)
|
|
251 |
elseif score == 2 then
|
|
252 |
spawnTarget(1730,1040)
|
|
253 |
elseif score == 3 then
|
|
254 |
spawnTarget(2080,780)
|
|
255 |
elseif score == 4 then
|
|
256 |
blowUp(1730,1226)
|
|
257 |
blowUp(1440,1595)
|
|
258 |
blowUp(1527,1575)
|
|
259 |
blowUp(1614,1595)
|
|
260 |
blowUp(1420,1675)
|
|
261 |
blowUp(1527,1675)
|
|
262 |
blowUp(1634,1675)
|
|
263 |
blowUp(1440,1755)
|
|
264 |
blowUp(1527,1775)
|
|
265 |
blowUp(1614,1755)
|
|
266 |
spawnTarget(1527,1667)
|
|
267 |
elseif score == 5 then
|
|
268 |
spawnTarget(1527,1667)
|
|
269 |
elseif score == 6 then
|
|
270 |
spawnTarget(2175,1300)
|
|
271 |
elseif score == 7 then
|
|
272 |
spawnTarget(2250,940)
|
|
273 |
elseif score == 8 then
|
|
274 |
spawnTarget(2665,1540)
|
|
275 |
elseif score == 9 then
|
|
276 |
spawnTarget(3040,1160)
|
|
277 |
elseif score == 10 then
|
|
278 |
spawnTarget(2930,1500)
|
|
279 |
elseif score == 11 then
|
|
280 |
spawnTarget(700,720)
|
|
281 |
elseif score == 12 then
|
|
282 |
blowUp(914,1222)
|
|
283 |
blowUp(1050,1222)
|
|
284 |
blowUp(1160,1008)
|
|
285 |
blowUp(1160,1093)
|
|
286 |
blowUp(1160,1188)
|
|
287 |
blowUp(375,911)
|
|
288 |
blowUp(510,911)
|
|
289 |
blowUp(640,911)
|
|
290 |
blowUp(780,911)
|
|
291 |
blowUp(920,911)
|
|
292 |
blowUp(1060,913)
|
|
293 |
blowUp(1198,913)
|
|
294 |
spawnTarget(1200,730)
|
|
295 |
elseif score == 13 then
|
|
296 |
spawnTarget(1200,830)
|
|
297 |
elseif score == 14 then
|
|
298 |
spawnTarget(1430,450)
|
|
299 |
elseif score == 15 then
|
|
300 |
spawnTarget(796,240)
|
|
301 |
elseif score == 16 then
|
|
302 |
spawnTarget(300,10)
|
|
303 |
elseif score == 17 then
|
|
304 |
spawnTarget(2080,820)
|
|
305 |
elseif score == 18 then
|
|
306 |
blowUp(2110,920)
|
|
307 |
blowUp(2210,920)
|
|
308 |
blowUp(2200,305)
|
|
309 |
blowUp(2300,305)
|
|
310 |
blowUp(2300,400)
|
|
311 |
blowUp(2300,500)
|
|
312 |
blowUp(2300,600)
|
|
313 |
blowUp(2300,700)
|
|
314 |
blowUp(2300,800)
|
|
315 |
blowUp(2300,900)
|
|
316 |
blowUp(2401,305)
|
|
317 |
blowUp(2532,305)
|
|
318 |
blowUp(2663,305)
|
|
319 |
spawnTarget(2300,760)
|
|
320 |
elseif score == 19 then
|
|
321 |
spawnTarget(2300,760)
|
|
322 |
elseif score == 20 then
|
|
323 |
spawnTarget(2738,190)
|
|
324 |
elseif score == 21 then
|
|
325 |
spawnTarget(2590,-100)
|
|
326 |
elseif score == 22 then
|
|
327 |
blowUp(2790,305)
|
|
328 |
blowUp(2930,305)
|
|
329 |
blowUp(3060,305)
|
|
330 |
blowUp(3190,305)
|
|
331 |
blowUp(3310,305)
|
|
332 |
blowUp(3393,613)
|
|
333 |
blowUp(2805,370)
|
|
334 |
blowUp(2805,500)
|
|
335 |
blowUp(2805,630)
|
|
336 |
blowUp(2805,760)
|
|
337 |
blowUp(2805,890)
|
|
338 |
blowUp(2700,890)
|
|
339 |
blowUp(3258,370)
|
|
340 |
blowUp(3258,475)
|
|
341 |
blowUp(3264,575)
|
|
342 |
spawnTarget(3230,240)
|
|
343 |
elseif score == 23 then
|
|
344 |
spawnTarget(3230,290)
|
|
345 |
elseif score == 24 then
|
|
346 |
spawnTarget(3670,250)
|
|
347 |
elseif score == 25 then
|
|
348 |
spawnTarget(2620,-100)
|
|
349 |
elseif score == 26 then
|
|
350 |
spawnTarget(2870,300)
|
|
351 |
elseif score == 27 then
|
|
352 |
spawnTarget(3850,900)
|
|
353 |
elseif score == 28 then
|
|
354 |
spawnTarget(3780,300)
|
|
355 |
elseif score == 29 then
|
|
356 |
spawnTarget(3670,0)
|
|
357 |
elseif score == 30 then
|
|
358 |
spawnTarget(3480,1200)
|
|
359 |
end
|
3271
|
360 |
else
|
|
361 |
if not game_lost then
|
|
362 |
-- Otherwise show that the goal was accomplished
|
|
363 |
ShowMission(loc(caption), loc(subcaption), loc(success), 0, 0);
|
|
364 |
-- Also let the hogs shout "victory!"
|
|
365 |
PlaySound(sndVictory)
|
|
366 |
-- Save the time left so we may keep it.
|
|
367 |
time_goal = TurnTimeLeft
|
|
368 |
end
|
|
369 |
end
|
|
370 |
end
|
|
371 |
end
|