[Include] Music-box (Jukebox)
#1

What is this?

This is an include which allows you to add as much music-boxes (jukeboxes) on your server as you want. If you're using an object-streamer on your main script, then you should modify object and 3d label functions in this include.



Credits:

- ****** for foreach include,
- ZeeX for zcmd command processor.



Pictures:





How to use this?

Easy and simple. Scroll down and download the "mbox.inc" include file and place it into the "\pawno\include\" folder and do the same thing with "foreach.inc" and "zcmd.inc" files.

Open your main script and put this ...:
pawn Код:
#include <foreach>
#include <zcmd>
#include <mbox>
... right after the:
pawn Код:
#include <a_samp>
You can create and delete music-boxes dynamically.

Example:
pawn Код:
new
        mBox;
pawn Код:
mBox = CreateMusicBox(
    "Wisin & Yandel - Me Estas Tentando",       // ID: 0
    "Don Omar feat. Lucenzo - Danza Kuduro",    // ID: 1
    "Don Omar feat. Tego Calderon - Bandolero", // ID: 2
    "Wisin & Yandel - Sexy Movimiento",         // ID: 3
);
pawn Код:
LinkSongToURL(mBox, 0, "http://k007.kiwi6.com/hotlink/eosb9jsyjg/Wisin_and_Yandel_-_Me_Estas_Tentando.mp3");        // ID: 0
LinkSongToURL(mBox, 1, "http://k007.kiwi6.com/hotlink/k4fxncgxqa/Don_Omar_feat._Lucenzo_-_Danza_Kuduro.mp3");       // ID: 1
LinkSongToURL(mBox, 2, "http://k007.kiwi6.com/hotlink/c8gkefzp57/Don_Omar_feat._Tego_Calderon_-_Bandolero.mp3");    // ID: 2
LinkSongToURL(mBox, 3, "http://k007.kiwi6.com/hotlink/0puvwnwj1c/Wisin_and_Yandel_-_Sexy_Movimiento.mp3");          // ID: 3
pawn Код:
SetSongWaitTime(mBox, 0, 238)// ID: 0
SetSongWaitTime(mBox, 1, 202)// ID: 1
SetSongWaitTime(mBox, 2, 311)// ID: 2
SetSongWaitTime(mBox, 3, 269)// ID: 3
pawn Код:
AssignMusicBoxToPos(mBox, 1461.277, -1900.5, 21.86, 0.0, 0.0, 90.0);
As you can see, you first need to create the music-box, link the URL to the song, set the song waiting time and finally assign the music-box to the position where you want it. Scroll down and make sure to read how to use these functions correctly.



Functions:

CreateMusicBox
Information: This function creates a music-box with names of the songs you input.

Input parameters:
@name[] - Name of the song.
@... - Songs are limited with "MAX_SONGS_PER_MBOX" define.

returns - The function returns dynamic ID (starting with 0) of the created music-box. If the function returns the value -1, then the music-box wasn't created, which means you did something wrong.

Example:
pawn Код:
mBox = CreateMusicBox(
    "Wisin & Yandel - Me Estas Tentando",       // ID: 0
    "Don Omar feat. Lucenzo - Danza Kuduro",    // ID: 1
    "Don Omar feat. Tego Calderon - Bandolero", // ID: 2
    "Wisin & Yandel - Sexy Movimiento",         // ID: 3
);

LinkSongToURL
Information: This function links the URL of the song to the song. Remember that you must create a music-box before you use this function!

Input parameters:
@mboxid - Dynamic ID of the created music-box.
@songid - ID of the song in the specified music-box. First song has the ID 0, second ID 1 and so on.
@link[] - URL of the song.

returns - The function doesn't return a specific value.

Example:
pawn Код:
LinkSongToURL(mBox, 0, "http://k007.kiwi6.com/hotlink/eosb9jsyjg/Wisin_and_Yandel_-_Me_Estas_Tentando.mp3");        // ID: 0
LinkSongToURL(mBox, 1, "http://k007.kiwi6.com/hotlink/k4fxncgxqa/Don_Omar_feat._Lucenzo_-_Danza_Kuduro.mp3");       // ID: 1
LinkSongToURL(mBox, 2, "http://k007.kiwi6.com/hotlink/c8gkefzp57/Don_Omar_feat._Tego_Calderon_-_Bandolero.mp3");    // ID: 2
LinkSongToURL(mBox, 3, "http://k007.kiwi6.com/hotlink/0puvwnwj1c/Wisin_and_Yandel_-_Sexy_Movimiento.mp3");          // ID: 3

