henesua

aa_ex_music

Feb 15th, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //::///////////////////////////////////////////////
  2. //:: aa_ex_music
  3. //:://////////////////////////////////////////////
  4. /*
  5.     Use: Executed by an area
  6.  
  7.     Recursive script function that cycles through a series of songs.
  8.     Local int: SONG_ID_01 (see: ambientmusic.2da)
  9.  
  10.     Last two chars determines order that track will play in.
  11.  
  12. */
  13. //:://////////////////////////////////////////////
  14. //:: Created By: The Magus (2012 feb 14)
  15. //:: Modified:
  16. //:://////////////////////////////////////////////
  17.  
  18. #include "aa_inc_time"
  19.  
  20. void main()
  21. {
  22.     object oArea    = OBJECT_SELF;
  23.     int nPCs        = GetLocalInt(oArea, "PC_COUNT");
  24.     int nNow        = GetCurrentGameTime(TRUE);
  25.     int nChange     = GetLocalInt(oArea, "SONG_CHANGE_TIME");
  26.  
  27.     if (nPCs==0)
  28.     {
  29.         // no PCs present. Reset.
  30.         MusicBackgroundStop(oArea);
  31.         SetLocalInt(oArea, "SONG_ID_CURRENT", 0);
  32.         MusicBackgroundChangeDay(oArea, 0);
  33.         MusicBackgroundChangeNight(oArea, 0);
  34.     }
  35.     else if(nChange<=nNow)// it is time to change a song and we have a player present
  36.     {
  37.         int nSongID;
  38.         int nTrack      = GetLocalInt(oArea, "SONG_ID_CURRENT")+1;
  39.         int nSongLength; float fSongLength; string sTrack;
  40.         if(nTrack<10)
  41.             sTrack = "0"+IntToString(nTrack);
  42.         else
  43.             sTrack = IntToString(nTrack);
  44.         nSongID         = GetLocalInt(oArea, "SONG_ID_"+sTrack);
  45.         if(!nSongID)
  46.         {
  47.             nTrack      = 1;
  48.             nSongID     = GetLocalInt(oArea, "SONG_ID_01");
  49.         }
  50.  
  51.         string sSongLength = Get2DAString("ambientmusic","LENGTH",nSongID);
  52.         if(sSongLength == "****")
  53.             sSongLength = "0";
  54.         nSongLength =   StringToInt(sSongLength);
  55.  
  56.         int nDelay;
  57.         if(nTrack==1)   { nDelay    = 1; }
  58.         else            { nDelay    = 1; }
  59.  
  60.         MusicBackgroundStop(oArea);
  61.         MusicBackgroundChangeDay(oArea, nSongID);
  62.         MusicBackgroundChangeNight(oArea, nSongID);
  63.         MusicBackgroundSetDelay(oArea, nDelay*1000);
  64.         MusicBackgroundPlay(oArea);
  65.  
  66.         SetLocalInt(oArea, "SONG_ID_CURRENT", nTrack);
  67.         SetLocalInt(oArea, "SONG_CHANGE_TIME", nNow+nSongLength+nDelay);
  68.         fSongLength = IntToFloat(nSongLength+nDelay)+0.25;
  69.         if(nSongLength>0)
  70.             DelayCommand(fSongLength, ExecuteScript("aa_ex_music", oArea));
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment