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