Jump to content
  • 0

Random BGM on OnPCLoadMapEvent


b1rbert

Question


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  47
  • Reputation:   3
  • Joined:  05/04/14
  • Last Seen:  

Hey,

wanted to ask for a script that randomly chooses between 5 options of playBGM whenever OnPCLoadMapEvent happens.

tried around a bit myself but I'm not really getting it at the moment, maybe someone can whip up something simple real quick.

huge thanks in advance

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 1

  • Group:  Members
  • Topic Count:  79
  • Topics Per Day:  0.02
  • Content Count:  480
  • Reputation:   67
  • Joined:  08/28/12
  • Last Seen:  

switch(rand(1,5)) {
case 1:
	playBGM "<BGM filename>";
	end;
case 2:
	playBGM "<BGM filename>";
	end;
case 3:
	playBGM "<BGM filename>";
	end;
case 4:
	playBGM "<BGM filename>";
	end;
case 5:
	playBGM "<BGM filename>";
	end;
}

 

  • MVP 1
Link to comment
Share on other sites

  • 1

  • Group:  Members
  • Topic Count:  63
  • Topics Per Day:  0.02
  • Content Count:  1016
  • Reputation:   191
  • Joined:  11/27/14
  • Last Seen:  

Try this let me know if it works . But i read some other comments and i think you already found what you need . I just want to put my entry 

 

- script RandomBGM -1,{

OnInit:
    // Define the map where the BGM should be randomized
    set .map$, "prontera";
    // Define the list of BGMs
    setarray .bgms$[0], "BGM/01.mp3", "BGM/02.mp3", "BGM/03.mp3", "BGM/04.mp3";
    // Initialize an array to track played BGMs
    set .played[0], 0, 0, 0, 0;
    set .totalPlayed, 0;

    // Define a global label to set BGM on map load
    OnPCLoadMapEvent:
        // Check if the player has loaded the specific map
        if (strcharinfo(3) == .map$) {
            // Check if all BGMs have been played
            if (.totalPlayed >= getarraysize(.bgms$)) {
                // Reset the played array
                set .totalPlayed, 0;
                for (set .i, 0; .i < getarraysize(.bgms$); set .i, .i + 1) {
                    set .played[.i], 0;
                }
            }

            // Find a BGM that hasn't been played yet
            do {
                set .randomIndex, rand(getarraysize(.bgms$));
            } while (.played[.randomIndex]);

            // Mark the BGM as played
            set .played[.randomIndex], 1;
            set .totalPlayed, .totalPlayed + 1;

            // Play the random BGM
            playbgm .bgms$[.randomIndex];
        }
    end;
}

// Define the map to trigger the OnPCLoadMapEvent label
prontera mapflag loadevent;

 

  • Like 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  47
  • Reputation:   3
  • Joined:  05/04/14
  • Last Seen:  

29 minutes ago, WhiteEagle said:
switch(rand(1,5)) {
case 1:
	playBGM "<BGM filename>";
	end;
case 2:
	playBGM "<BGM filename>";
	end;
case 3:
	playBGM "<BGM filename>";
	end;
case 4:
	playBGM "<BGM filename>";
	end;
case 5:
	playBGM "<BGM filename>";
	end;
}

 

Thanks a lot. Works like a charm.

I actually tried something similiar like your script before with the examples you can find in different scripts but what I had put together didnt work.

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  79
  • Topics Per Day:  0.02
  • Content Count:  480
  • Reputation:   67
  • Joined:  08/28/12
  • Last Seen:  

This system would be interesting when one BGM is over, another BGM is randomly selected.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  47
  • Reputation:   3
  • Joined:  05/04/14
  • Last Seen:  

What I found out so far is that once the BGM it selects is over, the normal BGM that usually plays starts. Could be avoided by making the BGMs a lot longer but it will still reach the end eventually.

Currently have the NPC standing in Prontera, as soon as the Payon BGM I choose in the script ended, it started the Prontera theme even though it wasn't in the list.

Could probably work around that with some sort of loop script but haven't look at it yet

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  36
  • Topics Per Day:  0.01
  • Content Count:  111
  • Reputation:   1
  • Joined:  01/05/13
  • Last Seen:  

On 30/06/2024 at 22:30, Poring King said:

Tente isso, deixe-me saber se funciona. Mas eu li alguns outros comentários e acho que você já encontrou o que precisa. Eu só quero colocar minha entrada 

 







 

Good evening, when I try to run this script I get player error [Error]: buildin_strcharinfo: fatal error ! player not attached!
[Debug]: Function: strcharinfo (1 parameter):

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...