Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Music System by Montana™
- #include <a_samp>
- #include <a_mysql>
- #include <foreach>
- #include <[MV]_Youtube>
- #include <zcmd>
- //Connect to host
- #define MYSQL_HOST "localhost"
- #define MYSQL_USER "root"
- #define MYSQL_DATABASE "sa-mp"
- #define MYSQL_PASSWORD ""
- #define COLOR_ORANGE 0xFFA100FF
- #define MusicDialog 1050
- #define PlaySong 1051
- #define AddSongLink 1052
- #define AddSongName 1053
- #define SongList 1054
- #define RemoveSong 1055
- #define MAX_SONGS 1250
- new mysql;
- new PlayerSongName[MAX_PLAYERS][256], PlayerSongLink[MAX_PLAYERS][256];
- new PlayerSongSelect[MAX_PLAYERS][MAX_SONGS];
- enum mInfo
- {
- ID,
- PlayerName[24],
- SongUsed,
- SongName[256],
- SongLink[256]
- }
- new MusicInfo[MAX_SONGS][mInfo];
- COMMAND:music(playerid, params[])
- {
- ShowPlayerDialog(playerid, MusicDialog, DIALOG_STYLE_LIST, "Music System", "Play Song\nMy Music\nAdd Music\nRemove Music\nStop Music", "Continue", "Cancel");
- return 1;
- }
- public OnFilterScriptInit()
- {
- mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
- mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
- if(mysql_errno() != 0) // checks if the server failed to connected or not
- {
- print("[MYSQL]: Failed to connect to MySQL Database");
- }
- else
- {
- print("I have connected to the MySQL server.");
- }
- LoadMusic();
- return 1;
- }
- public OnPlayerDisconnect(playerid)
- {
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case MusicDialog:
- {
- if(!response)
- {
- SendClientMessage(playerid, 0x42F3F198, "Music System closed.");
- return 1;
- }
- switch(listitem)
- {
- case 0:
- {
- ShowPlayerDialog(playerid, PlaySong, DIALOG_STYLE_INPUT, "Youtube link:", "Please enter the youtube link you wish to play example:\nhttps://www.youtube.com/watch?v=7csKaIhn8NY - Eminem - Legacy.", "Done", "Cancel");
- }
- case 1:
- {
- GetPlayerMusic(playerid);
- }
- case 2:
- {
- ShowPlayerDialog(playerid, AddSongLink, DIALOG_STYLE_INPUT, "Youtube link:", "Please enter the youtube link you would like to save for example:\nhttps://www.youtube.com/watch?v=7csKaIhn8NY - Eminem - Legacy.", "Done", "Cancel");
- }
- case 3:
- {
- GetPlayerMusicToDelete(playerid);
- }
- case 4:
- {
- StopYoutubeVideoForPlayer(playerid);
- }
- }
- }
- case PlaySong:
- {
- if(!response)
- {
- SendClientMessage(playerid, 0x42F3F198, "Music System closed.");
- return 1;
- }
- if(strfind(inputtext,"www.youtube.com",true) == -1) return SendClientMessage(playerid, 0x969696FF, "Error: Youtube links only please, if it doesn't work try an other."), ShowPlayerDialog(playerid, PlaySong, DIALOG_STYLE_INPUT, "Youtube link:", "Please enter the youtube link you would like to save for example:\nhttps://www.youtube.com/watch?v=7csKaIhn8NY - Eminem - Legacy.", "Done", "Cancel");
- PlayYoutubeVideoForPlayer(playerid, inputtext);
- }
- case AddSongLink:
- {
- if(!response)
- {
- SendClientMessage(playerid, 0x42F3F198, "Music System closed.");
- return 1;
- }
- if(strfind(inputtext,"www.youtube.com",true) == -1) return SendClientMessage(playerid, 0x969696FF, "Error: Youtube links only please, if it doesn't work try an other."), ShowPlayerDialog(playerid, AddSongLink, DIALOG_STYLE_INPUT, "Youtube link:", "Please enter the youtube link you would like to save for example:\nhttps://www.youtube.com/watch?v=7csKaIhn8NY - Eminem - Legacy.", "Done", "Cancel");
- format(PlayerSongLink[playerid], 256, inputtext);
- PlayYoutubeVideoForPlayer(playerid, inputtext);
- SendClientMessage(playerid, COLOR_ORANGE, "System: Testing the song, is this the right one and is it working? If not cancel it and try an other link.");
- ShowPlayerDialog(playerid, AddSongName, DIALOG_STYLE_INPUT, "Song or Artist Name:", "Please enter the song or artist name or both for example:\nHopsin - All your fault.", "Done", "Cancel");
- }
- case AddSongName:
- {
- if(!response)
- {
- SendClientMessage(playerid, 0x42F3F198, "Music System closed.");
- return 1;
- }
- if(strlen(inputtext) == 0 || strlen(inputtext) > 60)
- {
- SendClientMessage(playerid, 0x969696FF, "Invalid song name or artist, Length must be greater than 1 and less than 60.");
- ShowPlayerDialog(playerid, AddSongName, DIALOG_STYLE_INPUT, "Song or Artist Name:", "Please enter the song or artist name or both for example:\nHopsin - All your fault.", "Done", "Cancel");
- }
- format(PlayerSongName[playerid], 256, inputtext);
- SendClientMessage(playerid, COLOR_ORANGE, "System: We are now saving the song into our database, You can play it any time. /music then My Music.");
- new pname[24];
- GetPlayerName(playerid, pname, 24);
- new query[256];
- mysql_format(mysql, query, sizeof(query), "INSERT INTO `Music` (`Name`, `SongUsed`, `SongName`, `SongLink`) VALUES ('%e', 1, '%s', '%s')", pname, PlayerSongName[playerid], PlayerSongLink[playerid]);
- mysql_query(mysql, query);
- new str[256];
- format(str, sizeof(str), "System: You have saved youtube video %s into your music.", GetVideoTitle(playerid));
- SendClientMessage(playerid, COLOR_ORANGE, str);
- LoadMusic();
- }
- case SongList:
- {
- if(!response)
- {
- SendClientMessage(playerid, 0x42F3F198, "Music System closed.");
- return 1;
- }
- PlayYoutubeVideoForPlayer(playerid, MusicInfo[PlayerSongSelect[playerid][listitem]][SongLink]);
- LoadMusicLink(MusicInfo[PlayerSongSelect[playerid][listitem]][ID]);
- }
- case RemoveSong:
- {
- if(!response)
- {
- SendClientMessage(playerid, 0x42F3F198, "Music System closed.");
- return 1;
- }
- RemoveMusic(MusicInfo[PlayerSongSelect[playerid][listitem]][ID]);
- }
- }
- return 1;
- }
- stock GetMusic()
- {
- for(new i = 1; i < MAX_SONGS;i++)
- {
- if(MusicInfo[i][SongUsed] == 0)
- {
- return i;
- }
- }
- return -1;
- }
- stock RemoveMusic(id)
- {
- new query[128];
- mysql_format(mysql, query, sizeof(query), "DELETE FROM `Music` WHERE `ID`= %d", id);
- mysql_pquery(mysql, query);
- MusicInfo[id][SongUsed] = 0;
- }
- stock GetPlayerMusic(playerid)
- {
- new sendername[24];
- GetPlayerName(playerid, sendername, 24);
- new string[956];
- //new str[956];
- new combine[956];
- new found = 0;
- new item = 0;
- for(new i = 0; i < MAX_SONGS; i++)
- {
- if(MusicInfo[i][SongUsed] == 1)
- {
- if(strcmp(MusicInfo[i][PlayerName], sendername, true) == 0)
- {
- format(string, sizeof (string), "%s %s\n", string, MusicInfo[i][SongName]);
- format(combine, sizeof(combine), "%s", string);
- found = 1;
- PlayerSongSelect[playerid][item] = i;
- item = item + 1;
- }
- }
- }
- if(found == 0) return SendClientMessage(playerid, 0x969696FF, "Error: You haven't saved any music into the database yet.");
- ShowPlayerDialog(playerid, SongList, DIALOG_STYLE_LIST, "Music Player", combine, "Play", "Cancel");
- return 1;
- }
- stock GetPlayerMusicToDelete(playerid)
- {
- new sendername[24];
- GetPlayerName(playerid, sendername, 24);
- new string[956];
- //new str[956];
- new combine[956];
- new found = 0;
- new item = 0;
- for(new i = 0; i < MAX_SONGS; i++)
- {
- if(MusicInfo[i][SongUsed] == 1)
- {
- if(strcmp(MusicInfo[i][PlayerName], sendername, true) == 0)
- {
- format(string, sizeof (string), "%s %s\n", string, MusicInfo[i][SongName]);
- format(combine, sizeof(combine), "%s", string);
- found = 1;
- PlayerSongSelect[playerid][item] = i;
- item = item + 1;
- }
- }
- }
- if(found == 0) return SendClientMessage(playerid, 0x969696FF, "Error: You haven't saved any music into the database yet.");
- ShowPlayerDialog(playerid, RemoveSong, DIALOG_STYLE_LIST, "Music Player", combine, "Play", "Cancel");
- return 1;
- }
- stock LoadMusic()
- {
- new query[256];
- for(new i = 1; i < MAX_SONGS; i++)
- {
- format(query, sizeof(query), "SELECT * FROM Music WHERE ID=%i", i);
- mysql_function_query(mysql, query, true, "LoadMusicSQL", "d", i);
- }
- return 1;
- }
- forward LoadMusicSQL(id);
- public LoadMusicSQL(id)
- {
- new fields, rows;
- cache_get_data(rows, fields);
- if(rows)
- {
- if(MusicInfo[id][SongUsed] == 0)
- {
- new fetch[256];
- cache_get_field_content(0, "ID", fetch);
- MusicInfo[id][ID]= strval(fetch);
- cache_get_field_content(0, "Name", fetch);
- format(MusicInfo[id][PlayerName], 24, fetch);
- cache_get_field_content(0, "SongName", fetch);
- format(MusicInfo[id][SongName], 256, fetch);
- cache_get_field_content(0, "SongLink", fetch);
- format(MusicInfo[id][SongLink], 256, fetch);
- cache_get_field_content(0, "SongUsed", fetch);
- MusicInfo[id][SongUsed]= strval(fetch);
- print("I have loaded a song.");
- }
- }
- return 1;
- }
- LoadMusicLink(id)
- {
- new query[256];
- format(query, sizeof(query), "SELECT * FROM Music WHERE ID=%i", id);
- mysql_function_query(mysql, query, true, "ReLoadSongLinkSQL", "d", id);
- }
- forward ReLoadSongLinkSQL(id);
- public ReLoadSongLinkSQL(id)
- {
- new fields, rows;
- cache_get_data(rows, fields);
- if(rows)
- {
- if(MusicInfo[id][SongUsed] == 1)
- {
- new fetch[256];
- cache_get_field_content(0, "SongLink", fetch);
- format(MusicInfo[id][SongLink], 256, fetch);
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement