author | Wuzzy <Wuzzy2@mail.ru> |
Sat, 21 Oct 2017 17:21:34 +0200 | |
changeset 12727 | 23fb2179945f |
parent 12346 | fb22caa19600 |
child 12728 | 745d5c9a3abc |
permissions | -rw-r--r-- |
11015 | 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 implement the localization library using loadfile. |
|
12 |
-- This allows us to localize strings without needing to think |
|
13 |
-- about translations. |
|
14 |
-- We can use the function loc(text) to localize a string. |
|
15 |
||
16 |
HedgewarsScriptLoad("/Scripts/Locale.lua") |
|
17 |
||
18 |
-- This variable will hold the number of destroyed targets. |
|
19 |
local score = 0 |
|
20 |
-- This variable will hold the number of shots from the sniper rifle |
|
21 |
local shots = 0 |
|
22 |
-- This variable represents the number of targets to destroy. |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
23 |
local score_goal = 27 |
11015 | 24 |
-- This variable controls how many milliseconds/ticks we'd |
25 |
-- like to wait before we end the round once all targets |
|
26 |
-- have been destroyed. |
|
27 |
local end_timer = 1000 -- 1000 ms = 1 s |
|
28 |
-- This variable is set to true if the game is lost (i.e. |
|
29 |
-- time runs out). |
|
30 |
local game_lost = false |
|
31 |
-- This variable will point to the hog's gear |
|
32 |
local player = nil |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
33 |
-- Current target gear |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
34 |
local target = nil |
11015 | 35 |
-- This variable will grab the time left at the end of the round |
36 |
local time_goal = 0 |
|
37 |
||
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
38 |
-- Like score, but targets before a blow-up sequence count double. |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
39 |
-- Used to calculate final target score |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
40 |
local score_bonus = 0 |
11015 | 41 |
|
42 |
local last_hit_time = 0 |
|
11528 | 43 |
|
44 |
local cinematic = false |
|
45 |
||
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
46 |
-- Number of dynamite gears currently in game |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
47 |
local dynamiteCounter = 0 |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
48 |
|
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
49 |
-- Position for delayed targets |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
50 |
local delayedTargetTargetX, delayedTargetY |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
51 |
|
11015 | 52 |
-- This is a custom function to make it easier to |
53 |
-- spawn more targets with just one line of code |
|
54 |
-- You may define as many custom functions as you |
|
55 |
-- like. |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
56 |
|
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
57 |
-- Spawns a target at (x, y) |
11015 | 58 |
function spawnTarget(x, y) |
59 |
-- add a new target gear |
|
60 |
target = AddGear(x, y, gtTarget, 0, 0, 0, 0) |
|
61 |
-- have the camera move to the target so the player knows where it is |
|
62 |
FollowGear(target) |
|
63 |
end |
|
64 |
||
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
65 |
-- Remembers position to spawn a target at (x, y) after a dynamite explosion |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
66 |
function spawnTargetDelayed(x, y) |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
67 |
delayedTargetX = x |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
68 |
delayedTargetY = y |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
69 |
end |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
70 |
|
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
71 |
-- Cut sequence to blow up land with dynamite |
11015 | 72 |
function blowUp(x, y) |
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
73 |
if cinematic == false then |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
74 |
cinematic = true |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
75 |
SetCinematicMode(true) |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
76 |
end |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
77 |
AddGear(x, y, gtDynamite, 0, 0, 0, 0) |
11015 | 78 |
end |
79 |
||
80 |
function onNewTurn() |
|
81 |
SetWeapon(amSniperRifle) |
|
82 |
end |
|
83 |
||
84 |
-- This function is called before the game loads its |
|
85 |
-- resources. |
|
86 |
-- It's one of the predefined function names that will |
|
87 |
-- be called by the game. They give you entry points |
|
88 |
-- where you're able to call your own code using either |
|
89 |
-- provided instructions or custom functions. |
|
90 |
function onGameInit() |
|
91 |
-- At first we have to overwrite/set some global variables |
|
92 |
-- that define the map, the game has to load, as well as |
|
93 |
-- other things such as the game rules to use, etc. |
|
94 |
-- Things we don't modify here will use their default values. |
|
95 |
||
96 |
-- The base number for the random number generator |
|
97 |
Seed = 0 |
|
98 |
-- Game settings and rules |
|
99 |
GameFlags = gfMultiWeapon + gfOneClanMode + gfArtillery |
|
100 |
-- The time the player has to move each round (in ms) |
|
101 |
TurnTime = 150000 |
|
102 |
-- The frequency of crate drops |
|
103 |
CaseFreq = 0 |
|
104 |
-- The number of mines being placed |
|
105 |
MinesNum = 0 |
|
106 |
-- The number of explosives being placed |
|
107 |
Explosives = 0 |
|
108 |
-- The delay between each round |
|
109 |
Delay = 0 |
|
110 |
-- The map to be played |
|
111 |
Map = "Ropes" |
|
112 |
-- The theme to be used |
|
11017
16c47a5573e4
change theme used by sniper training, for performance reasons
sheepluva
parents:
11015
diff
changeset
|
113 |
Theme = "Golf" |
12224
d62d6f8ebef1
Disable Sudden Death consistently in all missions which don't require it
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
114 |
-- Disable Sudden Death |
d62d6f8ebef1
Disable Sudden Death consistently in all missions which don't require it
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
115 |
WaterRise = 0 |
d62d6f8ebef1
Disable Sudden Death consistently in all missions which don't require it
Wuzzy <almikes@aol.com>
parents:
12049
diff
changeset
|
116 |
HealthDecrease = 0 |
11015 | 117 |
|
118 |
-- Create the player team |
|
12049
030464f34d47
Tweak flags used in all missions to fit more to the theme
Wuzzy <almikes@aol.com>
parents:
11968
diff
changeset
|
119 |
AddTeam(loc("Sniperz"), 14483456, "Simple", "Island", "Default", "cm_crosshair") |
11015 | 120 |
-- And add a hog to it |
121 |
player = AddHog(loc("Hunter"), 0, 1, "Sniper") |
|
122 |
SetGearPosition(player, 602, 1465) |
|
123 |
end |
|
124 |
||
125 |
-- This function is called when the round starts |
|
126 |
-- it spawns the first target that has to be destroyed. |
|
127 |
-- In addition it shows the scenario goal(s). |
|
128 |
function onGameStart() |
|
129 |
-- Disable graph in stats screen |
|
130 |
SendHealthStatsOff() |
|
131 |
-- Spawn the first target. |
|
132 |
spawnTarget(860,1020) |
|
11017
16c47a5573e4
change theme used by sniper training, for performance reasons
sheepluva
parents:
11015
diff
changeset
|
133 |
|
11015 | 134 |
-- Show some nice mission goals. |
135 |
-- Parameters are: caption, sub caption, description, |
|
136 |
-- extra text, icon and time to show. |
|
137 |
-- A negative icon parameter (-n) represents the n-th weapon icon |
|
138 |
-- A positive icon paramter (n) represents the (n+1)-th mission icon |
|
139 |
-- A timeframe of 0 is replaced with the default time to show. |
|
140 |
ShowMission(loc("Sniper Training"), loc("Aiming Practice"), loc("Eliminate all targets before your time runs out.|You have unlimited ammo for this mission."), -amSniperRifle, 0) |
|
141 |
end |
|
142 |
||
143 |
-- This function is called every game tick. |
|
144 |
-- Note that there are 1000 ticks within one second. |
|
145 |
-- You shouldn't try to calculate too complicated |
|
146 |
-- code here as this might slow down your game. |
|
147 |
function onGameTick20() |
|
148 |
if game_lost then |
|
149 |
return |
|
150 |
end |
|
151 |
-- after a target is destroyed, show hog, then target |
|
152 |
if (target ~= nil) and (TurnTimeLeft + 1300 < last_hit_time) then |
|
153 |
-- move camera to the target |
|
154 |
FollowGear(target) |
|
155 |
elseif TurnTimeLeft + 300 < last_hit_time then |
|
156 |
-- move camera to the hog |
|
157 |
FollowGear(player) |
|
158 |
end |
|
159 |
-- If time's up, set the game to be lost. |
|
160 |
-- We actually check the time to be "1 ms" as it |
|
161 |
-- will be at "0 ms" right at the start of the game. |
|
162 |
if TurnTimeLeft < 40 and TurnTimeLeft > 0 and score < score_goal and game_lost == false then |
|
163 |
game_lost = true |
|
164 |
-- ... and show a short message. |
|
165 |
AddCaption(loc("Time's up!")) |
|
166 |
ShowMission(loc("Sniper Training"), loc("Aiming Practice"), loc("Oh no! Time's up! Just try again."), -amSkip, 0) |
|
167 |
-- and generate the stats and go to the stats screen |
|
168 |
generateStats() |
|
169 |
EndGame() |
|
170 |
-- Just to be sure set the goal time to 1 ms |
|
171 |
time_goal = 1 |
|
172 |
end |
|
173 |
-- If the goal is reached or we've lost ... |
|
174 |
if score == score_goal or game_lost then |
|
175 |
-- ... check to see if the time we'd like to |
|
176 |
-- wait has passed and then ... |
|
177 |
if end_timer == 0 then |
|
178 |
-- ... end the game ... |
|
179 |
generateStats() |
|
180 |
EndGame() |
|
181 |
else |
|
182 |
-- ... or just lower the timer by 1. |
|
183 |
-- Reset the time left to stop the timer |
|
184 |
TurnTimeLeft = time_goal |
|
185 |
end |
|
186 |
end_timer = end_timer - 20 |
|
187 |
end |
|
188 |
end |
|
189 |
||
190 |
-- This function is called when the game is initialized |
|
191 |
-- to request the available ammo and probabilities |
|
192 |
function onAmmoStoreInit() |
|
193 |
-- add an unlimited supply of shotgun ammo |
|
194 |
SetAmmo(amSniperRifle, 9, 0, 0, 0) |
|
195 |
end |
|
196 |
||
197 |
-- This function is called when a new gear is added. |
|
198 |
-- We use it to count the number of shots, which we |
|
199 |
-- in turn use to calculate the final score and stats |
|
200 |
function onGearAdd(gear) |
|
201 |
if GetGearType(gear) == gtSniperRifleShot then |
|
202 |
shots = shots + 1 |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
203 |
elseif GetGearType(gear) == gtDynamite then |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
204 |
dynamiteCounter = dynamiteCounter + 1 |
11015 | 205 |
end |
206 |
end |
|
207 |
||
208 |
-- This function is called before a gear is destroyed. |
|
209 |
-- We use it to count the number of targets destroyed. |
|
210 |
function onGearDelete(gear) |
|
11528 | 211 |
local gt = GetGearType(gear) |
11017
16c47a5573e4
change theme used by sniper training, for performance reasons
sheepluva
parents:
11015
diff
changeset
|
212 |
|
11528 | 213 |
if gt == gtCase then |
11015 | 214 |
game_lost = true |
215 |
return |
|
216 |
end |
|
11017
16c47a5573e4
change theme used by sniper training, for performance reasons
sheepluva
parents:
11015
diff
changeset
|
217 |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
218 |
if (gt == gtDynamite) then |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
219 |
-- Dynamite blow-up, used to continue the game. |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
220 |
dynamiteCounter = dynamiteCounter - 1 |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
221 |
|
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
222 |
-- Wait for all dynamites to be destroyed before we continue. |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
223 |
-- Most cut scenes spawn multiple dynamites. |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
224 |
if dynamiteCounter == 0 then |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
225 |
if cinematic then |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
226 |
cinematic = false |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
227 |
SetCinematicMode(false) |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
228 |
end |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
229 |
-- Add bonus score for the previuos target |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
230 |
score_bonus = score_bonus + 1 |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
231 |
-- Now *actually* spawn the delayed target |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
232 |
spawnTarget(delayedTargetX, delayedTargetY) |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
233 |
end |
11528 | 234 |
return |
235 |
end |
|
236 |
||
237 |
if gt == gtTarget then |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
238 |
target = nil |
11015 | 239 |
-- remember when the target was hit for adjusting the camera |
240 |
last_hit_time = TurnTimeLeft |
|
241 |
-- Add one point to our score/counter |
|
242 |
score = score + 1 |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
243 |
score_bonus = score_bonus + 1 |
11015 | 244 |
-- If we haven't reached the goal ... |
245 |
if score < score_goal then |
|
246 |
-- ... spawn another target. |
|
247 |
if score == 1 then |
|
248 |
spawnTarget(1520,1350) |
|
249 |
elseif score == 2 then |
|
250 |
spawnTarget(1730,1040) |
|
251 |
elseif score == 3 then |
|
252 |
spawnTarget(2080,780) |
|
253 |
elseif score == 4 then |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
254 |
-- Short cut scene, blows up up lots up land and prepares |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
255 |
-- next target position. |
11015 | 256 |
AddCaption(loc("Good so far!") .. " " .. loc("Keep it up!")); |
257 |
blowUp(1730,1226) |
|
258 |
blowUp(1440,1595) |
|
259 |
blowUp(1527,1575) |
|
260 |
blowUp(1614,1595) |
|
261 |
blowUp(1420,1675) |
|
262 |
blowUp(1527,1675) |
|
263 |
blowUp(1634,1675) |
|
264 |
blowUp(1440,1755) |
|
265 |
blowUp(1527,1775) |
|
266 |
blowUp(1614,1755) |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
267 |
-- Target appears *after* the cutscene. |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
268 |
spawnTargetDelayed(1527,1667) |
11015 | 269 |
elseif score == 5 then |
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
270 |
spawnTarget(2175,1300) |
11015 | 271 |
elseif score == 6 then |
272 |
spawnTarget(2250,940) |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
273 |
elseif score == 7 then |
11015 | 274 |
spawnTarget(2665,1540) |
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
275 |
elseif score == 8 then |
11015 | 276 |
spawnTarget(3040,1160) |
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
277 |
elseif score == 9 then |
11015 | 278 |
spawnTarget(2930,1500) |
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
279 |
elseif score == 10 then |
11015 | 280 |
AddCaption(loc("This one's tricky.")); |
281 |
spawnTarget(700,720) |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
282 |
elseif score == 11 then |
11015 | 283 |
AddCaption(loc("Well done.")); |
284 |
blowUp(914,1222) |
|
285 |
blowUp(1050,1222) |
|
286 |
blowUp(1160,1008) |
|
287 |
blowUp(1160,1093) |
|
288 |
blowUp(1160,1188) |
|
289 |
blowUp(375,911) |
|
290 |
blowUp(510,911) |
|
291 |
blowUp(640,911) |
|
292 |
blowUp(780,911) |
|
293 |
blowUp(920,911) |
|
294 |
blowUp(1060,913) |
|
295 |
blowUp(1198,913) |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
296 |
spawnTargetDelayed(1200,830) |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
297 |
elseif score == 12 then |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
298 |
spawnTarget(1430,450) |
11015 | 299 |
elseif score == 13 then |
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
300 |
spawnTarget(796,240) |
11015 | 301 |
elseif score == 14 then |
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
302 |
spawnTarget(300,10) |
11015 | 303 |
elseif score == 15 then |
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
304 |
spawnTarget(2080,820) |
11015 | 305 |
elseif score == 16 then |
306 |
AddCaption(loc("Demolition is fun!")); |
|
307 |
blowUp(2110,920) |
|
308 |
blowUp(2210,920) |
|
309 |
blowUp(2200,305) |
|
310 |
blowUp(2300,305) |
|
311 |
blowUp(2300,400) |
|
312 |
blowUp(2300,500) |
|
313 |
blowUp(2300,600) |
|
314 |
blowUp(2300,700) |
|
315 |
blowUp(2300,800) |
|
316 |
blowUp(2300,900) |
|
317 |
blowUp(2401,305) |
|
318 |
blowUp(2532,305) |
|
319 |
blowUp(2663,305) |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
320 |
spawnTargetDelayed(2300,760) |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
321 |
elseif score == 17 then |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
322 |
spawnTarget(2738,190) |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
323 |
elseif score == 18 then |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
324 |
spawnTarget(2590,-100) |
11015 | 325 |
elseif score == 19 then |
326 |
AddCaption(loc("Will this ever end?")); |
|
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(3258,370) |
|
339 |
blowUp(3258,475) |
|
340 |
blowUp(3264,575) |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
341 |
spawnTargetDelayed(3230,290) |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
342 |
elseif score == 20 then |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
343 |
spawnTarget(3670,250) |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
344 |
elseif score == 21 then |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
345 |
spawnTarget(2620,-100) |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
346 |
elseif score == 22 then |
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
347 |
spawnTarget(2870,300) |
11015 | 348 |
elseif score == 23 then |
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
349 |
spawnTarget(3850,900) |
11015 | 350 |
elseif score == 24 then |
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
351 |
spawnTarget(3780,300) |
11015 | 352 |
elseif score == 25 then |
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
353 |
spawnTarget(3670,0) |
11015 | 354 |
elseif score == 26 then |
355 |
AddCaption(loc("Last Target!")); |
|
356 |
spawnTarget(3480,1200) |
|
357 |
end |
|
358 |
else |
|
359 |
if not game_lost then |
|
360 |
-- Otherwise show that the goal was accomplished |
|
361 |
ShowMission(loc("Sniper Training"), loc("Aiming Practice"), loc("Congratulations! You've eliminated all targets|within the allowed time frame."), 0, 0) |
|
362 |
-- Also let the hogs shout "victory!" |
|
363 |
PlaySound(sndVictory) |
|
364 |
-- Save the time left so we may keep it. |
|
365 |
time_goal = TurnTimeLeft |
|
366 |
end |
|
367 |
end |
|
368 |
end |
|
369 |
end |
|
370 |
||
371 |
-- This function calculates the final score of the player and provides some texts and |
|
372 |
-- data for the final stats screen |
|
373 |
function generateStats() |
|
374 |
local accuracy = (score/shots)*100 |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
375 |
local end_score_targets = (score_bonus * 200) |
11015 | 376 |
local end_score_overall |
377 |
if not game_lost then |
|
378 |
local end_score_time = math.ceil(time_goal/5) |
|
379 |
local end_score_accuracy = math.ceil(accuracy * 100) |
|
380 |
end_score_overall = end_score_time + end_score_targets + end_score_accuracy |
|
381 |
||
382 |
SendStat(siGameResult, loc("You have successfully finished the sniper rifle training!")) |
|
383 |
SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets)) |
|
384 |
SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots)) |
|
385 |
SendStat(siCustomAchievement, string.format(loc("Accuracy bonus: +%d points"), end_score_accuracy)) |
|
386 |
SendStat(siCustomAchievement, string.format(loc("You had %.2fs remaining on the clock (+%d points)."), (time_goal/1000), end_score_time)) |
|
387 |
else |
|
388 |
SendStat(siGameResult, loc("You lose!")) |
|
11017
16c47a5573e4
change theme used by sniper training, for performance reasons
sheepluva
parents:
11015
diff
changeset
|
389 |
|
11015 | 390 |
SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets)) |
391 |
SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots)) |
|
392 |
end_score_overall = end_score_targets |
|
393 |
end |
|
12346
fb22caa19600
Fix incorrect PointsType in sniper rifle training and That Sinking Feeling
Wuzzy <almikes@aol.com>
parents:
12224
diff
changeset
|
394 |
SendStat(siPointType, loc("points")) |
11015 | 395 |
SendStat(siPlayerKills, tostring(end_score_overall), loc("Sniperz")) |
396 |
end |
|
12727
23fb2179945f
Sniper rifle mission: Fix targets spawning twice in dynamite scenes, jacking up the total amount of targets
Wuzzy <Wuzzy2@mail.ru>
parents:
12346
diff
changeset
|
397 |