Project Zomboid

Project Zomboid

True Music
Matola 21 Jun, 2023 @ 7:56pm
Help in a mod based in the true music
Recently I'm trying to make a jukebox working mod, and everything is going good, but I wanted to know how you did the sound range and the sound fade as the player gets far from the object that is playing, here's the code of the mod I'm doing, that is based on another mod called gkjukebox
--*********************************************************** --** BBUANG Dang! --** GK Play Mode 41.53+ --** Context menu for playing about ZukeBox object --*********************************************************** require "TimedActions/ISBaseTimedAction" GKPlay = ISBaseTimedAction:derive("GKPlay"); local song = nil; function GKPlay:isValid() return true; end function GKPlay:waitToStart() self.character:faceThisObject(self.machine); return self.character:shouldBeTurning(); end function GKPlay:update() local isPlaying = self.gameSound and self.gameSound ~= 0 and self.character:getEmitter():isPlaying(self.gameSound) if not isPlaying then local soundRadius = 1 local volume = 1 -- Use the emitter because it emits sound in the world (zombies can hear) self.gameSound = self.character:getEmitter():playSound(self.soundFile); addSound(self.character, self.character:getX(), self.character:getY(), self.character:getZ(), soundRadius, volume) end end function GKPlay:start() self:setOverrideHandModels(nil, nil) end function GKPlay:stop() --ISBaseTimedAction.stop(self); end function GKPlay:perform() if song then getSoundManager():StopSound(song); song = nil; end if self.playtype == "1" then song = getSoundManager():PlayWorldSound(self.soundEnd, self.machine:getSquare(), 0, 20, 1.0, false); addSound(self.machine, self.machine:getX(), self.machine:getY(), self.machine:getZ(), 100, 100) elseif self.playtype == "2" then song = getSoundManager():PlayWorldSound(self.soundEnd, self.machine:getSquare(), 0, 20, 1.0, false); end end function GKPlay:new(character, machine, sound, soundEnd, length, playtype) local o = {} setmetatable(o, self) self.__index = self o.character = character o.machine = machine o.soundFile = sound o.soundEnd = soundEnd o.stopOnWalk = true; o.stopOnRun = true; o.maxTime = length o.gameSound = 0 o.deltaTabulated = 0 o.playtype = playtype return o; end
If anyone know how to make the sound slowly fade away instead of just disappearing please let me know. Thankyou already