49 local dynamiteGears = {} |
49 local dynamiteGears = {} |
50 |
50 |
51 -- Position for delayed targets |
51 -- Position for delayed targets |
52 local delayedTargetTargetX, delayedTargetY |
52 local delayedTargetTargetX, delayedTargetY |
53 |
53 |
|
54 -- Team name of the player's team |
|
55 local playerTeamName = loc("Sniperz") |
|
56 |
54 -- This is a custom function to make it easier to |
57 -- This is a custom function to make it easier to |
55 -- spawn more targets with just one line of code |
58 -- spawn more targets with just one line of code |
56 -- You may define as many custom functions as you |
59 -- You may define as many custom functions as you |
57 -- like. |
60 -- like. |
58 |
61 |
66 |
69 |
67 -- Remembers position to spawn a target at (x, y) after a dynamite explosion |
70 -- Remembers position to spawn a target at (x, y) after a dynamite explosion |
68 function spawnTargetDelayed(x, y) |
71 function spawnTargetDelayed(x, y) |
69 delayedTargetX = x |
72 delayedTargetX = x |
70 delayedTargetY = y |
73 delayedTargetY = y |
|
74 -- The previous target always counts double after destruction |
|
75 score_bonus = score_bonus + 1 |
|
76 end |
|
77 |
|
78 function getTargetScore() |
|
79 return score_bonus * 200 |
71 end |
80 end |
72 |
81 |
73 -- Cut sequence to blow up land with dynamite |
82 -- Cut sequence to blow up land with dynamite |
74 function blowUp(x, y, follow) |
83 function blowUp(x, y, follow) |
75 if cinematic == false then |
84 if cinematic == false then |
122 -- Disable Sudden Death |
131 -- Disable Sudden Death |
123 WaterRise = 0 |
132 WaterRise = 0 |
124 HealthDecrease = 0 |
133 HealthDecrease = 0 |
125 |
134 |
126 -- Create the player team |
135 -- Create the player team |
127 AddTeam(loc("Sniperz"), 14483456, "Simple", "Island", "Default", "cm_crosshair") |
136 AddTeam(playerTeamName, 0xFF0204, "Simple", "Island", "Default", "cm_crosshair") |
128 -- And add a hog to it |
137 -- And add a hog to it |
129 player = AddHog(loc("Hunter"), 0, 1, "Sniper") |
138 player = AddHog(loc("Hunter"), 0, 1, "Sniper") |
130 SetGearPosition(player, 602, 1465) |
139 SetGearPosition(player, 602, 1465) |
131 end |
140 end |
132 |
141 |
144 -- extra text, icon and time to show. |
153 -- extra text, icon and time to show. |
145 -- A negative icon parameter (-n) represents the n-th weapon icon |
154 -- A negative icon parameter (-n) represents the n-th weapon icon |
146 -- A positive icon paramter (n) represents the (n+1)-th mission icon |
155 -- A positive icon paramter (n) represents the (n+1)-th mission icon |
147 -- A timeframe of 0 is replaced with the default time to show. |
156 -- A timeframe of 0 is replaced with the default time to show. |
148 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) |
157 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) |
|
158 |
|
159 -- Displayed initial player score |
|
160 SetTeamLabel(playerTeamName, "0") |
149 end |
161 end |
150 |
162 |
151 -- This function is called every game tick. |
163 -- This function is called every game tick. |
152 -- Note that there are 1000 ticks within one second. |
164 -- Note that there are 1000 ticks within one second. |
153 -- You shouldn't try to calculate too complicated |
165 -- You shouldn't try to calculate too complicated |
243 if dynamiteCounter == 0 then |
255 if dynamiteCounter == 0 then |
244 if cinematic then |
256 if cinematic then |
245 cinematic = false |
257 cinematic = false |
246 SetCinematicMode(false) |
258 SetCinematicMode(false) |
247 end |
259 end |
248 -- Add bonus score for the previuos target |
|
249 score_bonus = score_bonus + 1 |
|
250 -- Now *actually* spawn the delayed target |
260 -- Now *actually* spawn the delayed target |
251 spawnTarget(delayedTargetX, delayedTargetY) |
261 spawnTarget(delayedTargetX, delayedTargetY) |
252 end |
262 end |
253 return |
263 return |
254 end |
264 end |
388 |
398 |
389 -- Save the time left so we may keep it. |
399 -- Save the time left so we may keep it. |
390 time_goal = TurnTimeLeft |
400 time_goal = TurnTimeLeft |
391 end |
401 end |
392 end |
402 end |
|
403 SetTeamLabel(playerTeamName, getTargetScore()) |
393 end |
404 end |
394 end |
405 end |
395 |
406 |
396 -- This function calculates the final score of the player and provides some texts and |
407 -- This function calculates the final score of the player and provides some texts and |
397 -- data for the final stats screen |
408 -- data for the final stats screen |
398 function generateStats() |
409 function generateStats() |
399 local accuracy = 0 |
410 local accuracy = 0 |
400 if shots > 0 then |
411 if shots > 0 then |
401 accuracy = (score/shots)*100 |
412 accuracy = (score/shots)*100 |
402 end |
413 end |
403 local end_score_targets = (score_bonus * 200) |
414 local end_score_targets = getTargetScore() |
404 local end_score_overall |
415 local end_score_overall |
405 if not game_lost then |
416 if not game_lost then |
406 local end_score_time = math.ceil(time_goal/5) |
417 local end_score_time = math.ceil(time_goal/5) |
407 local end_score_accuracy = math.ceil(accuracy * 100) |
418 local end_score_accuracy = math.ceil(accuracy * 100) |
408 end_score_overall = end_score_time + end_score_targets + end_score_accuracy |
419 end_score_overall = end_score_time + end_score_targets + end_score_accuracy |
|
420 SetTeamLabel(playerTeamName, tostring(end_score_overall)) |
409 |
421 |
410 SendStat(siGameResult, loc("You have successfully finished the sniper rifle training!")) |
422 SendStat(siGameResult, loc("You have successfully finished the sniper rifle training!")) |
411 SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets)) |
423 SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets)) |
412 SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots)) |
424 SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots)) |
413 SendStat(siCustomAchievement, string.format(loc("Accuracy bonus: +%d points"), end_score_accuracy)) |
425 SendStat(siCustomAchievement, string.format(loc("Accuracy bonus: +%d points"), end_score_accuracy)) |
418 SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets)) |
430 SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets)) |
419 SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots)) |
431 SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots)) |
420 end_score_overall = end_score_targets |
432 end_score_overall = end_score_targets |
421 end |
433 end |
422 SendStat(siPointType, loc("points")) |
434 SendStat(siPointType, loc("points")) |
423 SendStat(siPlayerKills, tostring(end_score_overall), loc("Sniperz")) |
435 SendStat(siPlayerKills, tostring(end_score_overall), playerTeamName) |
424 end |
436 end |
425 |
437 |