Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * By RaFaeL zilberman (c) 2012
- * This include have writed for Sa:Mp - San andress multi player!
- * Blue-F.co.il
- * Version: 1.2 [BETA]
- */
- //==========================================================================================
- #if defined _stsreamer_included
- #endinput
- #endif
- #define _stsreamer_included
- #if !defined STREAM_RATE
- #define STREAM_RATE 100 // Time to update the streamer - in milseconds like 1000 (1sec) or 60000(1min)
- #endif
- #if !defined MAX_STREAMS
- #define MAX_STREAMS 90 // Maximum global streaming
- #endif
- #define INVALID_STREAM_ID -1
- //==========================================================================================
- /****************** Natives *******************/
- /*
- native PlayDynamicStream(url[], playerid = INVALID_PLAYER_ID, Float:posX = 0.0, Float:posY = 0.0, Float:posZ = 0.0, Float:distance = 50.0);
- native StopDynamicStream(streamid);
- native GetStreamDetails(streamid, url[], &playerid, &Float:PosX, &Float:PosY, &Float:PosZ, &Float:distance);
- natice CountDynamicStreams();
- native IsAnyStreamForPlayer(playerid);
- native IsStreamForPlayer(playerid, streamid);
- native GetPlayerStreaming(playerid);
- native TooglePlayerStreaming(playerid, streamid = INVALID_STREAM_ID, bool:status);
- native PlayerToogleStatus(playerid, streamid = INVALID_STREAM_ID);
- native ToogleGlobalStream(streamid = INVALID_STREAM_ID, bool:status);
- native IsValidStream(streamid);
- */
- forward OnDynamicStreamIn(playerid, streamid);
- forward OnDynamicStreamOut(playerid, streamid);
- //==========================================================================================
- enum StreamInfo {
- surl[128],
- sUser,
- bool:uPosXYZ,
- Float:sposX,
- Float:sposY,
- Float:sposZ,
- Float:sdistance,
- bool:uDisabled[MAX_PLAYERS],
- bool:Disabled
- };
- new STService;
- new Streams[MAX_STREAMS][StreamInfo];
- new bool:UsedSTSlot[MAX_STREAMS];
- new STService_actual[MAX_PLAYERS];
- new bool:UserDisabled[MAX_PLAYERS];
- new bool:UserStreamsDIsabled[MAX_PLAYERS][MAX_STREAMS];
- forward STSERVICE_BGWokrer();
- //==========================================================================================
- //==========================================================================================
- stock PlayDynamicStream(url[], playerid = INVALID_PLAYER_ID, Float:posX = 0.0, Float:posY = 0.0, Float:posZ = 0.0, Float:distance = 50.0) {
- if(STService == 0) STService = SetTimer("STSERVICE_BGWokrer", STREAM_RATE, true);
- new streamid = 1;
- while(UsedSTSlot[streamid] == true) streamid++;
- UsedSTSlot[streamid] = true;
- format(Streams[streamid][surl], 128, url);
- Streams[streamid][uPosXYZ] = (posX==0.0&&posY==0.0&&posZ==0.0)? (false):(true);
- Streams[streamid][sposX] = posX;
- Streams[streamid][sposY] = posY;
- Streams[streamid][sposZ] = posZ;
- Streams[streamid][sdistance] = (Streams[streamid][uPosXYZ])? (distance):(1000000.0);
- Streams[streamid][sUser] = (playerid != INVALID_PLAYER_ID)? (playerid):(INVALID_PLAYER_ID);
- return streamid;
- }
- stock StopDynamicStream(streamid) {
- if(streamid == 0 || !UsedSTSlot[streamid]) return false;
- UsedSTSlot[streamid] = false;
- for(new i,j=GetMaxPlayers(); i<j; i++) if(STService_actual[i] == streamid) {
- if(STService_actual[i] > 0) CallLocalFunction("OnDynamicStreamOut", "ii", i, STService_actual[i]);
- StopAudioStreamForPlayer(i);
- STService_actual[i] = 0;
- }
- return 1;
- }
- stock GetStreamDetails(streamid, url[], &playerid, &Float:PosX, &Float:PosY, &Float:PosZ, &Float:distance) {
- if(!IsValidStream(streamid)) return 1;
- format(url, 128, Streams[streamid][surl]);
- PosX = Streams[streamid][sposX];
- PosY = Streams[streamid][sposY];
- PosZ = Streams[streamid][sposZ];
- distance = Streams[streamid][sdistance];
- playerid = (Streams[streamid][sUser] == INVALID_PLAYER_ID)? (-1):(Streams[streamid][sUser]);
- return 1;
- }
- stock CountDynamicStreams() {
- new count;
- for(new streamid, j=MAX_STREAMS; streamid<j; streamid++) if(UsedSTSlot[streamid] == true) count++;
- return count;
- }
- stock IsAnyStreamForPlayer(playerid) {
- return (STService_actual[playerid] == 0)? (false):(true);
- }
- stock IsStreamForPlayer(playerid, streamid) {
- return (IsAnyStreamForPlayer(playerid) && IsValidStream(streamid) && STService_actual[playerid] == streamid)? (true):(false);
- }
- stock GetPlayerStreaming(playerid) {
- return (!IsAnyStreamForPlayer(playerid))? (0):(STService_actual[playerid]);
- }
- stock TooglePlayerStreaming(playerid, streamid = INVALID_STREAM_ID, bool:status) {
- status = (status)? (false):(true);
- if(streamid == INVALID_STREAM_ID) {
- UserDisabled[playerid] = status;
- if(STService_actual[playerid] > 0) {
- StopAudioStreamForPlayer(playerid), CallLocalFunction("OnDynamicStreamOut", "ii", playerid, STService_actual[playerid]);
- }
- STService_actual[playerid] = 0;
- } else {
- if(!IsValidStream(streamid)) return 1;
- UserStreamsDIsabled[playerid][streamid] = status;
- if(STService_actual[playerid] == streamid) {
- StopAudioStreamForPlayer(playerid), CallLocalFunction("OnDynamicStreamOut", "ii", playerid, STService_actual[playerid]);
- STService_actual[playerid] = 0;
- }
- }
- return 1;
- }
- stock PlayerToogleStatus(playerid, streamid = INVALID_STREAM_ID) {
- if(streamid == INVALID_STREAM_ID)
- return (UserDisabled[playerid])? (false):(true);
- else
- return (UserStreamsDIsabled[playerid][streamid])? (false):(true);
- }
- stock ToogleGlobalStream(streamid = INVALID_STREAM_ID, bool:status) {
- if(streamid == INVALID_STREAM_ID) {
- if(status) {
- if(STService == 0) STService = SetTimer("STSERVICE_BGWokrer", STREAM_RATE, true);
- } else {
- KillTimer(STService);
- STService = 0;
- for(new i,j=GetMaxPlayers(); i<j; i++) if(STService_actual[i] > 0) {
- CallLocalFunction("OnDynamicStreamOut", "ii", i, STService_actual[i]);
- StopAudioStreamForPlayer(i);
- STService_actual[i] = 0;
- }
- }
- } else {
- if(!IsValidStream(streamid)) return 1;
- Streams[streamid][Disabled] = (status)? (false):(true);
- for(new i,j=GetMaxPlayers(); i<j; i++) if(STService_actual[i] == streamid) {
- if(STService_actual[i] > 0) CallLocalFunction("OnDynamicStreamOut", "ii", i, STService_actual[i]);
- StopAudioStreamForPlayer(i);
- STService_actual[i] = 0;
- }
- }
- return 1;
- }
- stock IsValidStream(streamid) {
- if(!UsedSTSlot[streamid] || streamid < 0 || streamid == INVALID_STREAM_ID) return false;
- return true;
- }
- //==========================================================================================
- //==========================================================================================
- public STSERVICE_BGWokrer() {
- for(new i,j=GetMaxPlayers(); i<j; i++) if(!UserDisabled[i]) {
- new Float:prevdist = 100000.000;
- new prevst, prevstx;
- for(new streamid=1; streamid < MAX_STREAMS; streamid++) if(UsedSTSlot[streamid]) {
- new Float:dist = STSERVICE_getdist(i,Streams[streamid][sposX],Streams[streamid][sposY],Streams[streamid][sposZ]);
- if(dist < prevdist && dist < Streams[streamid][sdistance]) {
- prevdist = dist;
- prevst = streamid;
- }
- if(!Streams[streamid][uPosXYZ]) {
- prevstx = streamid;
- }
- }
- new streamid = (prevst > 0)? (prevst):(prevstx);
- if(streamid > 0) {
- if(Streams[streamid][Disabled] || UserStreamsDIsabled[i][streamid]) return 1;
- if(((Streams[streamid][sUser] != INVALID_PLAYER_ID && Streams[streamid][sUser] == i) || (Streams[streamid][sUser] == INVALID_PLAYER_ID)) && (STService_actual[i] != streamid)) {
- StopAudioStreamForPlayer(i);
- if(STService_actual[i] > 0) CallLocalFunction("OnDynamicStreamOut", "ii", i, STService_actual[i]);
- STService_actual[i] = streamid;
- CallLocalFunction("OnDynamicStreamIn", "ii", i, streamid);
- PlayAudioStreamForPlayer(i, Streams[streamid][surl], Streams[streamid][sposX],Streams[streamid][sposY],Streams[streamid][sposZ], Streams[streamid][sdistance], (Streams[streamid][uPosXYZ])? (1):(0));
- }
- } else if(STService_actual[i] != 0) {
- if(STService_actual[i] > 0) CallLocalFunction("OnDynamicStreamOut", "ii", i, STService_actual[i]);
- STService_actual[i] = 0;
- StopAudioStreamForPlayer(i);
- }
- }
- return 1;
- }
- stock STSERVICE_getdist(playerid,Float:x2,Float:y2,Float:z2) {
- new Float:x1,Float:y1,Float:z1, Float:tmpdis;
- GetPlayerPos(playerid,x1,y1,z1);
- tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
- return floatround(tmpdis);
- }
- //==========================================================================================
Add Comment
Please, Sign In to add comment