SetSongWaitTime
Information: This function sets the waiting time of the song before the next song starts with playing. Remember that you must create a music-box before you use this function!

Input parameters:
@mboxid - Dynamic ID of the created music-box.
@songid - ID of the song in the specified music-box. First song has the ID 0, second ID 1 and so on.
@time - Time of the song in seconds. If the length of the song is 3 minutes, then your waiting time for that song should be 180 (seconds), before the next song starts playing.

returns - The function doesn't return a specific value.

Example:
pawn Код:
SetSongWaitTime(mBox, 0, 238)// ID: 0
SetSongWaitTime(mBox, 1, 202)// ID: 1
SetSongWaitTime(mBox, 2, 311)// ID: 2
SetSongWaitTime(mBox, 3, 269)// ID: 3

AssignMusicBoxToPos
Information: This function assigns the music box to the position you want. Remember that you must create a music-box before you use this function!

Input parameters:
@mboxid - Dynamic ID of the created music-box.
@Float: x - X position of the music-box object.
@Float: y - Y position of the music-box object.
@Float: z - Z position of the music-box object.
@Float: rx - X rotation of the music-box object.
@Float: ry - Y rotation of the music-box object.
@Float: rz - Z rotation of the music-box object.
Float: range - The music-box song playing range in which the players will be able to hear the songs.

returns - The function doesn't return a specific value.

Example:
pawn Код:
AssignMusicBoxToPos(mBox, 1461.277, -1900.5, 21.86, 0.0, 0.0, 90.0);


Definitions:

These are the original definitions in the include file:
pawn Код:
#define MAX_MUSIC_BOXES (5)
#define MAX_SONGS_PER_MBOX (22)
#define MAX_MBOX_SONG_RANGE (50.0)
#define MAX_MBOX_WAIT_TIME (150)
#define MBOX_DIALOG_ID (7777)
Definition "MAX_MUSIC_BOXES" defines how many music-boxes you can have in the script. Definition "MAX_SONGS_PER_MBOX" defines maximum songs you can have on the music-box. Definition "MAX_MBOX_SONG_RANGE" defines the default song playing range of the music-box. Definition "MAX_MBOX_WAIT_TIME" defines the default song waiting time. The dialog ID of the song-dialog is 7777 defined with the "MBOX_DIALOG_ID" define. If you're already using number 7777 in your main script or any other script on your server, then make sure to change this definition to the number which is not in usage.



Explanation & command:

The command to open the song-dialog is "/musicbox". The song cost is $10.00 (you can change this yourself in the include file if you don't like it). Once you pick the song, you won't be able to change it for some time (this time is defined in the "MAX_MBOX_WAIT_TIME" define). If the song has finished and no one picks the next one, the music-box will automatically pick the next song on the list. If the song on the list is the last song, then the music-box will start playing from the start again. The players will hear the songs if they're in the range of the music-box.



Where to upload my songs?

I myself am using the Kiwi6 website for this.



Prepared songs:

Here are some songs which I uploaded and added to the script some time ago, so perhaps some of the URLs might not be working.



Download:

Reply
#2

Nice Job, REP4U
Reply
#3

Nice.

~Bravo brate. Evo jedan REP za tebe.
Reply
#4

Good work!
Reply
#5

You should use model ID: 1732 (CJ_Juke_Box) for the music box object, since some people might confuse the current object as an ATM machine, but nice work anyway lol.
Reply
#6

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
You should use model ID: 1732 (CJ_Juke_Box) for the music box object, since some people might confuse the current object as an ATM machine, but nice work anyway lol.
Yes, but that one looks old and rubbish (maybe some nice texture could help? ). I don't know, when I wrote this script for my server, I used an ATM object since I wasn't happy with other objects (including the one you suggested). But it doesn't matter, people can change their object ID in the INC file if they want, it's a work that requires a few seconds. Anyway, I'm glad you people like it. Enjoy.
Reply
#7

Good work Correlli!
Reply
#8

Nice
Reply
#9

I do not like the way you handle music box creation, but it's just my opinion. Code is fine
Reply
#10

This is more like it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)