Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Need help?

    Create a topic in the appropriate section
    Don't write everything in the chat!
  • Take a look at the marketplace

    There you can buy
    everything related to game servers
  • Don't want a ban?

    Please read our rules
    Don't disturb the order!
  • Sell or buy?

    Use services of the guarantor
    We will make your deal safe
  • 0
Sign in to follow this  
RichardTwi

Помощь с синхронизацией звука.

Как правильно синхронизировать звуки в DayZ?
При включении радио звук играет у всех, но если с помощью действия я меняю m_CurrentTrackIndex, то это слышно только у клиента, который и сделал действие.
Есть ли какой-либо пример синхронизации звука? Или как это починить?
p.s. я пока что только обучаюсь
 

class radioitembasetest : ItemBase
{
	protected EffectSound m_ActiveSound;
	protected bool m_Playing;
	protected int m_CurrentTrackIndex = 0;
    protected float m_RandomInt;
    protected bool m_ItWillBeActivated;
	protected ref array<string> SoundSets = {};

    protected bool m_SyncStatus;

    void radioitembasetest()
    {
       	RegisterNetSyncVariableBool( "m_SyncStatus" );
		RegisterNetSyncVariableInt(	"m_CurrentTrackIndex" );
    }

    override void OnVariablesSynchronized()
	{
		super.OnVariablesSynchronized();
        
        if( m_SyncStatus && !IsPlaying() ) TurnOn();
        if( !m_SyncStatus && IsPlaying() ) TurnOff();
	}

    override bool CanPutInCargo( EntityAI parent )
    {
        return false;
    }
    override bool CanPutIntoHands (EntityAI parent)
	{
		return false;
	}

    void NextTrack()
    {
        if(SoundSets.Count())
        {
            if(m_CurrentTrackIndex >= SoundSets.Count())
            {
                m_CurrentTrackIndex = 0;
            } else {
                ++m_CurrentTrackIndex;
            }
            Play();
        }
    }
	
	void RefreshFrequency()
	{
		RadioRef();
		Play();
	}

    bool Play()
    {
        if(!CanPlaySound())
            return false;


		if (!GetGame().IsServer()  ||  !GetGame().IsMultiplayer())
        {
			m_ActiveSound.SoundStop();
        	m_ActiveSound = SEffectManager.CreateSound(SoundSets[m_CurrentTrackIndex], GetPosition(), 0, 0, false, true);
			m_ActiveSound.Event_OnSoundWaveEnded.Insert(NextTrack);
        	m_ActiveSound.SetParent(this);
       	 	m_ActiveSound.SetSoundAutodestroy(true);
			m_ActiveSound.SoundPlay();
			SetSynchDirty();
            SetTapeVolume();
        }
		m_Playing = true;
        m_SyncStatus = true;
		SetSynchDirty();

        return true;
    }

    void Stop()
    {
        m_Playing = false;
        m_SyncStatus = false;
        SetSynchDirty();

        if (m_ActiveSound)
        {
            m_ActiveSound.SoundStop();
        }
    }

    bool CanPlaySound()
    {
		return true;
    }

    void TurnOn()
    {
        if ( GetCompEM().CanWork() )
        {
            GetCompEM().SwitchOn();
        }
    } 
    
    void TurnOff()
    {
        GetCompEM().SwitchOff();
    }

    override void OnSwitchOn()
    {
        RadioFuncRandomization();
        if (!Play())
        {
            TurnOff();
        }
    }
	
	void RadioRef()
	{
			m_RandomInt = Math.RandomFloat(0,15); // 0.000....1 - 14
            m_RandomInt = Math.Floor(m_RandomInt);
            m_CurrentTrackIndex = m_RandomInt;
			SetSynchDirty();
			
	}
	
    void RadioFuncRandomization()
    {
        if(!isActivated())
        {
            m_RandomInt = Math.RandomFloat(0,15); // 0.000....1 - 14
            m_RandomInt = Math.Floor(m_RandomInt);
            m_CurrentTrackIndex = m_RandomInt;
            m_ItWillBeActivated = true;
            Print("[randomization] m_CurrentTrackIndex = " + m_CurrentTrackIndex + " --- " + "m_RandomInt = " + m_RandomInt);
        }
        else
        {
            return;
        }
        GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(RadioFuncDelay, 60000, false);
    }

    void RadioFuncDelay()
    {
        m_ItWillBeActivated = false;
    }

    override void OnSwitchOff()
	{
		if(IsPlaying())
		{
			Stop();
            delete m_ActiveSound;
		}
	}

    bool isActivated()
    {
        return m_ItWillBeActivated;
    }

    bool IsPlaying()
    {
        return m_Playing;
    }
	
	void SetTapeVolume()
    {
        m_ActiveSound.SetMaxVolume(3.0);
    }

    override void SetActions()
	{
        super.SetActions();
		AddAction(ActionTurnOnWhileOnGround);
		AddAction(ActionTurnOffWhileOnGround);
		AddAction(ReFrequencyRadio);
        RemoveAction(ActionTakeItem);
        RemoveAction(ActionTakeItemToHands);
	}
}

 

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

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
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you automaticly agree to our Guidelines and Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.