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