A Quick & Dirty mp3 player for MOHAA

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Innkeeper
Colonel
Posts: 475
Joined: Mon Nov 25, 2002 10:13 pm
Location: NC, USA (about 7.5 klicks from the capital dome)
Contact:

A Quick & Dirty mp3 player for MOHAA

Post by Innkeeper »

Just on a whim I decided to add functionality to MOHAA to play various mp3 files while I was testing my map. I just got a little tired of hearing the same old things and wanted to hear some music. So I bound the numbers 0 through 9 on the numeric keypad to play 9 different mp3s. This is not something for a released map, but it was fun to create and breaks the monotony while testing.

If anyone is interested, this is how I did it, just remember it was quick and probably very dirty code.

Step 1: Edit the ?unnamedsoldier.cfg? and add the following:

Code: Select all

bind F7 "ik_mp3_on"
bind F8 "ik_mp3_off"

bind KP_INS "ik_mp3_0"
bind KP_END "ik_mp3_1"
bind KP_DOWNARROW "ik_mp3_2"
bind KP_PGDN "ik_mp3_3"
bind KP_LEFTARROW "ik_mp3_4"
bind KP_5 "ik_mp3_5"
bind KP_RIGHTARROW "ik_mp3_6"
bind KP_HOME "ik_mp3_7"
bind KP_UPARROW "ik_mp3_8"
bind KP_PGUP "ik_mp3_9"

alias ik_mp3_on "set ik_mp3on 1"
alias ik_mp3_off "set ik_mp3on 0"
alias ik_mp3_9 "set ik_mp3 9"
alias ik_mp3_8 "set ik_mp3 8"
alias ik_mp3_7 "set ik_mp3 7"
alias ik_mp3_6 "set ik_mp3 6"
alias ik_mp3_5 "set ik_mp3 5"
alias ik_mp3_4 "set ik_mp3 4"
alias ik_mp3_3 "set ik_mp3 3"
alias ik_mp3_2 "set ik_mp3 2"
alias ik_mp3_1 "set ik_mp3 1"
alias ik_mp3_0 "set ik_mp3 0"
Don?t worry about where you add them; because once MOHAA writes to this file again, they will be rearranged.

Step 2: Make a folder in ?\main? called ?mp3s? and add the mp3 files you want to hear. Make sure that they do not have spaces in their names.

Step 3: Create a ?yourmapname.mp3s? file and add the names of the mp3 files. Then put it in the ?\main\mp3s? folder. The following is an example.

Code: Select all

// snow.mp3s

level.mp30 = none
level.mp31 = "Peter_Gabrial_-_Steam.mp3"
level.mp32 = "Glen_Miller_-_In_the_Mood.mp3"
level.mp33 = "Artie_Shaw_-_American_Patrol.mp3"
level.mp34 = "Peter_Gabrial_-_Shock_The_Monkey_(Extended_Version).mp3"
level.mp35 = "Peter_Gabrial_-_Sledgehammer.mp3"
level.mp36 = "Queen_-_Another_One_Bites_The_Dust.mp3"
level.mp37 = none
level.mp38 = none
level.mp39 = none
Make sure that there arn't any spaces in the filenames.

Step 4: Copy ?jukebox.scr? to the ?main\mp3s? folder. A copy of ?jukebox.scr? is below:

Code: Select all

//
// jukebox.scr
//
// SCRIPTING: Innkeeper w/lots of coffee

main local.mp3s:
   if(level.jukebox_run == 1)
   {
      end
   }

   println "DEBUG =====> Loading jukebox.scr"


   level waittill spawn

   if(local.mp3s != NIL)
   {
      if(level.mp3s == NIL)
      {
         level.mp3s = local.mp3s
      }
   }
   if(level.mp3s != NIL)
   {
      local.string = ("mp3s/" + level.mp3s + ".mp3s")
      exec local.string
      println ("DEBUG =====> using mp3 list file => " + local.string)
      forcemusic none none
   }

   thread jukebox

   level.jukebox_run = 1
end


jukebox:
   local.music = ("none")
   local.lastmp3 = getcvar(ik_mp3)
   local.newmp3 = getcvar(ik_mp3)

   setcvar ik_mp3on 1
   setcvar ik_mp3 1

   while(1)
   {
      if(getcvar(ik_mp3on)&& $player != NULL)
      {
         local.newmp3 = getcvar(ik_mp3)
         if(local.newmp3 != local.lastmp3)
         {
            switch(local.newmp3)
            {
               case 1: local.music = level.mp31
                        break
               case 2: local.music = level.mp32
                        break
               case 3: local.music = level.mp33
                        break
               case 4: local.music = level.mp34
                        break
               case 5: local.music = level.mp35
                        break
               case 6: local.music = level.mp36
                       break
               case 7: local.music = level.mp37
                       break
               case 8: local.music = level.mp38
                       break
               case 9: local.music = level.mp39
                       break
               case 0: local.music = level.mp30
                        break
                       local.music = ("none")
            }
            if(local.music != "none")
            {
               local.string = ("tmstart mp3s/" + local.music)
               println ("music is " + local.string)
               $player stufftext "tmstop"
               wait 0.5
               $player stufftext ("tmstart mp3s/" + local.music)
            }
            else
            {
               println ("music is none")
            }
            local.lastmp3 = local.newmp3
         }
      }
      else
      {
         $player stufftext "tmstop"
      }

      wait 0.5
   }
end
Step 5: Add ?exec mp3s/jukebox.scr yourmapname? to your map's script after "level waittill prespawn"

