[MySQL-R39] Music Player

Započeo ich., Decembar 19, 2017, 12:38:03 POSLE PODNE

prethodna tema - sledeća tema

0 članova i 4 gostiju pregledaju ovu temu.

Tip: Filterscript
Autor: Rolux





MySQL Table /

[pawn]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;[/pawn]

Script /

[pawn]#include    <a_samp>
#include     <a_mysql>
#include    <sscanf2>
#include   <zcmd>

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

//»Enum
enum music
{
m_id,
m_artist[32],
m_song[32],
m_link[96]
}

//»Vars
new sql,songs,mInfo[MAX_SONGS][music];

//»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("[MySQL] » ( ! )Failed to connect to the database!");
   }
   else
     {
           print("[MySQL] » Successful connection to the database!");
   }
   print("[MusicPlayer] » 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][m_link]);
               new string[100];
               format(string,100,"Music started! / Performer: %s / Song : %s /",mInfo[listitem-1][m_artist],mInfo[listitem-1][m_song]);
            SendClientMessage(playerid,0x8a3cf0AA,string);
         }
      }
   }
   return 0;
}

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


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

stock ShowMusic(playerid)
{
   new str[512] = "Performer\t-\tSong\n{f03c3c}Stop music\n",str2[100],count;
   for(new i = 0; i < songs; i++)
   {
      format(str2,sizeof(str2),"%s\t-\t%s\n",mInfo[m_artist],mInfo[m_song]);
      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[32],song[32],link[96],string[96];
   if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xf03c3cAA,"You are not authorized to use this command!!");
   if(sscanf(params, "s[32]s[32]s[96]",artist,song,link)) return SendClientMessage(playerid,0xf03c3cAA,"/newsong [Performer] [Song] [Link to mp3]");
   for(new i = 0; i < songs; i++)
   {
      if(Compare(mInfo[m_artist],artist) && Compare(mInfo[m_song],song)) return SendClientMessage(playerid,0xf03c3cAA,"This Song from the performer is already added!");
   }
   new query[256];
   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[m_id] = 0;
      mInfo[m_artist] = EOS;
      mInfo[m_song] = EOS;
      mInfo[m_link] = EOS;
   }
   songs = 0;
   mysql_tquery(sql, "SELECT * FROM songs", "LoadSongs");
   SendClientMessage(playerid,0x1cd657AA,"You sucessfully refreshed the song list!");
   return true;
}[/pawn]



Nice job :D Lepo je sto si podelio to ovde
PS: Inace koliko vas bre sad ima sa 420 xD


Citat: [ANDRIJEVIC] poslato Decembar 19, 2017, 16:49:59 POSLE PODNE
Citat: ᴢɪᴠᴋᴏᴠɪá´,, poslato Decembar 19, 2017, 16:29:04 POSLE PODNE
Nice job :D 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


Finoo,uradi nekad neki update  8)
[/center]


Citat: [ANDRIJEVIC] poslato Decembar 19, 2017, 20:38:34 POSLE PODNE
Citat: xᴜɴá´...ᴇʀ poslato Decembar 19, 2017, 20:36:47 POSLE PODNE
Zaglavio si malo u vremenu al ok :D

jebes vreme oceni rad :P

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 :)