403 end |
403 end |
404 |
404 |
405 -- This function calculates the final score of the player and provides some texts and |
405 -- This function calculates the final score of the player and provides some texts and |
406 -- data for the final stats screen |
406 -- data for the final stats screen |
407 function generateStats() |
407 function generateStats() |
408 local accuracy = 0 |
408 local accuracy |
|
409 local accuracy_int |
409 if shots > 0 then |
410 if shots > 0 then |
410 accuracy = (score/shots)*100 |
411 accuracy = (score/shots)*100 |
|
412 accuracy_int = div(score*100, shots) |
411 end |
413 end |
412 local end_score_targets = getTargetScore() |
414 local end_score_targets = getTargetScore() |
413 local end_score_overall |
415 local end_score_overall |
414 if not game_lost then |
416 if not game_lost then |
415 local end_score_time = math.ceil(time_goal/5) |
417 local end_score_time = math.ceil(time_goal/5) |
416 local end_score_accuracy = math.ceil(accuracy * 100) |
418 local end_score_accuracy = 0 |
|
419 if shots > 0 then |
|
420 end_score_accuracy = math.ceil(accuracy * 100) |
|
421 end |
417 end_score_overall = end_score_time + end_score_targets + end_score_accuracy |
422 end_score_overall = end_score_time + end_score_targets + end_score_accuracy |
418 SetTeamLabel(playerTeamName, tostring(end_score_overall)) |
423 SetTeamLabel(playerTeamName, tostring(end_score_overall)) |
419 |
424 |
420 SendStat(siGameResult, loc("You have successfully finished the sniper rifle training!")) |
425 SendStat(siGameResult, loc("You have successfully finished the sniper rifle training!")) |
421 SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets)) |
426 SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets)) |
422 SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots)) |
427 SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots)) |
423 SendStat(siCustomAchievement, string.format(loc("Accuracy bonus: +%d points"), end_score_accuracy)) |
428 if end_score_accuracy > 0 then |
|
429 SendStat(siCustomAchievement, string.format(loc("Accuracy bonus: +%d points"), end_score_accuracy)) |
|
430 end |
424 SendStat(siCustomAchievement, string.format(loc("You had %.2fs remaining on the clock (+%d points)."), (time_goal/1000), end_score_time)) |
431 SendStat(siCustomAchievement, string.format(loc("You had %.2fs remaining on the clock (+%d points)."), (time_goal/1000), end_score_time)) |
|
432 |
|
433 if(shots > 0) then |
|
434 updateChallengeRecord("AccuracyRecord", accuracy_int) |
|
435 end |
425 else |
436 else |
426 SendStat(siGameResult, loc("Challenge over!")) |
437 SendStat(siGameResult, loc("Challenge over!")) |
427 |
438 |
428 SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets)) |
439 SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets)) |
429 SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots)) |
440 SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots)) |