[MySQL-R39] Music Player

Započeo ich.
19. Dec. 2017. Zaključano
2,924
pregleda
9
postova
Lovacnadrolje42
5
Underboss
19. Dec. 2017.
Tip: Filterscript
Autor: Rolux




MySQL Table /
CREATE TABLE `songs` (
  `ID` tinyint(4) NOT NULL,
  `Artist` text NOT NULL,
  `Song` text NOT NULL,
  `Link` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `songs`
  ADD PRIMARY KEY (`ID`);

ALTER TABLE `songs`
  MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;


Script /
#include 	
#include 
#include
#include

//»Defines
#define MAX_SONGS 100
#define DIALOG_SONG 100

//»Enum
enum music
{
m_id,
m_artist,
m_song,
m_link
}

//»Vars
new sql,songs,mInfo;

//»Forwards
forward LoadSongs();
forward InsertSong(a[],b[],c[]);

public OnFilterScriptInit()
{
mysql_log(LOG_ALL, LOG_TYPE_HTML);
sql = mysql_connect("127.0.0.1", "root", "music", "");
if(mysql_errno() != 0)
{
        print(" » ( ! )Failed to connect to the database!");
}
else
  {
        print(" » Successful connection to the database!");
}
print(" » Loading songs..");
mysql_tquery(sql, "SELECT * FROM songs", "LoadSongs");
return 1;
}

public OnFilterScriptExit()
{
mysql_close(sql);
return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_SONG)
{
if(response)
{
if(listitem == 0)
{
StopAudioStreamForPlayer(playerid);
  SendClientMessage(playerid,0xf03c3cAA,"Music stopped!");
}
else
{
            PlayAudioStreamForPlayer(playerid,mInfo[listitem-1]);
            new string;
            format(string,100,"Music started! / Performer: %s / Song : %s /",mInfo[listitem-1],mInfo[listitem-1]);
SendClientMessage(playerid,0x8a3cf0AA,string);
}
}
}
return 0;
}

public LoadSongs()
{
for(new i = 0; i < cache_get_row_count(); i++)
{
mInfo = cache_get_row_int(i,0);
cache_get_row(i, 1,mInfo,1,32);
cache_get_row(i, 2,mInfo,1,32);
cache_get_row(i, 3,mInfo,1,96);
songs ++;
}
printf(" » %d song(s) loaded from the database.",songs);
return true;
}

public InsertSong(a[],b[],c[])
{
mInfo = cache_insert_id();
strins(mInfo,a,0);
strins(mInfo,b,0);
strins(mInfo,c,0);
songs++;
return true;
}

stock ShowMusic(playerid)
{
new str = "Performer\t-\tSong\n{f03c3c}Stop music\n",str2,count;
for(new i = 0; i < songs; i++)
{
format(str2,sizeof(str2),"%s\t-\t%s\n",mInfo,mInfo);
strcat(str,str2);
count = 1;
}
if(count != 1) return SendClientMessage(playerid,0xf03c3cAA,"There is nothing to play. :/");
ShowPlayerDialog(playerid,DIALOG_SONG,DIALOG_STYLE_TABLIST_HEADERS,"MusicPlayer",str, "Select", "Exit");
return true;
}

stock Compare(comp[], with[]) // by fl0rian
{
new LenghtComp = strlen(comp);
new LenghtWith = strlen(with);
new Character;
if( LenghtComp != LenghtWith ) return false;
for( new i = 0; i < LenghtComp; i++ )
{
    if( comp == with )
    {
        Character++;
}
}
if( LenghtComp == Character ) return true;
return false;
}

CMD:mp(playerid,params[])
{
#pragma unused params
ShowMusic(playerid);
return true;
}

CMD:newsong(playerid,params[])
{
new artist,song,link,string;
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xf03c3cAA,"You are not authorized to use this command!!");
if(sscanf(params, "sss",artist,song,link)) return SendClientMessage(playerid,0xf03c3cAA,"/newsong [Link to mp3]");
for(new i = 0; i < songs; i++)
{
if(Compare(mInfo,artist) && Compare(mInfo,song)) return SendClientMessage(playerid,0xf03c3cAA,"This Song from the performer is already added!");
}
new query;
mysql_format(sql, query, 256, "INSERT INTO songs (Artist,Song,Link) VALUES ('%s','%s','%s')",artist,song,link);
mysql_tquery(sql, query,"InsertSong","sss",artist,song,link);
format(string,96,"You sucessfully added a song! Performer: %s , Song : %s",artist,song);
SendClientMessage(playerid,0x1cd657AA,string);
return true;
}

CMD:refresh(playerid,params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xf03c3cAA,"You are not authorized to use this command!!");
for(new i = 0; i < songs; i++)
{
mInfo = 0;
mInfo = EOS;
mInfo = EOS;
mInfo = EOS;
}
songs = 0;
mysql_tquery(sql, "SELECT * FROM songs", "LoadSongs");
SendClientMessage(playerid,0x1cd657AA,"You sucessfully refreshed the song list!");
return true;
}


Dzoni Zivkovic
5
Underboss
19. Dec. 2017.
Nice job 😄 Lepo je sto si podelio to ovde
PS: Inace koliko vas bre sad ima sa 420 xD
Lovacnadrolje42
5
Underboss
19. Dec. 2017.
ᴢɪᴠᴋᴏᴠɪᴄ wrote on December 19, 2017, 3:29 pm:
Nice job 😄 Lepo je sto si podelio to ovde
PS: Inace koliko vas bre sad ima sa 420 xD


samo oni pravi duvaci xd
Dzoni Zivkovic
5
Underboss
19. Dec. 2017.
Quote from December 19, 2017, 3:29 pm:
Nice job 😄 Lepo je sto si podelio to ovde
PS: Inace koliko vas bre sad ima sa 420 xD


samo oni pravi duvaci xd

lozanee nego ovaj comi mi najjaci retard... nema mreci hahaha
Rax_King
5
Godfather
19. Dec. 2017.
Zaglavio si malo u vremenu al ok 😄
Wucha
5
Underboss
19. Dec. 2017.
Finoo,uradi nekad neki update  😎
Lovacnadrolje42
5
Underboss
19. Dec. 2017.
xᴜɴᴅᴇʀ wrote on December 19, 2017, 7:36 pm:
Zaglavio si malo u vremenu al ok 😄


jebes vreme oceni rad 😛
Rax_King
5
Godfather
19. Dec. 2017.
Quote from December 19, 2017, 7:36 pm:
Zaglavio si malo u vremenu al ok 😄


jebes vreme oceni rad 😛

1. Compare f-ja ti ne moze biti 100% tacna (zbog spaceova)
2. MySQL je ocigledno outdated
3. Pocetnicke greske (pravljenje varijabli pa provjera)

Moze bolje 🙂
Lovacnadrolje42
5
Underboss
20. Dec. 2017.
Ovo nisam ja radiio 😄

Morate biti prijavljeni da biste odgovorili na ovu temu.

Prijava

© 2026 SmartShark. All rights reserved.

Powered by Momentum|v2026.3.001 Alpha