View Single Post
  #5  
Old 01-30-2010, 05:36 PM
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
Here's a new and much much better version of it:

PHP Code:
//#CLIENTSIDE
function onCreated()
{
  
this.songList = new TStaticVar();
  
  
// Music file stored locally
  
this.songList.("My Example Music.mp3") = {
    { 
"mylevel.nw""my_gmap" }
  };
  
  
// Streamed song
  
this.songList.("My Example Music 2.mp3") = {
    { 
"mylevel2.nw""my_gmap2" },
    
"http://www.myexamplewebsite.com/music/"
  
};
}

function 
onPlayerEnters()
{
  
// Get the list of songs
  
temp.songList this.songList.getDynamicVarNames();
  
  for (
temp.songtemp.songList) {
    
// Data specific to this song
    
temp.data this.songList.(@temp.song);
    
// Is the song being streamed or played locally?
    
temp.streamed = (temp.data[1] == "" false true);
    
temp.volumetype = (temp.streamed "radiovolume" "mp3volume");
    
// Song name
    
temp.songpath = (temp.streamed temp.data[1] @ temp.song temp.song);
    
temp.printname extractfilebase(temp.song);
    
// File name
    
temp.currentsong extractfilename(getmusicfilename());
    
    
// If the current song isn't supposed to play in this area,
    // check if it's currently playing and stop it, then continue
    // with the next song.
    
if (!(player.level.name in temp.data[0])
     && !
onSpecialLevel(temp.data[0])) {
      if (
temp.currentsong == temp.song) {
        
player.chat "Stopped playing \"" temp.printname "\"...";
        
stopMusic();
      }
      continue;
    }
    
    
// Is the player already playing this song?
    
if (temp.currentsong == temp.song)
      break;
    else if (
temp.currentsong != temp.song)
      
stopMusic();
    
    
// If this song isn't streamed, does the player have it?
    
if (temp.streamed)
      
temp.fileexists true;
    else
      
temp.fileexists fileExists(temp.song);
    
// If he hasn't, warn about it and then stop.
    
if (!temp.fileexists) {
      
player.chat "Couldn't play \"" temp.printname "\"! Download from Start > Install Packages > Audio/Music";
      break;
    }
    
    
// Ok, let's see if volume is enabled or not!
    
temp.volumeenabled = (makevar("$pref::audio::" temp.volumetype) == false true);
    
// If it's not, warn about it and then stop.
    
if (!temp.volumeenabled) {
      
player.chat =  "Couldn't play \"" temp.printname "\"! Make sure your" SPC temp.volumetype SPC "is turned on in F3 options!";
      break;
    }
    
    
playlooped(temp.songpath);
    
player.chat "Playing \"" temp.printname "\"...";
  }
}

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;
  }

__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote