[solved] Gamemode's Sound Doesn't Always Play

Discuss all aspects of editing for ZDoom.
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

[solved] Gamemode's Sound Doesn't Always Play

Postby buu342 » Sat Nov 12, 2016 2:40 pm

Hi there.

I'm making a round based gamemode for Zandronum with ACS, and I'm having trouble with LocalAmbientSound.

So after every round, the gamemode plays an intermission song. This song is played via LocalAmbientSound. The reason I'm using this is because
1) SetMusic seems to leave a very small gap of white noise in the beggining before playing the song
2) The music is sometimes specific for players, as the music tells the player if they won or lost the round.

The way the system is set up is the server is constantly running the gamemode in the back, setting the rounds via numbers. When a round is over, it sets the round variable to 50, which in the client's code (which was activated via an ENTER script) is supposed to check if the round is 50. If it is, it sets an intermission song to play. However, if a player joins mid game, sometimes the song doesn't play at all.
Music is also meant to play when a player wins or loses a game, which is during round number 0.

Here's a video example of the gamemode in action (the bug is not shown): https://www.youtube.com/watch?v=tbT_RT0MW4M

Here's the code. I removed unnecessary lines. It's still a big script regardless.
Code: Select allExpand view
script 1 OPEN   //Server - Setup
{
//Do a bunch of things
ACS_EXECUTE(3,0,true);
}

script 2 ENTER  // Client - Setup
{
//Do a bunch of things
DoCodeClient[PlayerNumber()] = false;
acs_executealways(4,0);
}

// RoundReal 0 = Waiting between minigames (Intermission music)
// RoundReal 50 = Win/Loss screen (Win/Lose Music)
// RoundReal 100+ = Minigame itself
// RoundReal 666 = Game Over

script 3 (void) // Server - Round Runner
{
RoundReal = 0; // Round Real is a global variable which keeps track of the round stuff that was in the comment stack above this one
// Do a bunch of things
delay(140);
int round;
round = random(0,15)+100;
RoundReal = round;
ACS_Execute(round,0); // This executes one of the rounds.
}

script 4 (void) // Client - Round Music
{
    if (RoundReal == 0 && RoundNum < MaxRounds) // Play intermission music
    {   
   ACS_ExecuteAlways(9,0);
        if ((RoundNum == speedupround1 || RoundNum == speedupround2 || RoundNum == speedupround3 || RoundNum == speedupround4))
         ACS_Execute(11,1,0);
        else
         ACS_Execute(11,0,0);
   if (!(RoundNum == speedupround1 || RoundNum == speedupround2 || RoundNum == speedupround3 || RoundNum == speedupround4))
      hudmessage(s:"";HUDMSG_PLAIN,1,cR_ORANGE,0.5,0.3,1);
   else if (RoundReal == 0 && (RoundNum == speedupround1 || RoundNum == speedupround2 || RoundNum == speedupround3 || RoundNum == speedupround4))
      hudmessage(s:"Speed Up";HUDMSG_PLAIN,1,cR_BLUE,0.5,0.3,1);
    }
if (RoundReal == 50 && RoundSongPlaying == false)  // Play Victory/fail music
    {
        if ((CheckInventory("WonRoundItem") == 0) || (PlayerDiedInRound[PlayerNumber()] == true))
        {
         SetFont("BIGFONT");
         if (SpeedupNum == 0)
         LocalAmbientSound("DoomWare/Fail",127);
         if (SpeedupNum == 1)
         LocalAmbientSound("DoomWare/Fail2",127);
         if (SpeedupNum == 2)
         LocalAmbientSound("DoomWare/Fail3",127);
         if (SpeedupNum == 3)
         LocalAmbientSound("DoomWare/Fail4",127);
         if (SpeedupNum == 4)
         LocalAmbientSound("DoomWare/Fail5",127);
         WinSongPlaying[PlayerNumber()] = true;
         hudmessage(s:"You Failed!";HUDMSG_PLAIN,1,cR_RED,0.5,0.3,1);
        }
        else if (PlayerDiedInRound[PlayerNumber()] == false)
        {
         SetFont("BIGFONT");
         Score[PlayerNumber()] += 1;
         if (SpeedupNum == 0)
         LocalAmbientSound("DoomWare/Win",127);
         if (SpeedupNum == 1)
         LocalAmbientSound("DoomWare/Win2",127);
         if (SpeedupNum == 2)
         LocalAmbientSound("DoomWare/Win3",127);
         if (SpeedupNum == 3)
         LocalAmbientSound("DoomWare/Win4",127);
         if (SpeedupNum == 4)
         LocalAmbientSound("DoomWare/Win5",127);
         WinSongPlaying[PlayerNumber()] = true;
         hudmessage(s:"You Won!";HUDMSG_PLAIN,1,cR_Green,0.5,0.3,1);
        }
    }
    if (RoundReal == 104) // Client - Stop Moving
    {
      if (DoCodeClient[PlayerNumber()] == true) // This is to stop players that join mid round from playing
      {
      DoCodeClient[PlayerNumber()] = false;
           SetFont("BIGFONT");
           hudmessage(s:"Stop Moving";HUDMSG_PLAIN,1,cR_ORANGE,0.5,0.3,1);
           delay(70-(SpeedupNum*2));
           if (CalcSpeed(GetActorVelX(ID[PlayerNumber()]),GetActorVely(ID[PlayerNumber()])) > 11)
             thing_damage(ID[PlayerNumber()],10000000,MOD_BARREL);
      delay(35);
      }
    }
delay(1);
restart;
}

script 11 (int mus) // Client - Round Music
{
   if (mus == 1)
   {
      if (RoundNum == speedupround1) {
      LocalAmbientSound("DoomWare/SPEEDUP",127); }
      if (RoundNum == speedupround2) {
      LocalAmbientSound("DoomWare/Speedup2",127); }
      if (RoundNum == speedupround3) {
      LocalAmbientSound("DoomWare/Speedup3",127); }
      if (RoundNum == speedupround4) {
      LocalAmbientSound("DoomWare/Speedup4",127); }
      if (SpeedupNum == 1)
        delay(125);
        if (SpeedupNum == 2)
        delay(120);
        if (SpeedupNum == 3)
        delay(110);
        if (SpeedupNum == 4)
        delay(100);
      if (SpeedupNum == 0)
      delay(140);
      if (SpeedupNum == 1)
      delay(130);
      if (SpeedupNum == 2)
      delay(115);
      if (SpeedupNum == 3)
      delay(100);
      if (SpeedupNum == 4)
      delay(90);
   }
   if (mus == 0)
   {
      if (SpeedupNum == 0) {
      LocalAmbientSound("DoomWare/intro",127); }
      if (SpeedupNum == 1) {
      LocalAmbientSound("DoomWare/intro2",127); }
      if (SpeedupNum == 2) {
      LocalAmbientSound("DoomWare/intro3",127); }
      if (SpeedupNum == 3) {
      LocalAmbientSound("DoomWare/intro4",127); }
      if (SpeedupNum == 4) {
      LocalAmbientSound("DoomWare/intro5",127); }
      if (SpeedupNum == 0)
      delay(140);
      if (SpeedupNum == 1)
      delay(130);
      if (SpeedupNum == 2)
      delay(115);
      if (SpeedupNum == 3)
      delay(100);
      if (SpeedupNum == 4)
      delay(90);
   }
}

Script 104 (void) // Gamemode Example
{
    setMusic("D_MOVEIT");
    delay(70-(SpeedupNum*2));
    delay(35);
    setMusic(""); // at this point, the round over music should play, which tells the player that they won or lost
    RoundReal = 50;
    delay(66-(7*SpeedupNum)); // Give time to play the win/lose music before restarting the round running script.
    RoundNum +=1;
    ACS_EXECUTE(3,0);
}


Any suggestions? Feel free to ask me questions about the code itself and I will explain it.
Last edited by buu342 on Sun Nov 13, 2016 8:36 am, edited 1 time in total.
buu342
 
Joined: 03 Jan 2012

Re: Gamemode's Sound Doesn't Always Play

Postby buu342 » Sun Nov 13, 2016 8:36 am

I fixed it utilizing arrays in the variable which checks whether or not the song plays, and by using a delay in the script. I made also added some if checks to make sure that the player doesn't join during the time either song is playing to make sure that their client does not go out of sync. Thank you anyway!
buu342
 
Joined: 03 Jan 2012


Return to Editing (Archive)

Who is online

Users browsing this forum: No registered users and 3 guests