Advertisement
Guest User

[FS] Walkie Talkye System by Captive

a guest
Jun 2nd, 2013
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.12 KB | None | 0 0
  1. /*
  2.  ============================|Walkie Talkie System|============================
  3. |==============================================================================|
  4. |______________________________________________________________________________|
  5. | Version: v1.0                                                               |
  6. | Author: Captive                                                              |
  7. | Credits: Captive                           |
  8. |______________________________________________________________________________|
  9.                                                Vietata la rimozione dei crediti
  10. Use:
  11. - / Wtmenu to access the menu of the Walkie Talkie to turn it on, turn it off or
  12.   select the frequency, send a sound to the channel
  13. - /wt [text] to talk through Walkie Talkie
  14. */
  15.  
  16. #include <a_samp>
  17. #include <zcmd>
  18. #include <sscanf2>
  19.  
  20. #define COLOR_INFO 0xFFFFFFFF //White
  21. #define COLOR_ERROR 0xFF0000FF //Red
  22. #define COLOR_ME 0x9ACD32AA //Light Green
  23. #define COLOR_WT 0xFF9900AA //Orange
  24. #define COLOR_GREEN 0x33AA33AA
  25. #define COLOR_RED 0xFF0000FF
  26.  
  27. #define DIALOG_WTMENU 0
  28. #define DIALOG_WTCH 3
  29.  
  30. enum wtsystem
  31. {
  32.     bool:wtOn,
  33.     wtChannel
  34. };
  35.  
  36. new Wt_Info[MAX_PLAYERS][wtsystem];
  37. new stringa[256], pName[MAX_PLAYERS];
  38.  
  39. public OnFilterScriptInit()
  40. {
  41.     print("*==========================================*");
  42.     print("|  Walkie Talkie System  .  by Captive     |");
  43.     print("|  ...   ...   ...    Loaded!              |");
  44.     print("*==========================================*");
  45.     return 1;
  46. }
  47.  
  48. public OnPlayerConnect(playerid)
  49. {
  50.     SendClientMessage(playerid, COLOR_WT, "[Use]: /wtmenu to access the menu Walkie Talkie and / wt to talk");
  51.         Wt_Info[playerid][wtOn] = false;
  52.     Wt_Info[playerid][wtChannel] = -1;
  53.     return 1;
  54. }
  55.  
  56. forward StopUseWalkieTalkie(playerid);
  57. forward PlayerPlaySoundToChannel(channel);
  58. //------------------------------------------------------------------------------
  59. CMD:wtmenu(playerid, params[])
  60. {
  61.         if(Wt_Info[playerid][wtOn] == false)ShowPlayerDialog(playerid, DIALOG_WTMENU, DIALOG_STYLE_LIST, "Walkie Talkie Menu", "On", "Confirm", "Cancel");
  62.     else ShowPlayerDialog(playerid, DIALOG_WTMENU, DIALOG_STYLE_LIST, "Walkie Talkie Menu", "Off\nFrequency\nAlert Channel", "Confirm", "Cance");
  63.     return 1;
  64. }
  65.  
  66. CMD:wt(playerid, params[])
  67. {
  68.     new wtMessage[256];
  69.     if(sscanf(params, "s", wtMessage))return SendClientMessage(playerid, COLOR_INFO, "[Use]: /wt [testo]");
  70.     if(Wt_Info[playerid][wtOn] != true)return SendClientMessage(playerid, COLOR_ERROR, "[Error]: {FFFFFF}Your Walkie Talkie is powered off. Use /wtmenu to turn it on");
  71.     if(Wt_Info[playerid][wtChannel] == -1)return SendClientMessage(playerid, COLOR_ERROR, "[Error]: {FFFFFF}Your Walkie Talkie is not set to any frequency. Use /wtmenu to set");
  72.     GetPlayerName(playerid, pName, 24);
  73.     format(stringa, sizeof(stringa), "[WT] %s say: {FFFFFF}%s",pName, wtMessage);
  74.     SendClientMessageToChannel(Wt_Info[playerid][wtChannel], COLOR_WT, stringa);
  75.     SendRangedMessage(playerid, COLOR_INFO, stringa, 15.0);
  76.     if(GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_USECELLPHONE && GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_STOPUSECELLPHONE)
  77.     {
  78.         SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
  79.         SetTimerEx("StopUseWalkieTalkie", 3100, false, "i", playerid);
  80.     }
  81.     return 1;
  82. }
  83.  
  84. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  85. {  
  86.     GetPlayerName(playerid, pName, 24);
  87.     if(dialogid == DIALOG_WTMENU)
  88.     {
  89.         if(response)
  90.         {
  91.             format(stringa, sizeof(stringa), "*%s extracts a Walkie talkie and press the keys*", pName);
  92.             switch(listitem)
  93.             {
  94.                         case 0:
  95.                 {
  96.                         if(Wt_Info[playerid][wtOn] ==  false)
  97.                     {
  98.                         SendClientMessage(playerid, COLOR_INFO, "[Info]: Did you turn on the Walkie Talkie");  
  99.                             Wt_Info[playerid][wtOn] = true;
  100.                         Wt_Info[playerid][wtChannel] = -1;
  101.                         SendRangedMessage(playerid, COLOR_ME, stringa, 15.0);
  102.                     }
  103.                     else
  104.                     {
  105.                         format(stringa, sizeof(stringa), "%s  has left the channel", pName);
  106.                         SendClientMessageToChannel(Wt_Info[playerid][wtChannel], COLOR_RED, stringa);
  107.                         SendClientMessage(playerid, COLOR_INFO, "[Info]: Did you turn off the Walkie Talkie");
  108.                         Wt_Info[playerid][wtOn] = false;
  109.                         Wt_Info[playerid][wtChannel] = -1;
  110.                         SendRangedMessage(playerid, COLOR_ME, stringa, 15.0);
  111.  
  112.                     }
  113.                 }
  114.                 case 1:
  115.                 {
  116.                         if(Wt_Info[playerid][wtOn]!=true)return SendClientMessage(playerid, COLOR_ERROR, "[Error]: {FFFFFF}You must first turn on the Walkie Talkie.");
  117.                     ShowPlayerDialog(playerid, DIALOG_WTCH, DIALOG_STYLE_INPUT, "Frequency Selection", "Select a frequency from 0 to 999", "Select", "Cancel");
  118.                     }
  119.                 case 2:
  120.                 {
  121.                         if(Wt_Info[playerid][wtOn]!=true)return SendClientMessage(playerid, COLOR_ERROR, "[Error]: {FFFFFF}You must first turn on the Walkie Talkie.");
  122.                     PlayerPlaySoundToChannel(Wt_Info[playerid][wtChannel]);
  123.                     SendClientMessageToChannel(Wt_Info[playerid][wtChannel], COLOR_WT, "**The Walkie Talkie issued a sound**");
  124.                     SetTimerEx("PlayerPlaySoundToChannel", 280, false, "d", Wt_Info[playerid][wtChannel]);
  125.                     SetTimerEx("PlayerPlaySoundToChannel", 560, false, "d", Wt_Info[playerid][wtChannel]);
  126.                 }
  127.                             }  
  128.         }
  129.     }
  130. if(dialogid == DIALOG_WTCH)
  131.     {
  132.         if(response)
  133.         {
  134.             if(strval(inputtext) == Wt_Info[playerid][wtChannel])return SendClientMessage(playerid, COLOR_ERROR, "[Error]: {FFFFFF}You are already in this channel.");
  135.             if(strval(inputtext) < 1 && strval(inputtext) > 999)return SendClientMessage(playerid, COLOR_ERROR, "[Error]: {FFFFFF} Select a frequency from 0 to 999");
  136.             {
  137.                 format(stringa, sizeof(stringa), "%s has left the channel", pName);
  138.                 SendClientMessageToChannel(Wt_Info[playerid][wtChannel], COLOR_RED, stringa);
  139.                 Wt_Info[playerid][wtChannel] = strval(inputtext);
  140.                 format(stringa, sizeof(stringa), "%s entered the channel", pName);
  141.                 SendClientMessageToChannel(Wt_Info[playerid][wtChannel], COLOR_GREEN, stringa);
  142.                 format(stringa, sizeof(stringa), "[WT]: You have entered the channel %d", Wt_Info[playerid][wtChannel]);
  143.                 SendClientMessage(playerid, COLOR_GREEN, stringa);
  144.             }
  145.         }
  146.     }
  147.     return 1;
  148. }
  149.  
  150. stock SendRangedMessage(playerid, color, msg[], Float: r)
  151. {
  152.     new Float: Pos[3], players = GetMaxPlayers();
  153.     GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  154.     for(new i; i < players; i++)
  155.     {
  156.         if(!IsPlayerConnected(i)) continue;
  157.         if(IsPlayerInRangeOfPoint(i, r, Pos[0], Pos[1], Pos[2])) SendClientMessage(i, color, msg);
  158.     }
  159.     return 1;
  160. }
  161.  
  162. stock SendClientMessageToChannel(channel, color, message[])
  163. {
  164.     for(new i=0;i<MAX_PLAYERS;i++)
  165.     {
  166.         if(channel == -1)return 0;
  167.         if(Wt_Info[i][wtChannel] == channel)SendClientMessage(i, color, message);
  168.     }
  169.     return 1;
  170. }
  171.  
  172. public StopUseWalkieTalkie(playerid)
  173. {
  174.     SetPlayerSpecialAction(playerid, SPECIAL_ACTION_STOPUSECELLPHONE);
  175.     return 1;
  176. }
  177.  
  178. public PlayerPlaySoundToChannel(channel)
  179. {
  180.     for(new i=0;i<MAX_PLAYERS;i++)
  181.     {
  182.         if(!IsPlayerConnected(i))continue;
  183.         if(channel == -1)return 0;
  184.         if(Wt_Info[i][wtChannel] == channel) PlayerPlaySound(i, 1139, 0, 0 ,0);
  185.     }
  186.     return 1;
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement