PHP код:
// Server Auto Song Change System
//----Includes-----
#include <a_samp>
#include <zcmd>
#include <sscanf2>
//-----------------
//-----------------------------Defines----------------------------
#define GREEN 0x33AA33AA
#define RED 0xFF0000AA
#define SCM SendClientMessage
#define SCMTA SendClientMessageToAll
//----------------------------------------------------------------
new SongsList[][][] = {
"Song 1 Link, Music Name",
"Song 2 Link, Music Name",
"Song 3 Link, Music Name",
"Song 4 Link, Music Name",
"Song 5 Link, Music Name",
"Song 6 Link, Music Name",
"Song 7 Link, Music Name",
"Song 8 Link, Music Name",
"Song 9 Link, Music Name",
"Song 10 Link, Music Name"
};
//----------Forwards-----
forward AutoSongChange();
forward AutoSongChange2();
//-----------------------
// OnFilterScriptInit()
print("\n-----------------------------------------------");
print(" Auto Song Changer By TadePoleMG - Loaded ");
print("-----------------------------------------------\n");
// Here we set the timer(repeat) for auto songs change
SetTimer("AutoSongChange", 1000, false);
return 1;
//----------------
// OnFilterScriptExit()
print("\n-----------------------------------------------");
print(" Auto Song Changer By TadePoleMG - Unloaded ");
print("-----------------------------------------------\n");
KillTimer(AutoSongChange); // Here we kill that both timers
KillTimer(AutoSongChange2);
return 1;
//----------------
// Here We Starting Timer function
public AutoSongChange()
{
new SelectAutoSong = random(sizeof(SongsList)); // here we selecting random songs to play
for(new all;all<MAX_PLAYERS;all++)
{
if(IsPlayerConnected(all))
{
PlayAudioStreamForPlayer(i, SongsList[SelectAutoSong][0]);
}
}
new string[128];
format(string,128,"Current playing Song - %s", SongsList[SelectAutoSong][1]);
SCMTA(GREEN, string);
// Here we setting again timer of aabout time equal to audio stream time.
new Time = random(2);
switch(Time)
{
case 0:
{
SetTimer("AutoSongChange2", 180*1000, false); // 3minutes, edit as your need
}
case 1:
{
SetTimer("AutoSongChange2", 240*1000, false); // 4 minutes, edit as your need
}
case 2:
{
SetTimer("AutoSongChange2", 300*1000, false); // 5 minutes, edit as your need
}
}
return 1;
}
public AutoSongChange2()
{
new SelectAutoSong2 = random(sizeof(SongsList)); // here we selecting random songs to play
for(new all;all<MAX_PLAYERS;all++)
{
if(IsPlayerConnected(all))
{
PlayAudioStreamForPlayer(i, SongsList[SelectAutoSong2][0]);
}
}
new string[128];
format(string,128,"Current playing Song - %s", SongsList[SelectAutoSong2][1]);
SCMTA(GREEN, string);
new Time = random(2);
switch(Time)
{
case 0:
{
SetTimer("AutoSongChange", 180*1000, false); // 3minutes, edit as your need
}
case 1:
{
SetTimer("AutoSongChange", 240*1000, false); // 4 minutes, edit as your need
}
case 2:
{
SetTimer("AutoSongChange", 300*1000, false); // 5 minutes, edit as your need
}
}
return 1;
}
// You can also start stop by commands
CMD:startstream(playerid,params[])
{
if(IsPlayerAdmin(playerid))
{
new select;
if(sscanf(params,"s[200]", select)) return SCM(playerid, red,"CmdUse: /startstream (0-10)") &&
SCM(playerid, red,"CmdUse: will start songs, select song number.");
if(select < 0 || select > 10) return SCM(playerid, red,"Select from 0-10");
for(new all;all<MAX_PLAYERS;all++)
{
if(IsPlayerConnected(all))
{
PlayAudioStreamForPlayer(i, SongsList[select]);
KillTimer(AutoSongChange);
KillTimer(AutoSongChange2);
}
}
new string[128];
format(string,128,"Admin started new song - %s", SongsList[select][1]);
SCMTA(GREEN, string);
}
else SCM(playerid, red, "You are not allowed to use this command.");
return 1;
}
CMD:stopstream(playerid,params[])
{
if(IsPlayerAdmin(playerid))
{
#pragma unused params
KillTimer(AutoSongChange);
KillTimer(AutoSongChange2);
new string[128];
format(string,128,"Current playing audio stream is stopped now");
SCM(playerid, GREEN, string);
}
else SCM(playerid, red, "You are not allowed to use this command.");
return 1;
}
I think it can work better from above.
Above can't know when the stream comes but it tries about that time (only seconds of diffrence).
Thank You, rep++-If I helped you.