Jump to content

Recommended Posts

Hey, thanks for looking at the thread!

 

I have this Markiplier mod and it has custom fight music in it (borrowed some code from other mods that did the same thing) though it has errors... the 2 things I want to accomplish is making it fade out instead of instantly pausing and making it play the normal music whenever anybody except markiplier is playing! 

here is the code I am using... (in the modmain)

 

function MarkPostInit(markiplier)
 
---Music replacements
RemapSoundEvent( "dontstarve/music/music_danger", "markiplier_dance_party/music/danger_mark" )
RemapSoundEvent( "dontstarve/music/music_danger_cave", "markiplier_dance_party/music/danger_mark_cave" )
RemapSoundEvent( "dontstarve/music/music_danger_ruins", "markiplier_dance_party/music/danger_mark_ruins" )
RemapSoundEvent( "dontstarve/music/music_danger_winter", "markiplier_dance_party/music/danger_mark_winter" )
----Music dynamics
local DynamicMusic = Class(function(self, inst)
    self.enabled = true
 
    self.is_busy = false
    self.busy_timeout = 0
    
    self.playing_danger = false
end)
 
function DynamicMusic:OnStartDanger()
 
    if not self.enabled then return end
    
    self.danger_timeout = 10
    if not self.playing_danger then
        local epic = GetClosestInstWithTag("epic", self.inst, 30)
        local soundpath = nil
        
        if epic then
            soundpath = "dontstarve/music/music_epicfight"
        elseif GetWorld():IsCave() then
            soundpath = "dontstarve/music/music_danger_cave"
        else
            soundpath = "dontstarve/music/music_danger"
        end
 
        self.inst.SoundEmitter:PlaySound(soundpath, "danger")
        self:StopPlayingBusy()
        self.playing_danger = true
    end
end
 
 
function DynamicMusic:StopPlayingDanger()
    self.inst.SoundEmitter:KillSound("danger")
    self.playing_danger = false
end
 
function DynamicMusic:OnUpdate(dt)
 
    if self.danger_timeout and self.danger_timeout > 0 then
        self.danger_timeout = self.danger_timeout - dt
        if self.danger_timeout <= 0 then
            self:StopPlayingDanger()
        end
    end
 
    if self.busy_timeout and self.busy_timeout > 0 then
        self.busy_timeout = self.busy_timeout - dt
        if self.busy_timeout <= 0 then
            self:StopPlayingBusy()
            self.is_busy = false
        end
    end
end
end
 
------------------------------------------------------------------------If not playing as Markiplier
function NotMarkPostInit(markiplier)
 
---Music replacements
RemapSoundEvent( "dontstarve/music/music_danger", "dontstarve/music/music_danger" )
RemapSoundEvent("dontstarve/music/music_danger_cave", "dontstarve/music/music_danger_cave" )
RemapSoundEvent( "dontstarve/music/music_danger_ruins", "dontstarve/music/music_danger_ruins" )
RemapSoundEvent("dontstarve/music/music_danger_winter", "dontstarve/music/music_danger_winter" )
----Music dynamics
local DynamicMusic = Class(function(self, inst)
    self.enabled = true
 
    self.is_busy = false
    self.busy_timeout = 0
    
    self.playing_danger = false
end)
 
function DynamicMusic:OnStartDanger()
 
    if not self.enabled then return end
    
    self.danger_timeout = 10
    if not self.playing_danger then
        local epic = GetClosestInstWithTag("epic", self.inst, 30)
        local soundpath = nil
        
        if epic then
            soundpath = "dontstarve/music/music_epicfight"
        elseif GetWorld():IsCave() then
            soundpath = "dontstarve/music/music_danger_cave"
        else
            soundpath = "dontstarve/music/music_danger"
        end
 
        self.inst.SoundEmitter:PlaySound(soundpath, "danger")
        self:StopPlayingBusy()
        self.playing_danger = true
    end
end
 
 
function DynamicMusic:StopPlayingDanger()
    self.inst.SoundEmitter:KillSound("danger")
    self.playing_danger = false
end
 
function DynamicMusic:OnUpdate(dt)
 
    if self.danger_timeout and self.danger_timeout > 0 then
        self.danger_timeout = self.danger_timeout - dt
        if self.danger_timeout <= 0 then
            self:StopPlayingDanger()
        end
    end
 
    if self.busy_timeout and self.busy_timeout > 0 then
        self.busy_timeout = self.busy_timeout - dt
        if self.busy_timeout <= 0 then
            self:StopPlayingBusy()
            self.is_busy = false
        end
    end
end
end

 

AddSimPostInit(function(inst)
        if inst.prefab == "markiplier" then
                MarkPostInit(inst)
       else
                NotMarkPostInit(inst)
        end
end)

 

thanks so much if you got any ideas on how to fix these problems!!! :D

Edited by Fidooop

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...