function init() x,y,z,rx,ry,rz = 5,-.65,-.8,0,0,0 force = 30 --RegisterTool("papergun",GetTranslatedStringByKey("PAPER_GUN"),"MOD/vox/papergun.vox") --SetBool("game.tool.papergun.enabled",true) --SetString("game.player.tool","papergun") testClearSound = LoadSound("valuable.ogg") pickupSnd = LoadSound("MOD/sound/papergrab0.ogg") shootSnd = LoadSound("MOD/script/paperlauncher/papergun0.ogg") triggers = FindTriggers("deliverytrigger", true) papers = {} shootHaptic = LoadHaptic("MOD/haptic/papergun_fire.xml") local toolHaptic = LoadHaptic("MOD/haptic/papergun_tool.xml") SetToolHaptic("papergun", toolHaptic); end function tick(dt) if GetString("game.player.tool") == "papergun" then --SetString('game.tool.papergun.ammo.display',"") SetValue("x",.2,"linear",.1) local weppos = Vec(x,y,z) local weprot = QuatEuler(rx,ry,rz) SetToolTransform(Transform(weppos,weprot)) local bt = GetBodyTransform(GetToolBody()) local currentAmmo = GetInt("game.tool.papergun.ammo") if InputPressed("usetool") and GetBool("game.player.canusetool") and currentAmmo > 0 then PlaySound(shootSnd) PlayHaptic(shootHaptic, 1) local dir = QuatRotateVec(bt.rot, Vec(0,0,-1)) spawnDust(VecAdd(bt.pos, VecScale(dir, 0.9)), dir) currentAmmo = currentAmmo - 1 SetInt("game.tool.papergun.ammo", currentAmmo) local paper = Spawn("",bt)[2] table.insert(papers, paper) SetBodyTransform(paper,Transform(TransformToParentPoint(GetPlayerCameraTransform(),Vec(0.4,-.5,-.3)),GetPlayerCameraTransform().rot)) if GetBool("level.run") then SetTag(paper,"paper") SetDescription(paper, "loc@A_NEWSPAPER") else SetTag(paper,"oldpaper") SetDescription(paper, "loc@AN_OLD") end SetBodyVelocity(paper,TransformToParentVec(GetPlayerCameraTransform(),Vec(0,1,-force))) local angVel = Vec(math.random(-5,5),0,0) SetBodyAngularVelocity(paper, angVel) end end for i=1, #papers do if GetPlayerInteractBody() == papers[i] and InputPressed("interact") then if GetBool("level.run") and HasTag(papers[i], "oldpaper") then SetString("hud.notification", "loc@UI_HUD_PICKED_UP_NEWSPAPER") Delete(papers[i]) PlaySound(pickupSnd) else local currentAmmo = GetInt("game.tool.papergun.ammo") currentAmmo = currentAmmo + 1 SetInt("game.tool.papergun.ammo", currentAmmo) Delete(papers[i]) PlaySound(pickupSnd) end end end for i=1, #triggers do if not HasTag(triggers[i],"cleared") then for j=1, #papers do if IsBodyInTrigger(triggers[i], papers[j]) and HasTag(papers[j], "paper") then SetTag(triggers[i], "cleared") Delete(papers[j]) end if IsBodyInTrigger(triggers[i], papers[j]) and not HasTag(papers[j], "testcleared") and not HasTag(papers[j], "paper") then SetTag(triggers[i], "testcleared") SetTag(papers[j], "testcleared") PlaySound(testClearSound) end end end end end function spawnDust(pos, dir) ParticleReset() ParticleDrag(0.2) ParticleTile(0) ParticleCollide(0) for i = 1, 30, 1 do local life = 0.4 + math.random() * 0.4 local c0 = 0.6 + math.random() * 0.2 local c1 = 0.8 + math.random() * 0.1 ParticleColor(c0, c0, c0, c1, c1, c1) local a = 0.1 + math.random() * 0.2 ParticleAlpha(a, a, "constant", 0.1, 0.7) local radius = 0.1 + math.random() * 0.3 ParticleRadius(radius, radius) ParticleGravity((math.random() * 2.0 - 1.0) * 0.2) local angVel = (math.random() * 2.0 - 1.0) * 2.0 * math.pi * 3.0 ParticleRotation(angVel, angVel*0.5) local direction = dir direction = VecAdd(direction, VecScale(Vec(math.random() * 2.0 - 1.0, math.random() * 2.0 - 1.0, math.random() * 2.0 - 1.0), 0.6)) local velocity = VecScale(direction, 1.0 + math.random() * 3.0) local position = VecAdd(pos, VecScale(dir, math.floor(i/3) * 0.5)) SpawnParticle(position, velocity, life) end end