Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <a_mysql>
- #define MAX_SONGS 100 //You can add more.
- #define main 0x9ACD32AA
- #pragma tabsize 0
- #define MYSQL_HOST "hostname"
- #define MYSQL_NAME "name"
- #define MYSQL_DATABASE "databse"
- #define MYSQL_PASS "pass"
- new field[128][32],row[128];
- new isitplayingrudy[MAX_PLAYERS];
- public OnFilterScriptInit()
- {
- mysql_connect(MYSQL_HOST,MYSQL_NAME,MYSQL_DATABASE,MYSQL_PASS);
- if(mysql_ping() != -1)
- {
- print(" ");
- print("Connected to MySQL database...");
- print(" ");
- }
- else
- {
- print(" ");
- print("Unable to connected to MySQL database...");
- print("You may have problem with the script...");
- print("Please check the script for mysql connection..");
- print(" ");
- return 1;
- }
- Loadsongs();
- print("\n--------------------------------------");
- print(" SQL Based Simple Mp3 Player");
- print("--------------------------------------\n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- print("unloaded.");
- return 1;
- }
- new String[256];
- new songname[MAX_SONGS];
- new songlink[MAX_SONGS];
- public OnPlayerDisconnect(playerid)
- {
- isitplayingrudy[playerid] = -1;
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- isitplayingrudy[playerid] = -1;
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[128], idx;
- cmd = strtok(cmdtext, idx);
- if (strcmp("/nowplaying", cmdtext, true, 10) == 0)
- {
- if(isitplayingrudy[playerid] == 0) return SendClientMessage(playerid,main,"Your not playing anything.....");
- format(String,sizeof(String),"Now playing: %s",isitplayingrudy[playerid]);
- SendClientMessage(playerid,main,String);
- return 1;
- }
- if (strcmp("/mp3", cmdtext, true, 10) == 0)
- {
- new count;
- new tmp[128];
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp)){
- for(new i = 0;i<MAX_SONGS;i++)
- {
- if(DoesSongExist(i))
- {
- format(String,128,"%s - ID: %d",songname[i],i);
- SendClientMessage(playerid,main,String);
- }
- }
- SendClientMessage(playerid,main,"USAGE: /mp3 [ID]");
- return 1;
- }
- if(count == 0) return SendClientMessage(playerid,main,"No songs added at the moment.");
- if(count > 0)
- {
- // ShowPlayerDialog(playerid, 1912, DIALOG_STYLE_LIST, "MP3 Player",String,"Play","Exit");
- for(new i = 0;i<MAX_SONGS;i++)
- {
- if(DoesSongExist(i))
- {
- StopAudioStreamForPlayer(playerid);
- PlayAudioStreamForPlayer(playerid, songlink[i]);
- format(String,sizeof(String),"Now playing: %s",songname[i]);
- SendClientMessage(playerid,main,String);
- isitplayingrudy[playerid] = i;
- }
- }
- }
- return 1;
- }
- if (strcmp("/stopmusic", cmdtext, true, 10) == 0)
- {
- StopAudioStreamForPlayer(playerid);
- return 1;
- }
- if (strcmp("/changesong", cmdtext, true, 10) == 0)
- {
- if(!IsPlayerAdmin(playerid)) return 0;
- new tmp[128],tmp2[128];
- tmp = strtok(cmdtext, idx);
- tmp2 = strtok(cmdtext, idx);
- if(!strlen(tmp) || !strlen(tmp2)) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /changesong [ID] [Link] [Name]");
- new songid = strval(tmp);
- new length = strlen(cmdtext);
- while ((idx < length) && (cmdtext[idx] <= ' '))
- {
- idx++;
- }
- new offset = idx;
- new result[64];
- while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
- {
- result[idx - offset] = cmdtext[idx];
- idx++;
- }
- if(!DoesSongExist(songid)) return SendClientMessage(playerid, main, "Song ID doesn't exist. To create do /createsong [id] [url] [name]");
- format(String,sizeof(String),"INSERT INTO songs (ID,Name,link) VALUES (%d,%s,%s)",songid,result,tmp2);
- mysql_query(String);
- format(String,sizeof(String),"Song changed! To check /mp3 . ID: %d , Name: %s & Link: %s",songid,result,tmp2);
- SendClientMessage(playerid,main,String);
- return 1;
- }
- if (strcmp("/createsong", cmdtext, true, 10) == 0)
- {
- if(!IsPlayerAdmin(playerid)) return 0;
- new tmp[128],tmp2[128];
- tmp = strtok(cmdtext, idx);
- tmp2 = strtok(cmdtext, idx);
- if(!strlen(tmp) || !strlen(tmp2)) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /createsong [ID] [Link] [Name]");
- new songid = strval(tmp);
- new length = strlen(cmdtext);
- while ((idx < length) && (cmdtext[idx] <= ' '))
- {
- idx++;
- }
- new offset = idx;
- new result[64];
- while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
- {
- result[idx - offset] = cmdtext[idx];
- idx++;
- }
- if(DoesSongExist(songid)) return SendClientMessage(playerid, main, "Song ID exist. To change do /changesong [id] [url] [name]");
- format(String,sizeof(String),"INSERT INTO songs (ID,Name,link) VALUES (%d,%s,%s)",songid,result,tmp2);
- mysql_query(String);
- format(String,sizeof(String),"Song added! To check /mp3 . ID: %d , Name: %s & Link: %s",songid,result,tmp2);
- SendClientMessage(playerid,main,String);
- return 1;
- }
- return 0;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- /* for(new i = 0;i<MAX_SONGS;i++)
- {
- if(DoesSongExist(i))
- {
- if(response)
- {
- switch(dialogid)
- {
- case 1:
- {
- switch(listitem)
- {
- case 0-100:
- {
- StopAudioStreamForPlayer(playerid);
- PlayAudioStreamForPlayer(playerid, songlink[i]);
- }
- }
- }
- }
- }
- }
- }*/
- return 1;
- }
- stock DoesSongExist(orgid)
- {
- format(String,sizeof(String),"SELECT * FROM songs WHERE `ID` = %d LIMIT 0,1",orgid);
- mysql_query(String);
- mysql_store_result();
- if(mysql_num_rows() != 0)
- {
- mysql_free_result();
- return 1;
- }
- if(mysql_num_rows() == 0)
- {
- mysql_free_result();
- return 0;
- }
- return 1;
- }
- stock Loadsongs()
- {
- new c;
- c =0;
- for(new i = 0;i<MAX_SONGS;i++)
- {
- format(String,48,"SELECT * FROM songs WHERE `ID` = %d LIMIT 0,1",i);
- mysql_query(String);
- mysql_store_result();
- if(mysql_num_rows() == 0)
- {
- mysql_free_result();
- continue;
- }
- if(mysql_num_rows() != 0)
- {
- mysql_fetch_row_format(row, "|");
- explode(row, field, "|");
- format(songname[i],100,"%s",field[1]);
- format(songlink[i],100,"%s",field[2]);
- mysql_free_result();
- c++;
- }
- }
- return printf("Total Songs: %d",c);
- }
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- explode(const sSource[], aExplode[][], const sDelimiter[] = " ", iVertices = sizeof aExplode, iLength = sizeof aExplode[]) // Created by Westie
- {
- new
- iNode,
- iPointer,
- iPrevious = -1,
- iDelimiter = strlen(sDelimiter);
- while(iNode < iVertices)
- {
- iPointer = strfind(sSource, sDelimiter, false, iPointer);
- if(iPointer == -1)
- {
- strmid(aExplode[iNode], sSource, iPrevious, strlen(sSource), iLength);
- break;
- }
- else
- {
- strmid(aExplode[iNode], sSource, iPrevious, iPointer, iLength);
- }
- iPrevious = (iPointer += iDelimiter);
- ++iNode;
- }
- return iPrevious;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement