Advertisement
Guest User

BoomBox

a guest
May 22nd, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.91 KB | None | 0 0
  1. // Includes
  2. #include <a_samp>
  3. #include <zcmd>
  4. #include <sscanf>
  5. #include <streamer>
  6. #include <foreach>
  7.  
  8. // Defines
  9. #define COLOR_WHITE 0xFFFFFFFF
  10. #define COLOR_LIGHTBLUE 0x33CCFFFF
  11. #define COLOR_GREY 0xAFAFAFFF
  12.  
  13. // Clearing variables
  14. public OnPlayerConnect(playerid)
  15. {
  16.     DeletePVar(playerid, "BoomboxObject"); DeletePVar(playerid, "BoomboxURL");
  17.     DeletePVar(playerid, "bposX"); DeletePVar(playerid, "bposY"); DeletePVar(playerid, "bposZ"); DeletePVar(playerid, "bboxareaid");
  18.     if(IsValidDynamicObject(GetPVarInt(playerid, "BoomboxObject"))) DestroyDynamicObject(GetPVarInt(playerid, "BoomboxObject"));
  19.     return 1;
  20. }
  21.  
  22. // Clearing variables & Stopping boombox music on disconnect (Double check)
  23. public OnPlayerDisconnect(playerid)
  24. {
  25.     if(GetPVarType(playerid, "BoomboxObject"))
  26.     {
  27.         DestroyDynamicObject(GetPVarInt(playerid, "BoomboxObject"));
  28.         if(GetPVarType(playerid, "bboxareaid"))
  29.         {
  30.             foreach(Player,i)
  31.             {
  32.                 if(IsPlayerInDynamicArea(i, GetPVarInt(playerid, "bboxareaid")))
  33.                 {
  34.                     StopAudioStreamForPlayer(i);
  35.                     SendClientMessage(i, COLOR_GREY, " The boombox creator has disconnected from the server.");
  36.                 }
  37.             }
  38.         }
  39.     }
  40.     return 1;
  41. }
  42.  
  43.  
  44. // Boombox command - Usage: /boombox [URL]
  45. if(!strcmp(cmdtext, "/boomox", true) == 0)
  46. {
  47.     new string[128];
  48.     if(!GetPVarType(playerid, "BoomboxObject"))
  49.     {
  50.         if(sscanf(cmdtext, "s[256]", cmdtext)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /boombox [music url]");
  51.         foreach(Player, i)
  52.         {
  53.             if(GetPVarType(i, "BoomboxObject"))
  54.             {
  55.                 if(IsPlayerInRangeOfPoint(playerid, 30.0, GetPVarFloat(i, "bposX"), GetPVarFloat(i, "bposY"), GetPVarFloat(i, "bposZ")))
  56.                 {
  57.                     SendClientMessage(playerid, COLOR_GREY, " There is another boombox nearby, place yours somewhere else.");
  58.                     return 1;
  59.                 }
  60.             }
  61.         }
  62.  
  63.         new Float:x, Float:y, Float:z, Float:a;
  64.         GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, a);
  65.         SetPVarInt(playerid, "BoomboxObject", CreateDynamicObject(2103, x, y, z, 0.0, 0.0, 0.0, .worldid = GetPlayerVirtualWorld(playerid), .interiorid = GetPlayerInterior(playerid)));
  66.         SetPVarFloat(playerid, "bposX", x); SetPVarFloat(playerid, "bposY", y); SetPVarFloat(playerid, "bposZ", z);
  67.         SetPVarInt(playerid, "bboxareaid", CreateDynamicSphere(x, y, z, 30.0, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid)));
  68.         format(string, sizeof(string), " You have placed your boombox at your location.");
  69.         SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
  70.         foreach(Player, i)
  71.         {
  72.             if(IsPlayerInDynamicArea(i, GetPVarInt(playerid, "bboxareaid")))
  73.             {
  74.                 PlayAudioStreamForPlayer(i, cmdtext, GetPVarFloat(playerid, "bposX"), GetPVarFloat(playerid, "bposY"), GetPVarFloat(playerid, "bposZ"), 30.0, 1);
  75.             }
  76.         }
  77.         SetPVarString(playerid, "BoomboxURL", cmdtext);
  78.     }
  79.     else
  80.     {
  81.         DestroyDynamicObject(GetPVarInt(playerid, "BoomboxObject"));
  82.         DeletePVar(playerid, "BoomboxObject"); DeletePVar(playerid, "BoomboxURL");
  83.         DeletePVar(playerid, "bposX"); DeletePVar(playerid, "bposY"); DeletePVar(playerid, "bposZ");
  84.         if(GetPVarType(playerid, "bboxareaid"))
  85.         {
  86.             foreach(Player,i)
  87.             {
  88.                 if(IsPlayerInDynamicArea(i, GetPVarInt(playerid, "bboxareaid")))
  89.                 {
  90.                     StopAudioStreamForPlayer(i);
  91.                     SendClientMessage(i, COLOR_GREY, " The boombox creator has removed his boombox.");
  92.                 }
  93.             }
  94.             DeletePVar(playerid, "bboxareaid");
  95.         }
  96.         SendClientMessage(playerid, COLOR_LIGHTBLUE, " You have removed your boombox.");
  97.     }
  98.     return 1;
  99. }
  100.  
  101. // Boombox editing - Usage: /boomboxnext [url]
  102. if(!strcmp(cmdtext, "/boomboxnext", true) == 0)
  103. {
  104.     //if(!Boombox[playerid])
  105.     //return 1;
  106.     SendClientMessage(playerid, COLOR_GREY, "You don't have a boombox placed.");
  107.     if(sscanf(cmdtext, "s[256]", cmdtext)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /boomboxnext [music url]");
  108.     SendClientMessage(playerid, COLOR_GREY, " You have changed the music your boombox is playing.");
  109.     foreach(Player, i)
  110.     {
  111.         if(IsPlayerInDynamicArea(i, GetPVarInt(playerid, "bboxareaid")))
  112.         {
  113.             PlayAudioStreamForPlayer(i, cmdtext, GetPVarFloat(playerid, "bposX"), GetPVarFloat(playerid, "bposY"), GetPVarFloat(playerid, "bposZ"), 30.0, 1);
  114.         }
  115.     }
  116.     SetPVarString(playerid, "BoomboxURL", cmdtext);
  117.     return 1;
  118. }
  119.  
  120. // Playing/Stopping boombox music for nearby players / Updated from Onplayerupdate
  121. public OnPlayerEnterDynamicArea(playerid, areaid)
  122. {
  123.     foreach(Player, i)
  124.     {
  125.         if(GetPVarType(i, "bboxareaid"))
  126.         {
  127.             new station[256];
  128.             GetPVarString(i, "BoomboxURL", station, sizeof(station));
  129.             if(areaid == GetPVarInt(i, "bboxareaid"))
  130.             {
  131.                 PlayAudioStreamForPlayer(playerid, station, GetPVarFloat(i, "bposX"), GetPVarFloat(i, "bposY"), GetPVarFloat(i, "bposZ"), 30.0, 1);
  132.                 SendClientMessage(playerid, COLOR_GREY, " You are listening to music coming out of a nearby boombox.");
  133.                 return 1;
  134.             }
  135.         }
  136.     }
  137.     return 1;
  138. }
  139.  
  140. public OnPlayerLeaveDynamicArea(playerid, areaid)
  141. {
  142.     foreach(Player, i)
  143.     {
  144.         if(GetPVarType(i, "bboxareaid"))
  145.         {
  146.             if(areaid == GetPVarInt(i, "bboxareaid"))
  147.             {
  148.                 StopAudioStreamForPlayer(playerid);
  149.                 SendClientMessage(playerid, COLOR_GREY, " You have went far away from the boombox.");
  150.                 return 1;
  151.             }
  152.         }
  153.     }
  154.     return 1;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement