Jump to content
  • 0

Random BGM on OnPCLoadMapEvent


Question

Posted

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

6 answers to this question

Recommended Posts

  • 1
Posted
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
  • 1
Posted

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
  • 0
Posted
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.

 

  • 0
Posted

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

  • 0
Posted
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):

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...