- เครดิต
- 168
- ความรู้
-
- เงิน $
-
- ความดี
-
|
//==============================================================================
// Youtube Player v1.0 by usrb1n !
// http://forum.sa-mp.com/member.php?u=122322
//==============================================================================
// Includes & Defines
//==============================================================================
#include <a_samp>
#include <a_http>
#include <core>
#include <float>
#define U2BDIAG 6958 //DialogID used
new PlayerU2B[MAX_PLAYERS];
new PlayerU2BLink[MAX_PLAYERS][32];
new U2BRadius[MAX_PLAYERS][16];
forward U2BInfo(playerid, response_code, data[]);
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
#define WHOMADETHIS "Youtube Player v1.0 by {FF0000}us{FFEF00}rb{1A00FF}1n"
public OnFilterScriptInit()
{
print("Youtube player by usrb1n has been loaded(ห้ามลบเครดิตเด็ดขาด)");
}
public OnFilterScriptExit()
{
print("Youtube player by usrb1n has been unloaded(ห้ามลบเครดิตเด็ดขาด)");
}
//==============================================================================
// Commands
//==============================================================================
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(youtube, 7, cmdtext);
dcmd(stopu2b, 7, cmdtext);
return 0;
}
dcmd_stopu2b(playerid, params[])
{
if(strlen(params)) return 0;
PlayAudioStreamForPlayer(playerid, "เพลงถูกหยุดลงโดยแอดมิน.");
return 1;
}
dcmd_youtube(playerid, params[])
{
if(strlen(params)) return 0;
if(!IsPlayerAdmin(playerid))
{
SendClientMessage(playerid, 0xD776FF, "กรุณาล๊อกอินเข้า RCON ก่อนใช้คำสั่งนี้นะครับ.");
return 1;
}
ShowPlayerDialog(playerid, U2BDIAG, DIALOG_STYLE_LIST, WHOMADETHIS, "{46BEE6}เปิดให้ตัวเองฟัง\n{ED954E}เปิดให้คนอื่นฟัง\n{46BEE6}เปิดในรัศมีที่คุณกำหนด\n{ED954E}เปิดให้ได้ยินทั้งเซิฟเวอร์)", "เลิอก", "ยกเลิก");
return 1;
}
//==============================================================================
// Dialogs
//==============================================================================
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == U2BDIAG && response)
{
switch(listitem)
{
case 0:
{
PlayerU2B[playerid] = 1;
ShowPlayerDialog(playerid,U2BDIAG+1,DIALOG_STYLE_INPUT,WHOMADETHIS,"ใส่ลิงค์ของวีดีโอที่ต้องการจะเปิดให้ตัวเองฟัง:","เปิด","ยกเลิก");
return 1;
}
case 1:
{
PlayerU2B[playerid] = 2;
ShowPlayerDialog(playerid,U2BDIAG+1,DIALOG_STYLE_INPUT,WHOMADETHIS,"ใส่ลิงค์ของวีดีโอที่ต้องการจะให้ผู้เล่นฟัง:","เปิด","ยกเลิก");
return 1;
}
case 2:
{
PlayerU2B[playerid] = 3;
ShowPlayerDialog(playerid,U2BDIAG+1,DIALOG_STYLE_INPUT,WHOMADETHIS,"ใส่ลิงค์ของวีดีโอที่ต้องการจะเปิดคนในระแวกนี้ได้ยิน","เปิด","ยกเลิก");
return 1;
}
case 3:
{
PlayerU2B[playerid] = 4;
ShowPlayerDialog(playerid,U2BDIAG+1,DIALOG_STYLE_INPUT,WHOMADETHIS,"ใส่ลิงค์ของวีดีโอที่ต้องการจะเปิดให้ได้ยินทั้งเซิฟเวอร์:","เปิด","ยกเลิก");
return 1;
}
}
}
if(dialogid == U2BDIAG+1 && response)
{
if(strlen(inputtext))
{
new result[128], videostr[128];
strmid(result,inputtext,31,44,strlen(inputtext));
format(videostr,sizeof(videostr),"www.youtube-mp3.org/api/itemInfo/?video_id=%s",result);
strmid(PlayerU2BLink[playerid], result, 0, 32);
if (PlayerU2B[playerid] == 1)
{
PlayerU2B[playerid] = 11;
HTTP(playerid,HTTP_GET,videostr,"","U2BInfo");
}
else if (PlayerU2B[playerid] == 2)
{
PlayerU2B[playerid] = 22;
ShowPlayerDialog(playerid,U2BDIAG+2,DIALOG_STYLE_INPUT,WHOMADETHIS,"ใส่ไอดีของผู้เล่นทีต้องการจะเปิดให้ฟัง:","เปิด","ยกเลิก");
new string[128];
format(string, sizeof(string), "%s", PlayerU2BLink[playerid]);
}
else if (PlayerU2B[playerid] == 3)
{
PlayerU2B[playerid] = 33;
ShowPlayerDialog(playerid,U2BDIAG+3,DIALOG_STYLE_INPUT,WHOMADETHIS,"ใส่รัศมีที่ต้องการให้คนได้ยิน:","เปิด","ยกเลิก");
}
else if (PlayerU2B[playerid] == 4)
{
PlayerU2B[playerid] = 44;
HTTP(playerid,HTTP_GET,videostr,"","U2BInfo");
}
}
return 1;
}
if(dialogid == U2BDIAG+2 && response)
{
new gpid = strval(inputtext);
new videostr[128];
format(videostr,sizeof(videostr),"www.youtube-mp3.org/api/itemInfo/?video_id=%s",PlayerU2BLink[playerid]);
HTTP(gpid,HTTP_GET,videostr,"","U2BInfo");
return 1;
}
if(dialogid == U2BDIAG+3 && response)
{
strmid(U2BRadius[playerid], inputtext, 0, 32);
new videostr[128];
PlayerU2B[playerid] = 333;
format(videostr,sizeof(videostr),"www.youtube-mp3.org/api/itemInfo/?video_id=%s",PlayerU2BLink[playerid]);
HTTP(playerid,HTTP_GET,videostr,"","U2BInfo");
return 1;
}
return 0;
}
//==============================================================================
// Functions
//==============================================================================
public U2BInfo(playerid, response_code, data[])
{
if(response_code == 200)
{
new result[33], u2bstr[33]; new streamedurl[128];
new crypted = strfind(data, "\"h\"", true, -1);
strmid(result,data,crypted+7,crypted+39,strlen(data));
format(u2bstr,sizeof(u2bstr), "%s", result);
format(streamedurl, sizeof(streamedurl), "http://www.youtube-mp3.org/get?video_id=%s&h=%s",PlayerU2BLink[playerid], u2bstr);
if(PlayerU2B[playerid] == 11)
{
PlayAudioStreamForPlayer(playerid, streamedurl);
return 1;
}
else if(PlayerU2B[playerid] == 22)
{
PlayAudioStreamForPlayer(playerid, streamedurl);
return 1;
}
else if(PlayerU2B[playerid] == 33)
{
PlayAudioStreamForPlayer(playerid, streamedurl);
return 1;
}
else if(PlayerU2B[playerid] == 44)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
PlayAudioStreamForPlayer(i, streamedurl);
return 1;
}
else return 1;
}
}
else if(PlayerU2B[playerid] == 333)
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
new radius = strval(U2BRadius[playerid]);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerInRangeOfPoint(i, radius , X, Y, Z))
{
PlayAudioStreamForPlayer(i, streamedurl, X, Y, Z, radius, 1);
return 1;
}
else return 1;
}
}
}
}
else
{
new u2bstring[128];
format(u2bstring,sizeof(u2bstring)," {FF0000}ลิงค์ผิดพลาด\n\n{FFFFFF}วีดีโอดังกล่าวถูกลบหรือเสียหายไม่สามารถแปลงให้อยู่ในรูปของ MP3 ได้. ");
ShowPlayerDialog(playerid,61,DIALOG_STYLE_MSGBOX ,WHOMADETHIS,u2bstring, "ออก", "");
}
return 1;
}
|
|