#include "script/common.lua" --Dead zombie particles fx_template = {} fx_template[1] = { count = 1000, speed = 7, maxlife = 5, size = 0.1, color = Vec(math.random(127, 137)/255, math.random(72, 82)/255, math.random(59,69)/255), alpha = 1, gravity = -12, sticky = 0.2, stretch = 0.0, tile = 6, fadein = 0.0, fadeout = 0.2 } function init() totalVoxCount = 0 percentage = 100 SpawnBlocks() isSpawnParticles = false isCanSpawnParticles = true pspawntimer = 0 pdeletetimer = 0 ptable = {} ptabledelete = {} pdeletecount = 0 explosiontimer = 0 cavetrigger = FindTrigger("cavetrigger") isCheckExplosion = nil isStarted = false end function rnd(mi, ma) local v = math.random(0,1000) / 1000 return mi + (ma - mi) * v end function RndVec(seed) return Vec(rnd(-seed, seed), rnd(-seed, seed), rnd(-seed, seed)) end function ChooseRnd(list) return list[math.random(#list)] end function SpawnBlocks() blockpos = FindLocations("blockpos", true) blocks = FindShapes("block", true) for i = 1, #blocks do Delete(blocks[i]) end randomnum = shuffled_numbers(#blockpos) for i = 1, 16 do local locpos = GetLocationTransform(blockpos[randomnum[i]]) locpos.rot = QuatEuler(locpos.rot[1], math.random(0,180), locpos.rot[2]) local entity = Spawn("MOD/runtime/prefabs/minegame/resoursblock" .. math.random(1,3) .. ".xml", locpos, true) end SpawnJewerly() end function SpawnJewerly() jewelloc = FindLocations("presure", true) jewelpos = {} for i = 1, #jewelloc do jewelpos[i] = GetLocationTransform(jewelloc[i]) end table.sort(jewelpos, sort) for i = 1, #jewelpos do --MakeHole(jewelpos[i].pos, 2, 2, 2, true) local entity = Spawn("MOD/runtime/prefabs/minegame/jewel" .. i .. ".xml", jewelpos[i]) end SpawnEmptyBlocks() end function SpawnEmptyBlocks() for i = 16, 17 do local locpos = GetLocationTransform(blockpos[randomnum[i]]) locpos.rot = QuatEuler(locpos.rot[1], math.random(0,180), locpos.rot[2]) local entity = Spawn("MOD/runtime/prefabs/minegame/resoursblock" .. math.random(1,3) .. ".xml", locpos, true) end CountBlocks() end function CountBlocks() blocks = FindShapes("block", true) for i =1, #blocks do totalVoxCount = totalVoxCount + GetShapeVoxelCount(blocks[i]) end end function shuffled_numbers (n) local numbers = {} for i = 1, n do numbers[i] = i end shuffle(numbers) return numbers end function shuffle (arr) for i = 1, #arr - 1 do local j = math.random(i, #arr) arr[i], arr[j] = arr[j], arr[i] end end timer = 0 function tick(dt) if not IsPointInTrigger(cavetrigger, GetPlayerPos()) then return end if IsPointInTrigger(cavetrigger, GetPlayerPos()) and isStarted == false then SetString("hud.notification","Be careful. Try to collect as many jewels as possible") isStarted = true end local currentVoxCount = 0 for i =1, #blocks do currentVoxCount = currentVoxCount + GetShapeVoxelCount(blocks[i]) end percentage = math.floor(currentVoxCount / totalVoxCount*1000)/10 if percentage < 58 then DebugPrint("fail") end jewelloc = FindLocations("presure", true) --DebugPrint(#jewelloc) for i = 1, #jewelloc do DebugCross(GetLocationTransform(jewelloc[i]).pos) end end function update(dt) if not IsPointInTrigger(cavetrigger, GetPlayerPos()) then isCheckExplosion = nil return end if isCheckExplosion ~= nil then explosiontimer = explosiontimer + dt if explosiontimer > 0.1 then spawnParticles(isCheckExplosion) isCheckExplosion = nil explosiontimer = 0 end end end function spawnParticles(pos) ParticlesSpawner(pos, fx_template[1]) end function draw() if not IsPointInTrigger(cavetrigger, GetPlayerPos()) then return end local y = 70 if GetBool("hud.hasnotification") then y = y + 50 end UiTranslate(UiCenter()-100, y) UiFont("bold.ttf", 22) progressBar(200, 20, math.max(math.min(percentage/100, 100), 0)) UiTranslate(205, 16) UiText(percentage .. "%") end function sort(a, b) return VecLength(VecSub(a.pos, GetPlayerPos())) < VecLength(VecSub(b.pos, GetPlayerPos())) end function handleCommand(cmd) words = splitString(cmd, " ") if #words == 5 then if words[1] == "explosion" then local x = tonumber(words[3]) local y = tonumber(words[4]) local z = tonumber(words[5]) local exppoint = Vec(x,y,z) isCheckExplosion = exppoint end end end local fireage = 0 local smokeage = 0 local tempdt = 0 function ParticlesSpawner(position, particle) if particle.loopsound ~= nil and particle.loopsound ~= "" then local loadedloop = LoadLoop(particle.loopsound) if particle.loopstrength ~= nil then PlayLoop(loadedloop, position, particle.loopstrength) else PlayLoop(loadedloop, position, 1) end end if particle.singlesound ~= nil and particle.singlesound ~= "" then local loadedsound = LoadSound(particle.singlesound) if particle.soundstrength ~= nil then PlayLoop(loadedsound, position, particle.soundstrength) else PlayLoop(loadedsound, position, 1) end end if particle.fadein == nil then fadein = 0 end if particle.fadeout == nil then fadeout = 0 end local randomrange = 1 for i = 1, particle.count do local spawnposition = position local randomcoef = rnd(0,1) local life = particle.maxlife * (1 - randomcoef * 0.95) local velocityvector = Vec(0,0,0) if particle.randomrange ~= nil and particle.randomrange <= 1 and particle.randomrange > 0 then randomrange = rnd(1 - particle.randomrange, 1) end randomcoef = (0.4 + 0.6 * randomcoef) if particle.velocityvector == nil then velocityvector = VecAdd(Vec(0, randomcoef * 5, 0), VecScale(RndVec(1), randomcoef * particle.speed)) elseif particle.randomvelocity == false or particle.randomvelocity == nil then velocityvector = particle.velocityvector elseif particle.randomvelocity == true then velocityvector = Vec(rnd(- particle.velocityvector[1], particle.velocityvector[1]), rnd(0,particle.velocityvector[2]), rnd(- particle.velocityvector[3], particle.velocityvector[3])) end local radius = particle.size local endradius = particle.endsize if particle.spawnradius ~= nil then local rndangle = math.rad(math.random(-180,180)) local rndradius = rnd(-particle.spawnradius, particle.spawnradius) * ChooseRnd({rnd(0,0.6), rnd(0,1)}) spawnposition = VecAdd(position, Vec(math.sin(rndangle) * rndradius, 0, math.cos(rndangle) * rndradius)) -- random point near spawnpoint, but more often closer to it's center if particle.radiusfade ~= nil and particle.radiusfade ~= false then local sizecoef = (VecLength(VecSub(position, spawnposition))/particle.spawnradius) if sizecoef > 1 then sizecoef = 1 end radius = radius * sizecoef endradius = endradius * sizecoef life = life * sizecoef end end ----PARTICLE ParticleReset() if particle.typeis ~= nil and particle.typeis ~= "" then ParticleType(particle.typeis) end if particle.collide ~= nil then ParticleCollide(particle.collide) end if particle.endcolor == nil or particle.color == particle.endcolor then ParticleColor(particle.color[1], particle.color[2], particle.color[3]) else ParticleColor(particle.color[1], particle.color[2], particle.color[3], particle.endcolor[1], particle.endcolor[2], particle.endcolor[3]) end if particle.drag ~= nil then ParticleDrag(particle.drag) end if particle.alphaend ~= nil then ParticleAlpha(particle.alpha, particle.alphaend) else ParticleAlpha(particle.alpha) end if particle.endgravity ~= nil then ParticleGravity(particle.gravity, particle.endgravity) else ParticleGravity(particle.gravity) end if particle.endsize == nil or particle.size == particle.endsize or radius < particle.endsize then ParticleRadius(randomrange * radius, radius, "constant", particle, particle.fadein, particle.fadeout) else ParticleRadius(randomrange * radius, endradius, "constant", particle.sizefadein, particle.sizefadeout) end if particle.sticky ~= nil then ParticleSticky(particle.sticky) end if particle.stretch ~= nil then ParticleStretch(particle.stretch) end ParticleTile(particle.tile) if particle.glow ~= nil and particle.glow > 0 and particle.endglow ~= nil then ParticleEmissive(randomrange * particle.glow, particle.endglow, "easeout") elseif particle.glow ~= nil and particle.glow > 0 and particle.endglow == nil then ParticleEmissive(randomrange * particle.glow) end if particle.rotation == nil then particle.rotation = 0 end if particle.endrotation == nil then ParticleRotation(randomrange * particle.rotation * ChooseRnd({-1, 1})) else ParticleRotation(randomrange * particle.rotation * ChooseRnd({-1, 1}), particle.endrotation * ChooseRnd({-1, 1}), "easeout") end SpawnParticle(spawnposition, velocityvector, life) end end