Tip: Filterscript
Autor: Rolux
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;
}