That?s it. Music is on by default playing level.mp31, F8 turns it off and F7 turns it on. Pressing a number 0 through 9 selects the music from the ?yourmapname.mp3s? file, level.mp30 being for the number ?0? level.mp31 for number ?1?, and so on. If the song is ?none?, the music will not change from the currently playing song.

This was just for fun. If anyone finds a really good use for it I would like to hear about it.
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

You could also bind a key to the 'playmp3' command :roll: .

Still nice work 8)
Image
Innkeeper
Colonel
Posts: 475
Joined: Mon Nov 25, 2002 10:13 pm
Location: NC, USA (about 7.5 klicks from the capital dome)
Contact:

Post by Innkeeper »

I've not had any luck with "playmp3" or "stopmp3". Maybe I was doing something wrong :?
Innkeeper
Colonel
Posts: 475
Joined: Mon Nov 25, 2002 10:13 pm
Location: NC, USA (about 7.5 klicks from the capital dome)
Contact:

New version of "jukebox.scr"

Post by Innkeeper »

I have made a new version of "jukebox.scr" that does not require changes to "unnamedsoldier.cfg" because the script makes the changes it's self.

WARNING: USE OF THIS SCRIPT WILL OVERWRITE KEY BINDINGS FOR F7, F8, AND THE KEYPAD NUMBER KEYS

The following is the revised version.

Code: Select all

//
// jukebox.scr version 1.1
//
// SCRIPTING: Innkeeper w/lots of coffee
//
// WARNING: USE OF THIS SCRIPT WILL OVERWRITE KEY 
//          BINDINGS FOR F7, F8, AND THE KEYPAD NUMBER KEYS
//
// USEAGE:  F7 turns on the mp3 player (the mp3 player is on by default)
//          F8 turns off the mp3 player
//          Keypad numbers play the associated mp3 
//            i.e. keypad 1/End plays level.mp31 which is the
//            default first mp3 played when the script starts
//               

main local.mp3s:
   if(level.jukebox_run == 1)
   {
      end
   }

   println "DEBUG =====> Loading jukebox.scr"


   level waittill spawn

   if(local.mp3s != NIL)
   {
      if(level.mp3s == NIL)
      {
         level.mp3s = local.mp3s
      }
   }
   if(level.mp3s != NIL)
   {
      local.string = ("mp3s/" + level.mp3s + ".mp3s")
      exec local.string
      println ("DEBUG =====> using mp3 list file => " + local.string)
      forcemusic none none
   }

   thread jukebox

   level.jukebox_run = 1
end


jukebox:
   local.music = ("none")
   local.lastmp3 = getcvar(ik_mp3)
   local.newmp3 = getcvar(ik_mp3)

   local.doinit = 1

   setcvar ik_mp3on 1
   setcvar ik_mp3 1

   while(1)
   {
      if(getcvar(ik_mp3on)&& $player != NULL)
      {
         local.newmp3 = getcvar(ik_mp3)
         if(local.newmp3 != local.lastmp3)
         {
            switch(local.newmp3)
            {
               case 1: local.music = level.mp31
                        break
               case 2: local.music = level.mp32
                        break
               case 3: local.music = level.mp33
                        break
               case 4: local.music = level.mp34
                        break
               case 5: local.music = level.mp35
                        break
               case 6: local.music = level.mp36
                       break
               case 7: local.music = level.mp37
                       break
               case 8: local.music = level.mp38
                       break
               case 9: local.music = level.mp39
                       break
               case 0: local.music = level.mp30
                        break
                       local.music = ("none")
            }
            if(local.music != "none")
            {
               local.string = ("tmstart mp3s/" + local.music)
               println ("music is " + local.string)
               $player stufftext "tmstop"
               wait 0.5
               $player stufftext ("tmstart mp3s/" + local.music)
            }
            else
            {
               println ("music is none")
            }
            local.lastmp3 = local.newmp3
         }
         if(local.doinit)
         {
            $player stufftext "bind F7 set ik_mp3_on 1"
            $player stufftext "bind F8 set ik_mp3_on 0"

            $player stufftext "bind KP_INS set ik_mp3 0"
            $player stufftext "bind KP_END set ik_mp3 1"
            $player stufftext "bind KP_DOWNARROW set ik_mp3 2"
            $player stufftext "bind KP_PGDN set ik_mp3 3"
            $player stufftext "bind KP_LEFTARROW set ik_mp3 4"
            $player stufftext "bind KP_5 set ik_mp3 5"
            $player stufftext "bind KP_RIGHTARROW set ik_mp3 6"
            $player stufftext "bind KP_HOME set ik_mp3 7"
            $player stufftext "bind KP_UPARROW set ik_mp3 8"
            $player stufftext "bind KP_PGUP set ik_mp3 9"
            local.doinit = 0
         }
      }
      else
      {
         $player stufftext "tmstop"
      }

      wait 0.5
   }
end
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

LOL :)

Post by Rookie One.pl »

Wow, what a BIG AND RED warning ROTFL :lol: :lol: :lol: :lol:
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
TheShiznaeSpe
Major
Posts: 304
Joined: Wed Feb 05, 2003 11:45 pm
Location: US
Contact:

Post by TheShiznaeSpe »

actually, u can listen to mp3s in game without this script

-get kazaa lite or some kind of p2p prog
-before starting game, start playlist----then put the prog in the server tray
-then with music still on, start game
-go to the audio controls and turn music all the way down
-now press apply and u've got a makeshift player that requires only about .5% of computer
Post Reply