score = 0 timer = 0 local timerMax = 5 local countMax = 30 local offsetCan = 0 local broken = false bottleList = {} local button = 0 timerScore = 0 local timerScoreMax = 0 locations = {} isStartGame = false isInit = false isInitRestart = false startTimer = 0 local fadeToBlackAlpha = 0 local fadeInAlpha = 0.05 local fadetimer = 2 isSpawned = false function init() crateslocations = {} rackslocations = {} logslocations = {} boxlocations = {} cleanuppos = GetLocationTransform(FindLocation("cleanup")).pos button = FindShape("button") crates = FindLocations("cratestart") SetTag(button, "interact", "loc@UI_BUTTON_RESET") for i = 1, #crates do crateslocations[i] = GetLocationTransform(crates[i]) end racks = FindLocations("rackstart") for i = 1, #racks do rackslocations[i] = GetLocationTransform(racks[i]) end logs = FindLocations("logstart") for i = 1, #logs do logslocations[i] = GetLocationTransform(logs[i]) end boxes = FindLocations("boxstart") for i = 1, #boxes do boxlocations[i] = GetLocationTransform(boxes[i]) end boxesclosed = FindLocations("boxclosed") local locs = FindLocations("canpos") for i = 1, #locs do locations[i] = GetLocationTransform(locs[i]) end cleanup() isInit = true isStartGame = true -- BottlesSpawn() end function tick(dt) if broken then return end --if not isInit then startTimer = startTimer +dt end --if startTimer > 3 then isInit = true end if not isStartGame and score > 0 and not isInitRestart then SetTag(button, "interact", "loc@UI_BUTTON_RESET") isInitRestart = true end if GetPlayerInteractShape() == button and InputPressed("interact") then RemoveTag(button, "interact") for i = 1, #bottleList do BottleDelete(bottleList[i], i) end score = 0 isInit = false startTimer = 0 isInitRestart = false fadetimer = 0 isSpawned = false SetInt ("game.mod.shootergame.timescore", 0) SetInt("game.mod.shootergame.scores", 0) end BottleScore() if IsShapeBroken(button) then RemoveTag(button, "interact") broken = true end end function draw(dt) if fadetimer <= 0.8 then fadetimer = fadetimer + dt UiPush() fadeToBlackAlpha = fadeToBlackAlpha + fadeInAlpha UiColor(0, 0, 0, fadeToBlackAlpha) UiAlign("midlle") UiRect(UiWidth(), UiHeight()) UiPop() elseif fadetimer > 0.8 and fadetimer <= 1.2 then fadetimer = fadetimer + dt --BottlesSpawn() cleanup() UiColor(0, 0, 0, fadeToBlackAlpha) UiAlign("midlle") UiRect(UiWidth(), UiHeight()) elseif fadetimer > 1.2 and fadetimer <= 2.0 then fadetimer = fadetimer + dt UiPush() fadeToBlackAlpha = fadeToBlackAlpha - fadeInAlpha UiColor(0, 0, 0, fadeToBlackAlpha) UiAlign("midlle") UiRect(UiWidth(), UiHeight()) SetTag(button, "interact", "loc@UI_BUTTON_RESET") UiPop() end end function cleanup() if not isSpawned then deleteshapes = QueryAabbShapes(VecSub(cleanuppos, Vec(10,10,10)), VecAdd(cleanuppos, Vec(10,10,10))) for i=1, #deleteshapes do if GetShapeVoxelCount(deleteshapes[i]) < 5000 and not HasTag(deleteshapes[i], "unbreakable") then Delete(deleteshapes[i]) end end ObjectsSpawn() end end function ObjectsSpawn() for i = 1, #crateslocations do Spawn("MOD/runtime/prefabs/shootingrange/crate.xml", crateslocations[i], true) end for i = 1, #rackslocations do Spawn("MOD/runtime/prefabs/shootingrange/rack.xml", rackslocations[i], true) end for i =1, #logslocations do Spawn("MOD/runtime/prefabs/shootingrange/log.xml", logslocations[i], true) end for i =1, #boxlocations do Spawn("MOD/runtime/prefabs/shootingrange/box.xml", boxlocations[i], true) end BottlesSpawn() end function BottlesSpawn() for i=1, #locations do local entities = Spawn('', Transform(locations[i].pos)) SetTag(entities[1], "bottle") SetTag(entities[1], "nocull") table.insert(bottleList, entities[1]) end isSpawned = true end function update() if isStartGame or isInitRestart then return end if not isInit then return end for i=1, #bottleList do if IsBodyBroken(bottleList[i]) or VecLength(GetBodyVelocity(bottleList[i])) > 1 then timer = timerMax end end end function BottleScore() for i = 1, #bottleList do local bottle = bottleList[i] if IsBodyBroken(bottle) then score = score + 1 SetInt("game.mod.shootergame.scores", score) BottleDelete(bottle, i) end end end function BottleDelete(bottle, index) table.remove(bottleList, index) Delete(bottle) end function DrawTimer() UiPush() UiFont("bold.ttf", 32) UiTranslate(UiCenter() - 50, 65) UiAlign("left") UiTextOutline(0, 0, 0, 1) UiColor(1, 1, 1) UiScale(2.0) if timer <= 60 then UiText(math.ceil(timer * 10) / 10) else local time = math.ceil(timer) local minutes = math.floor(t / 60) local seconds = math.ceil(t - m * 60) if s < 10 then UiText(m .. ":0" .. s) else UiText(m .. ":" .. s) end end UiPop() end function DrawBestScore() UiPush() UiFont("bold.ttf", 32) UiTranslate(UiCenter() - 450, 135) UiAlign("left") UiColor(1, 1, 1) UiTextOutline(0, 0, 0, 2) UiScale(2.0) if bestScores[1] > 0 then UiText("BEST SCORE: " .. bestScores[1] .. " - CURRENT SCORE: " .. score) end UiPop() end function handleCommand(cmd) if cmd == "quickload" then crateslocations = {} rackslocations = {} logslocations = {} boxlocations = {} cleanuppos = GetLocationTransform(FindLocation("cleanup")).pos button = FindShape("button") crates = FindLocations("cratestart") for i = 1, #crates do crateslocations[i] = GetLocationTransform(crates[i]) end racks = FindLocations("rackstart") for i = 1, #racks do rackslocations[i] = GetLocationTransform(racks[i]) end logs = FindLocations("logstart") for i = 1, #logs do logslocations[i] = GetLocationTransform(logs[i]) end boxes = FindLocations("boxstart") for i = 1, #boxes do boxlocations[i] = GetLocationTransform(boxes[i]) end boxesclosed = FindLocations("boxclosed") local locs = FindLocations("canpos") for i = 1, #locs do locations[i] = GetLocationTransform(locs[i]) end end end