#include "common/utils.lua" local TOOL_BOX_SPAWN_TIME = 0.75 local toolBoxTable = {} function init() currentStage = 0 stage = 0 tools = {} tablestaff = {} screen = FindScreen("terminal") body = GetShapeBody(GetScreenShape(screen)) terminalpos = GetBodyTransform(body) arrow = LoadSprite("gfx/arrowdown.png") ringsprite = LoadSprite("gfx/ring.png") tablestaff = FindBodies("part3") currentStage = GetCurrentStage() barrel = FindBody("barrel") barreltrigger = FindTrigger("extraction") geartrigger = FindTrigger("gearzone") barrelTriggerPos = GetTriggerTransform(barreltrigger) barrelTriggerPos.rot = QuatEuler(90, 0, 0) geartriggerPos = GetTriggerTransform(geartrigger) geartriggerPos.rot = QuatEuler(90, 0, 0) initbarrerPos = GetBodyTransform(barrel) gears = FindShapes("gear") dirtygearsCounter = 0 specGear = FindBody("specialgear") specgearplace = FindShape("specgearplace") local dynamitebundleloc = FindLocation("dynamitebundleloc") local dynamiteloc = FindLocation("dynamiteloc") local powderloc = FindLocation("powderloc") dynamitebundleloct = GetLocationTransform(dynamitebundleloc) dynamiteloct = GetLocationTransform(dynamiteloc) powderloct = GetLocationTransform(powderloc) dynamitebundle = FindBody("dynamitebundle", true) dynamite = FindBody("dynamite", true) powder = FindBody("powder", true) toolBoxTable = { [1] = { body = powder, destination = powderloct }, [2] = { body = dynamitebundle, destination = dynamitebundleloct }, [3] = { body = dynamite, destination = dynamiteloct } } toolBoxSpawnTimer = nil toolBoxArrowList = {} ToolBoxSpawnSownd = LoadSound("tool_pickup.ogg") if currentStage ~= 3 then Delete(barrel) Delete(barreltrigger) for i = 1, #tablestaff do Delete (tablestaff[i]) end else if not isMessageRead("ravine_heist") then deactivateTable() end end if currentStage ~= 7 then Delete(geartrigger) Delete(specGear) Delete(specgearplace) for i = 1, #gears do Delete(gears[i]) end else if not isMessageRead("ravine_motivational") then for i = 1, #gears do SetTag(gears[i], "interact", "loc@UI_GEAR_CLEAR") SetTag(gears[i], "unbreakable") SetShapeEmissiveScale (gears[i], 0) end end end isCheckDynamic = false isCheckDynamicTimer = 0 end function tick(dt) if HasTag(body, "interact") then if GetPlayerScreen() == screen then SetTag(body, "interact", "loc@LEAVE") else SetTag(body, "interact", "loc@OPERATE") end end if GetPlayerScreen() ~= screen and GetPlayerInteractBody() == body and InputPressed("interact") then SetPlayerScreen(screen) end if currentStage == 1 then if not isMessageRead("town_heist") then if stage == 0 then drawArrow(terminalpos) SetString("hud.notification", GetTranslatedStringByKey("UI_FIRST_TOOLS_WELCOME")) SetBool("game.hub.hidetool", true) stage = 1 elseif stage == 1 then drawArrow(terminalpos) if isMessageRead("hub_tools") and GetPlayerScreen() == 0 then if not GetBool("game.tool.blowtorch.enabled") and not GetBool("game.tool.plank.enabled") and not GetBool("game.tool.shotgun.enabled") then SetString("hud.notification", GetTranslatedStringByKey("UI_FIRST_TOOLS")) SetBool("game.hub.hidetool", false) stage = 2 end end elseif stage == 3 then drawArrow(terminalpos) if isMessageRead("town_heist") then stage = 4 end end if GetBool("game.tool.blowtorch.enabled") and GetBool("game.tool.plank.enabled") and GetBool("game.tool.shotgun.enabled") and not isMessageRead("town_heist") and stage < 3 then SetString("hud.notification", GetTranslatedStringByKey("UI_FIRST_TOOLS_TERMINAL")) receiveMessage("town_heist") stage = 3 end end elseif currentStage == 3 then if not isMessageRead("ravine_heist") then if stage == 0 then SetString("hud.notification", GetTranslatedStringByKey("UI_SALTPEPPER_WELCOME")) stage = 1 elseif stage == 1 then DrawSprite(ringsprite, barrelTriggerPos, 2.5, 2.5, 1, 1, 1, 1, true, false) drawArrow(initbarrerPos) if VecLength(GetBodyVelocity(barrel)) > 0.1 then stage = 2 end elseif stage == 2 then DrawSprite(ringsprite, barrelTriggerPos, 2.5, 2.5, 1, 1, 1, 1, true, false) drawArrow(barrelTriggerPos) if IsBodyInTrigger(barreltrigger, barrel) and GetPlayerGrabBody() ~= barrel then activateTable() if not isMessageReceived("ravine_heist") then toolBoxSpawnTimer = TOOL_BOX_SPAWN_TIME end Delete(barrel) SetString("hud.notification", GetTranslatedStringByKey("UI_SALTPEPPER_TOOLS")) stage = 3 end elseif stage == 3 then if GetBool("game.tool.dynamite_bundle.enabled") and GetBool("game.tool.dynamite_stick.enabled") and GetBool("game.tool.powder.enabled") and not isMessageRead("ravine_heist") then receiveMessage("ravine_heist") SetString("hud.notification", GetTranslatedStringByKey("UI_SALTPEPPER_TERMINAL")) stage = 4 end elseif stage == 4 then drawArrow(terminalpos) if isMessageRead("ravine_heist") then stage = 5 end end end elseif currentStage == 7 then if not isMessageRead("ravine_motivational") then if stage == 0 then SetString("hud.notification", GetTranslatedStringByKey("UI_GEARS_WELCOME")) stage = 1 elseif stage == 1 then for i = 1, #gears do if HasTag(gears[i], "interact") then local trans = Transform(getCenterShape(gears[i])) drawArrow(trans) end if GetPlayerInteractShape() == gears[i] and InputPressed("interact") then RemoveTag(gears[i], "interact") SetShapeEmissiveScale (gears[i], 1) dirtygearsCounter = dirtygearsCounter + 1 end end if dirtygearsCounter == 4 then SetString("hud.notification", GetTranslatedStringByKey("UI_SALTPEPPER_TERMINAL")) receiveMessage("ravine_motivational") stage = 2 end end end end if isCheckDynamic then isCheckDynamicTimer = isCheckDynamicTimer - dt if isCheckDynamicTimer <= 0 then SetBodyDynamic(powder, false) SetBodyDynamic(dynamite, false) SetBodyDynamic(dynamitebundle, false) isCheckDynamic = false end end if toolBoxSpawnTimer ~= nil then if toolBoxSpawnTimer > 0 then if toolBoxSpawnTimer >= 0.5 then CreateToolBoxSpawnEffect() end toolBoxSpawnTimer = toolBoxSpawnTimer - dt else SpawnToolBoxes() end end DrawToolBoxesArrow() end function getCenterShape (shape) local min, max = GetShapeBounds(shape) local boundsSize = VecSub(max, min) center = VecLerp(min, max, 0.5) return center end function deactivateTable() local tools = FindBodies("tool", true) for i=1, #tools do RemoveTag(tools[i], "interact") SetTag(tools[i], "invisible") -- local shapes = GetBodyShapes(tools[i]) -- for j = 1, #shapes do --== SetTag(shapes[j], "invisible") --== SetShapeCollisionFilter(shapes[j], 0, 0) --end end for i = 1, #tablestaff do SetBodyDynamic (tablestaff[i], false) SetTag(tablestaff[i], "invisible") local shapes = GetBodyShapes(tablestaff[i]) for j = 1, #shapes do SetTag(shapes[j], "invisible") end end end function activateTable() isCheckDynamic = true isCheckDynamicTimer = 2.75 for i = 1, #tablestaff do RemoveTag(tablestaff[i], "invisible") local shapes = GetBodyShapes(tablestaff[i]) for j = 1, #shapes do RemoveTag(shapes[j], "invisible") if HasTag(shapes[j], "explosive") then SetBodyDynamic (tablestaff[i], true) end end end end function drawArrow(trans) local t = TransformCopy(trans) t.rot = QuatLookAt(t.pos, GetCameraTransform().pos) local offset = 2.5 + math.sin(4.0*GetTime())*0.5 t.pos[2] = t.pos[2] + offset DrawSprite(arrow, t, 2, 2, .3, .3, .3, 3, false, true) DrawSprite(arrow, t, 2, 2, 1, 1, 1, 1, true, true) end function GetCurrentStage() if GetBool("savegame.mod.mission.town_grease.complete") and not GetBool ("savegame.mod.mission.ravine_motivational.complete") then return 7 end if GetBool("savegame.mod.mission.town_explosive.complete") and not GetBool("savegame.mod.mission.ravine_heist.complete") then return 3 end if GetBool("savegame.mod.backintime") and not GetBool("savegame.mod.mission.town_heist.complete") then return 1 end return 0 end function isMessageRead(messageId) return GetInt("savegame.mod.message."..messageId) == 2 end function isMessageReceived(messageId) return GetInt("savegame.mod.message."..messageId) > 0 end function hasUnreadMessages(messageId) return GetInt("savegame.mod.message."..messages[i]) == 1 end function receiveMessage(messageId) SetInt("savegame.mod.message."..messageId, 1) end function handleCommand(cmd) if cmd == "quickload" then screen = FindScreen("terminal") body = GetShapeBody(GetScreenShape(screen)) terminalpos = GetBodyTransform(body) arrow = LoadSprite("gfx/arrowdown.png") ringsprite = LoadSprite("gfx/ring.png") tablestaff = FindBodies("part3") --currentStage = GetCurrentStage() barrel = FindBody("barrel") barreltrigger = FindTrigger("extraction") geartrigger = FindTrigger("gearzone") barrelTriggerPos = GetTriggerTransform(barreltrigger) barrelTriggerPos.rot = QuatEuler(90, 0, 0) geartriggerPos = GetTriggerTransform(geartrigger) geartriggerPos.rot = QuatEuler(90, 0, 0) initbarrerPos = GetBodyTransform(barrel) gears = FindShapes("gear") dirtygearsCounter = 0 specGear = FindBody("specialgear") specgearplace = FindShape("specgearplace") end end function SpawnToolBoxes() if #toolBoxTable == 0 then return end local tools = toolBoxTable[1] SetBodyTransform(tools.body, tools.destination) SetBodyDynamic(tools.body, true) SetBodyActive(tools.body, true) PlaySound(ToolBoxSpawnSownd, tools.destination.pos) table.insert(toolBoxArrowList, tools.body) table.remove(toolBoxTable, 1) toolBoxSpawnTimer = TOOL_BOX_SPAWN_TIME end function CreateToolBoxSpawnEffect() if #toolBoxTable == 0 then return end ParticleReset() ParticleType("smoke") ParticleColor(0.6, 0.6, 0.6, 0.92, 0.92, 0.92) ParticleRadius(0.1, 0.4) ParticleGravity(0, -1, "smooth") ParticleAlpha(1, 0.1, "easein", "fadein") ParticleTile(3) ParticleDrag(0.23) ParticleEmissive(0.05) ParticleRotation(3,5) ParticleStretch(0.1) for i = 1, 5 do SpawnParticle(toolBoxTable[1].destination.pos, RandomSeedVec(0.05), 1) end end function DrawToolBoxesArrow() if #toolBoxArrowList == 0 then return end local toDelete = nil for i = 1, #toolBoxArrowList do if IsHandleValid(toolBoxArrowList[i]) then drawArrow(GetBodyTransform(toolBoxArrowList[i])) else toDelete = i end end if toDelete ~= nil then table.remove(toolBoxArrowList, toDelete) end end