#include "ui/components/end_screen.lua" #include "missions.lua" #include "starthub.lua" #include "script/common.lua" #include "ui/ui_helpers.lua" #include "ui/ui_extensions.lua" -- Custom heist mission implementation -- This script requires heist.lua in the level to work properly function init() state = "" missionId = GetString("game.levelid") SetBool("level.campaign", true) -- To get adjustment of health and mission time to work properly savedScore = false score = 0 timeLeft = 0 endTimer = 0 endScreen = 0 endScreenScale = 0 end function tick(dt) --Read the current level state. This is set by heist.lua state = GetString("level.state") --If level is completed we need to deal with score if state == "win" and not savedScore then --Get the score from registry. These values are set by heist.lua score = GetInt("level.clearedprimary") + GetInt("level.clearedsecondary") timeLeft = GetFloat("level.timeleft") local missionTime = GetFloat("level.missiontime") --Save the new score if it's better than the current highscore local oldScore = GetInt("savegame.mod."..missionId..".score") local oldTimeLeft = GetFloat("savegame.mod."..missionId..".timeleft") if score > oldScore or (score == oldScore and timeLeft > oldTimeLeft) then SetInt("savegame.mod."..missionId..".score", score) SetFloat("savegame.mod."..missionId..".timeleft", timeLeft) SetFloat("savegame.mod."..missionId..".missiontime", missionTime) end --Do this only once savedScore = true end --If level is no longer in default state we need to handle win and lose if state ~= "" then --Wait two seconds to allow the escape vehicle to drive off endTimer = endTimer + dt if endTimer > 2 then if endScreen == 0 then SetValue("endScreen", 1, "cosine", 0.25) end end end end function draw() local canvas = UiCanvasSize() UiWindow(canvas.w, canvas.h) --End screen if endScreen > 0 then UiMakeInteractive() -- for end screen we do not want to draw a cursor if LastInputDevice() == UI_DEVICE_GAMEPAD then UiSetCursorState(UI_CURSOR_HIDE_AND_LOCK) else UiSetCursorState(UI_CURSOR_SHOW) end --Set gEndScreenScale to ease in the end screen SetValue("endScreenScale", 1, "easeout", 0.5) --Call to draw the endscreen -- drawEndScreen(endScreenScale, state) if state == "win" then SetBool("savegame.mod."..missionId..".complete",true) end EndScreen.draw(endScreenScale, state, gArtMissions, missionId, { exit = startHub, skip = function () SetBool("savegame.mod."..missionId..".complete", true) startHub() end, menu = Menu } ) end end