View Single Post
  #1  
Old 06-27-2008, 02:21 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Music Controller

A script that controls what song is played, and when.


PHP Code:
//#CLIENTSIDE
function onCreated()
{
  
this.songList = new TStaticVar();
  
  
/*
    this.songList.SONGNAME = { ARG1,
      { ARG2 }
    };
    ARG1 = determines if the song should stop playing when
           the players level name isn't in ARG2.
    ARG2 = an array with the levels the song should be played
           on, or what the level name should begin with.
           
           ~~~ EXAMPLE ~~~
           
    this.songList.("My Song Name") = { false,
      { "mylevelname.nw", "mylevelname2.nw", "my_gmap_" }
    };
  */
}

function 
onPlayerEnters()
{
  
temp.songList this.songList.getDynamicVarNames();
  for (
temp.songtemp.songList) {
    
temp.data this.songList.(@temp.song);
    
temp.song temp.song ".mp3";
    
temp.file getmusicfilename();
    
    
// Is temp.data[1] the players current level?
    
if (player.level.name in temp.data[1]) {
      if (
fileExists(temp.song)) playlooped(temp.song);
    }
    
// Ah well... is the player on a gmap, or does temp.data[1]
    // contain what the players level start with?
    
else if (isonmap || onSpecialLevel(temp.data[1])) {
      for (
temp.leveltemp.data[1]) {
        if (
player.level.name.starts(temp.level)) {
          if (
fileExists(temp.song)) playlooped(temp.song);
          break;
        }
      }
    }
    
    
// Should the song play in this level?
    
if (isMusicPlaying() && temp.file.ends(temp.song)) {
      if (
temp.data[0] == true && !(player.level.name in temp.data[1]) && !onSpecialLevel()) stopMusic();
    }
  }
}

function 
onSpecialLevel(levels)
{  
  for (
temp.levellevels) {
    if (
temp.level.name.ends(".nw")
     || 
temp.level.name.ends(".graal")) continue;
    
    if (
player.level.name.starts(temp.level)) return temp.level;
  }

As always, please, use the forums reputation system to show if you like the script or not.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote