Guest User

Cellphone FS Update #1

a guest
Jan 16th, 2013
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 40.13 KB | None | 0 0
  1. /* *****************************************************************************
  2.           ____     _ _       _                        _____ ____
  3.          / ___|___| | |_ __ | |__   ___  _ __   ___  |  ___/ ___|
  4.         | |   / _ \ | | '_ \| '_ \ / _ \| '_ \ / _ \ | |_  \___ \
  5.         | |__|  __/ | | |_) | | | | (_) | | | |  __/ |  _|  ___) |
  6.          \____\___|_|_| .__/|_| |_|\___/|_| |_|\___| |_|   |____/
  7.                       |_|
  8.  
  9.             This script was made entirely by LarzI aka zCourge.
  10.  
  11.             Shoutout to:
  12.  
  13.                 *   Y_Less for y_ini, sscanf, whirlpool and foreach (y_iterate)
  14.                 *   Zeex for zcmd
  15.                 *   Slice for bit-flags tutorial
  16.  
  17.  
  18. ***************************************************************************** */
  19.  
  20. #include <a_samp>
  21.  
  22. #define FILTERSCRIPT
  23.  
  24. #include <sscanf2>
  25. #include <zcmd>
  26.  
  27. #define MAX_INI_TAGS                    (500) //this has to be before y_ini for using as many tags as we do in our files.
  28.  
  29. #include <YSI\y_ini>
  30. #include <YSI\y_iterate>
  31.  
  32. // -------------------------------------------------------------------------- //
  33.  
  34. #define PHONE_NUMBER_LENGTH             (9)
  35. #define MAX_CONTACTS                    (24)    // <- You may change this value if you want to allow more contacts than 24 (6 contacts per page = 4 full pages)
  36.  
  37. #define DIALOG_DIALING                  (0)
  38. #define DIALOG_INCOMING_CALL            (1)
  39. #define DIALOG_MESSAGE                  (2)
  40. #define DIALOG_PHONEBOOK                (3)
  41. #define DIALOG_ADD_OR_REMOVE_CONTACTS   (4)
  42. #define DIALOG_ADD_CONTACT              (5)
  43. #define DIALOG_REMOVE_CONTACT           (6)
  44. #define DIALOG_CONTACT_CHANGES_MESSAGE  (7)
  45. #define DIALOG_VERIFY_REMOVAL           (8)
  46.  
  47. #define PHONE_BOOK_PATH                 "cellphone\\phonebooks\\%s.ini"
  48. #define PHONE_NUMBERS_PATH              "cellphone\\numbers.ini"
  49. #define CONFIG_PATH                     "cellphone\\filterscript.cfg"
  50.  
  51. // -------------------------------------------------------------------------- //
  52.  
  53. #define CheckFlag(%0,%1)        ((%0)&(%1))
  54. #define SetFlag(%0,%1)          ((%0)|=(%1))
  55. #define ResetFlag(%0,%1)        ((%0)&=(~(%1)))
  56.  
  57. // -------------------------------------------------------------------------- //
  58. // -------------------------------------------------------------------------- //
  59.  
  60. native WP_Hash(buffer[], len, const str[]);
  61.  
  62. // -------------------------------------------------------------------------- //
  63. // -------------------------------------------------------------------------- //
  64.  
  65.  
  66. enum pbInfo //pb = phonebook
  67. {
  68.     pbName[ MAX_PLAYER_NAME ],
  69.     pbNumber[ 10 ]
  70. };
  71.  
  72. enum Flags:( <<= 1 )
  73. {
  74.     PLAYER_IS_IN_PHONECALL = 1,                 //0000001
  75.     PLAYER_IS_ADDING_CONTACT,                   //0000010
  76.     PLAYER_IS_REMOVING_CONTACT,                 //0000100
  77.     PLAYER_HAS_CELLPHONE,                       //0001000
  78.     PLAYER_PHONE_IS_PRIVATE,                    //0010000
  79. };
  80.  
  81. // -------------------------------------------------------------------------- //
  82.  
  83. new
  84.             g_PlayerPhone[ MAX_PLAYERS ][ PHONE_NUMBER_LENGTH ],
  85.             g_PhoneNumbers[ MAX_PLAYERS ][ MAX_PLAYER_NAME ],
  86.             g_TempContactNumber[ MAX_PLAYERS ][ PHONE_NUMBER_LENGTH ],
  87.             g_DialogString[ MAX_PLAYERS ][ MAX_PLAYER_NAME * MAX_CONTACTS + ( MAX_CONTACTS - 1 ) ];
  88.  
  89. new
  90.             g_PhoneBook[ MAX_PLAYERS ][ MAX_CONTACTS ][ pbInfo ];               //each contact has his own name, and we need to put \n between every name;
  91.  
  92. new
  93.     Flags:  g_PlayerFlag[ MAX_PLAYERS ],
  94.             g_Dialer[ MAX_PLAYERS ],
  95.             g_TargetDial[ MAX_PLAYERS ],
  96.             g_DialTimer[ MAX_PLAYERS ],
  97.             g_ExtraContacts[ MAX_PLAYERS ],
  98.             g_ExtraPages[ MAX_PLAYERS ],
  99.             g_CurrentPage[ MAX_PLAYERS ],
  100.             g_Contacts[ MAX_PLAYERS ],
  101.             g_RemovingContact[ MAX_PLAYERS ];
  102.  
  103. new
  104.     bool:   g_PrivatePhones_Enabled,
  105.     bool:   g_TabClickCall_Enabled;
  106.  
  107. // -------------------------------------------------------------------------- //
  108. // -------------------------------------------------------------------------- //
  109.  
  110.  
  111. public OnFilterScriptInit()
  112.  
  113. {
  114.     print("\n--------------------------------------");
  115.     print(" ");
  116.     print(" Cellphone FS - by LarzI aka. zCourge");
  117.     print("                 Loaded");
  118.     print(" ");
  119.     print("--------------------------------------\n");
  120.  
  121.     if( !fexist( PHONE_NUMBERS_PATH ))
  122.     {
  123.         new
  124.             INI:pnFile = INI_Open( PHONE_NUMBERS_PATH ),
  125.             number[ 9 ];
  126.  
  127.         for( new i = 0; i < MAX_PLAYERS; i ++ )
  128.         {
  129.             format( number, sizeof( number ), "555-%04d", i );
  130.             INI_SetTag( pnFile, valstr2( i ));
  131.             INI_WriteString( pnFile, "number", number );
  132.             INI_WriteString( pnFile, "owner", "" );
  133.         }
  134.         INI_Close( pnFile );
  135.     }
  136.     if( !fexist( CONFIG_PATH ))
  137.     {
  138.         new
  139.             INI:confFile = INI_Open( CONFIG_PATH );
  140.  
  141.         INI_SetTag( confFile, "preferences" );
  142.         INI_WriteBool( confFile, "privatenumbers_enabled", true );
  143.         INI_WriteBool( confFile, "tabclickcall_enabled", true ); //OnPlayerClickPlayer
  144.         INI_Close( confFile );
  145.     }
  146.     INI_ParseFile( CONFIG_PATH, "FS_Config", .bPassTag = true );
  147.  
  148.     return true;
  149. }
  150.  
  151. // -------------------------------------------------------------------------- //
  152.  
  153. public OnFilterScriptExit()
  154. {
  155.     print("\n--------------------------------------");
  156.     print(" ");
  157.     print(" Cellphone FS - by LarzI aka. zCourge");
  158.     print("             Unloaded");
  159.     print(" ");
  160.     print("--------------------------------------\n");
  161.  
  162.     return true;
  163. }
  164.  
  165. // -------------------------------------------------------------------------- //
  166.  
  167. public OnPlayerConnect(playerid)
  168. {
  169.     g_PlayerFlag[ playerid ] = Flags: 0;
  170.  
  171.     g_Dialer[ playerid ] = INVALID_PLAYER_ID;
  172.     g_TargetDial[ playerid ] = INVALID_PLAYER_ID;
  173.  
  174.     if( !fexist( PhoneBookPath( playerid )))
  175.     {
  176.         new
  177.             INI:pbFile = INI_Open( PhoneBookPath( playerid ));
  178.  
  179.         INI_SetTag( pbFile, "statistics" );
  180.         INI_WriteInt( pbFile, "contacts", 0 );
  181.         INI_Close( pbFile );
  182.     }
  183.     else
  184.     {
  185.         INI_ParseFile( PhoneBookPath( playerid ), "PhoneBook", .bExtra = true, .extra = playerid, .bPassTag = true );
  186.         for( new i = 0; i < MAX_CONTACTS; i ++ )
  187.         {
  188.             if( isnull( g_PhoneBook[ playerid ][ i ][ pbName ] ))
  189.             {
  190.                 format( g_PhoneBook[ playerid ][ i ][ pbName ], MAX_PLAYER_NAME, "- empty -" );
  191.             }
  192.         }
  193.     }
  194.  
  195.     g_ExtraContacts[ playerid ] = g_Contacts[ playerid ];
  196.  
  197.     return true;
  198. }
  199.  
  200. // -------------------------------------------------------------------------- //
  201.  
  202. public OnPlayerDisconnect(playerid, reason)
  203. {
  204.     if( CheckFlag( g_PlayerFlag[ playerid ], PLAYER_HAS_CELLPHONE ))
  205.     {
  206.         fremove( PhoneBookPath( playerid ));
  207.  
  208.         new
  209.             INI:File = INI_Open( PhoneBookPath( playerid ));                                                //MAX_CONTACTS' digits + 1.
  210.  
  211.         INI_SetTag( File, "statistics" );
  212.         INI_WriteInt( File, "contacts", g_Contacts[ playerid ] );
  213.  
  214.         for( new i = 0; i < g_Contacts[ playerid ]; i ++ )
  215.         {
  216.  
  217.             if( !strcmp( g_PhoneBook[ playerid ][ i ][ pbName ], "- empty -" ))
  218.             {
  219.                 INI_DeleteTag( File, valstr2( i ));
  220.             }
  221.             else
  222.             {
  223.                 INI_SetTag( File, valstr2( i ));
  224.                 INI_WriteString( File, "name", g_PhoneBook[ playerid ][ i ][ pbName ] );
  225.                 INI_WriteString( File, "number", g_PhoneBook[ playerid ][ i ][ pbNumber ] );
  226.             }
  227.         }
  228.         INI_Close( File );
  229.  
  230.         File = INI_Open( PHONE_NUMBERS_PATH );
  231.  
  232.         INI_SetTag( File, "data" );
  233.         INI_WriteString( File, g_PlayerPhone[ playerid ], PlayerName( playerid ));
  234.         INI_Close( File );
  235.  
  236.         g_Contacts[ playerid ] = 0;
  237.  
  238.         for( new i = 0; i < MAX_CONTACTS; i ++ )
  239.         {
  240.             format( g_PhoneBook[ playerid ][ i ][ pbName ], MAX_PLAYER_NAME, "" );
  241.             format( g_PhoneBook[ playerid ][ i ][ pbNumber ], PHONE_NUMBER_LENGTH, "" );
  242.         }
  243.     }
  244.  
  245.     return true;
  246. }
  247.  
  248. // -------------------------------------------------------------------------- //
  249.  
  250. public OnPlayerSpawn(playerid)
  251. {
  252.     new
  253.         firstAvailableNumber,
  254.         bool:fan_Found;
  255.  
  256.     INI_ParseFile( PHONE_NUMBERS_PATH, "PhoneNumbers", .bPassTag = true );
  257.  
  258.     for( new i = 0; i < MAX_PLAYERS; i ++ )
  259.     {
  260.         if( isnull( g_PhoneNumbers[ i ] ) && !fan_Found )
  261.         {
  262.             firstAvailableNumber = i;
  263.             fan_Found = true;
  264.         }
  265.         else if( !strcmp( PlayerName( playerid ), g_PhoneNumbers[ i ] ))
  266.         {
  267.             format( g_PlayerPhone[ playerid ], PHONE_NUMBER_LENGTH, "555-%04d", i + 1 );
  268.             SetFlag( g_PlayerFlag[ playerid ], PLAYER_HAS_CELLPHONE );
  269.             break;
  270.         }
  271.     }
  272.     fan_Found = false;
  273.  
  274.     if( !CheckFlag( g_PlayerFlag[ playerid ], PLAYER_HAS_CELLPHONE ))
  275.     {
  276.         new
  277.             INI:pnFile = INI_Open( PHONE_NUMBERS_PATH );
  278.  
  279.         INI_SetTag( pnFile, valstr2( firstAvailableNumber ));
  280.         INI_WriteString( pnFile, "owner", PlayerName( playerid ));
  281.         INI_Close( pnFile );
  282.  
  283.         format( g_PhoneNumbers[ firstAvailableNumber ], MAX_PLAYER_NAME, "%s", PlayerName( playerid ));
  284.         format( g_PlayerPhone[ playerid ], PHONE_NUMBER_LENGTH, "555-%04d", ( firstAvailableNumber + 1 ));
  285.  
  286.         new
  287.             message[ 40 ];
  288.  
  289.         SendClientMessage( playerid, 0xFFFF00FF, "[INFO] {FFFFFF}You've been given a personal cellphone." );
  290.         format( message, sizeof( message ), "  * {FFFFFF}Your number is: %s.", g_PlayerPhone[ playerid ] );
  291.         SendClientMessage( playerid, 0xFFFF00FF, message );
  292.         SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}You can add contacts to your phonebook by entering /phonebook then press Add Contact - or do /addcontact." );
  293.         SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}to do so, you'll need their number; ask them!" );
  294.         SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}You can \"call\" players by either entering /call [contact/number], accessing your /phonebook" );
  295.         SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}or press tab and doubleclick a player (only if enabled)." );
  296.         SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}Your cellphone is public - this means that any player can call you by doubleclicking your name." );
  297.         SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}to disable this, simply enter /privatephone (toggle - only if enabled)." );
  298.         SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}You may type /phonehelp anytime to re-read these messages." );
  299.     }
  300.     return true;
  301. }
  302.  
  303. // -------------------------------------------------------------------------- //
  304.  
  305. public OnPlayerText(playerid, text[])
  306. {
  307.     if( CheckFlag( g_PlayerFlag[ playerid ], PLAYER_IS_IN_PHONECALL ))
  308.     {
  309.         format( text, 128 , "%s [phone]: {FFFFFF}%s", PlayerName( playerid ), text );
  310.         if( g_TargetDial[ playerid ] != INVALID_PLAYER_ID )
  311.         {
  312.             SendClientMessage( playerid, 0xFFFFFFFF, text );
  313.             SendClientMessage( g_TargetDial[ playerid ], 0xFFFF00FF, text );
  314.         }
  315.         else
  316.         {
  317.             SendClientMessage( playerid, 0xFFFFFFFF, text );
  318.             SendClientMessage( g_Dialer[ playerid ], 0xFFFF00FF, text );
  319.         }
  320.         return false;
  321.     }
  322.     return true;
  323. }
  324.  
  325. // -------------------------------------------------------------------------- //
  326.  
  327. public OnPlayerClickPlayer(playerid, clickedplayerid)
  328. {
  329.     if( g_TabClickCall_Enabled )
  330.     {
  331.         if( playerid == clickedplayerid )
  332.         {
  333.             SendClientMessage( playerid, 0xFF0000FF, "[ERROR] {FFFFFF}You can't call yourself" );
  334.         }
  335.         else if( CheckFlag( g_PlayerFlag[ clickedplayerid ], PLAYER_PHONE_IS_PRIVATE ))
  336.         {
  337.             SendClientMessage( playerid, 0xFF0000FF, "[ERROR] {FFFFFF}The player you're trying to call has set his phone to private." );
  338.         }
  339.         else if( g_Dialer[ clickedplayerid ] != INVALID_PLAYER_ID || g_TargetDial[ clickedplayerid ] != INVALID_PLAYER_ID )
  340.         {
  341.             SendClientMessage( playerid, 0xFF0000FF, "[ERROR] {FFFFFF}The player you're trying to call is currently in a call" );
  342.         }
  343.         else if( g_Dialer[ playerid ] != INVALID_PLAYER_ID || g_TargetDial[ playerid ] != INVALID_PLAYER_ID )
  344.         {
  345.             SendClientMessage( playerid, 0xFF0000FF, "[ERROR] {FFFFFF}End your current call first." );
  346.         }
  347.         else
  348.         {
  349.             TryPhoneCall( playerid, clickedplayerid );
  350.         }
  351.     }
  352.     return true;
  353. }
  354.  
  355. // -------------------------------------------------------------------------- //
  356.  
  357. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  358. {
  359.     switch( dialogid )
  360.     {
  361.         case DIALOG_DIALING:
  362.         {
  363.             if( response )  //Cancel
  364.             {
  365.                 KillTimer( g_DialTimer[ playerid ] );
  366.  
  367.                 ShowPlayerDialog( g_TargetDial[ playerid ], DIALOG_MESSAGE, DIALOG_STYLE_MSGBOX, "Missed call from", PlayerName( playerid ), "OK", "" );
  368.  
  369.                 g_Dialer[ g_TargetDial[ playerid ]] = INVALID_PLAYER_ID;
  370.                 g_TargetDial[ playerid ] = INVALID_PLAYER_ID;
  371.  
  372.                 return true;
  373.             }
  374.         }
  375.         case DIALOG_INCOMING_CALL:
  376.         {
  377.             if( response )  //Accept
  378.             {
  379.                 KillTimer( g_DialTimer[ g_Dialer[ playerid ]] );
  380.  
  381.                 SetFlag( g_PlayerFlag[ playerid ], PLAYER_IS_IN_PHONECALL );
  382.                 SetFlag( g_PlayerFlag[ g_Dialer[ playerid ]], PLAYER_IS_IN_PHONECALL );
  383.  
  384.                 SetPlayerAttachedObject( playerid, 0, 330, 6 );
  385.                 SetPlayerSpecialAction( playerid, SPECIAL_ACTION_USECELLPHONE );
  386.  
  387.                 ShowPlayerDialog( playerid, DIALOG_MESSAGE, DIALOG_STYLE_MSGBOX, "Call accepted", "Type /hangup any time to end the call", "OK", "" );
  388.                 ShowPlayerDialog( g_Dialer[ playerid ], DIALOG_MESSAGE, DIALOG_STYLE_MSGBOX, "Call accepted", "Type /hangup any time to end the call", "OK", "" );
  389.             }
  390.             else            //Decline
  391.             {
  392.                 KillTimer( g_DialTimer[ g_Dialer[ playerid ]] );
  393.                 ShowPlayerDialog( g_Dialer[ playerid ], DIALOG_MESSAGE, DIALOG_STYLE_MSGBOX, "Missed call from", PlayerName( playerid ), "OK", "" );
  394.  
  395.                 g_TargetDial[ g_Dialer[ playerid ]] = INVALID_PLAYER_ID;
  396.                 g_Dialer[ playerid ] = INVALID_PLAYER_ID;
  397.             }
  398.             return true;
  399.         }
  400.         case DIALOG_MESSAGE:
  401.         {
  402.             if( response )  //OK
  403.             {
  404.                 return true;
  405.             }
  406.         }
  407.         case DIALOG_PHONEBOOK:
  408.         {
  409.             new
  410.                 tempContacts = g_ExtraContacts[ playerid ];
  411.             if( !response )
  412.             {
  413.                 return true;
  414.             }
  415.             switch( listitem )
  416.             {
  417.                 case 0:
  418.                 {
  419.                     if( !strcmp( g_PhoneBook[ playerid ][ ( 0 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbName ], "- empty -" ))
  420.                     {
  421.                         ShowPlayerDialog( playerid, DIALOG_PHONEBOOK, DIALOG_STYLE_LIST, "Contacts", g_DialogString[ playerid ], "Select", "Close" );
  422.                         return true;
  423.                     }
  424.                     TryPhoneCall( playerid, PhoneNumberToPlayerid( g_PhoneBook[ playerid ][ ( 0 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbNumber ] ));
  425.                 }
  426.                 case 1:
  427.                 {
  428.                     if( !strcmp( g_PhoneBook[ playerid ][ ( 1 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbName ], "- empty -" ))
  429.                     {
  430.                         ShowPlayerDialog( playerid, DIALOG_PHONEBOOK, DIALOG_STYLE_LIST, "Contacts", g_DialogString[ playerid ], "Select", "Close" );
  431.                         return true;
  432.                     }
  433.                     TryPhoneCall( playerid, PhoneNumberToPlayerid( g_PhoneBook[ playerid ][ ( 1 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbNumber ] ));
  434.                 }
  435.                 case 2:
  436.                 {
  437.                     if( !strcmp( g_PhoneBook[ playerid ][ ( 2 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbName ], "- empty -" ))
  438.                     {
  439.                         ShowPlayerDialog( playerid, DIALOG_PHONEBOOK, DIALOG_STYLE_LIST, "Contacts", g_DialogString[ playerid ], "Select", "Close" );
  440.                         return true;
  441.                     }
  442.                     TryPhoneCall( playerid, PhoneNumberToPlayerid( g_PhoneBook[ playerid ][ ( 2 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbNumber ] ));
  443.                 }
  444.                 case 3:
  445.                 {
  446.                     if( !strcmp( g_PhoneBook[ playerid ][ ( 3 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbName ], "- empty -" ))
  447.                     {
  448.                         ShowPlayerDialog( playerid, DIALOG_PHONEBOOK, DIALOG_STYLE_LIST, "Contacts", g_DialogString[ playerid ], "Select", "Close" );
  449.                         return true;
  450.                     }
  451.                     TryPhoneCall( playerid, PhoneNumberToPlayerid( g_PhoneBook[ playerid ][ ( 3 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbNumber ] ));
  452.                 }
  453.                 case 4:
  454.                 {
  455.                     if( !strcmp( g_PhoneBook[ playerid ][ ( 4 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbName ], "- empty -" ))
  456.                     {
  457.                         ShowPlayerDialog( playerid, DIALOG_PHONEBOOK, DIALOG_STYLE_LIST, "Contacts", g_DialogString[ playerid ], "Select", "Close" );
  458.                         return true;
  459.                     }
  460.                     TryPhoneCall( playerid, PhoneNumberToPlayerid( g_PhoneBook[ playerid ][ ( 4 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbNumber ] ));
  461.                 }
  462.                 case 5:
  463.                 {
  464.                     if( !strcmp( g_PhoneBook[ playerid ][ ( 5 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbName ], "- empty -" ))
  465.                     {
  466.                         ShowPlayerDialog( playerid, DIALOG_PHONEBOOK, DIALOG_STYLE_LIST, "Contacts", g_DialogString[ playerid ], "Select", "Close" );
  467.                         return true;
  468.                     }
  469.                     TryPhoneCall( playerid, PhoneNumberToPlayerid( g_PhoneBook[ playerid ][ ( 5 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbNumber ] ));
  470.                 }
  471.                 case 6:
  472.                 {
  473.                     ShowPlayerDialog( playerid, DIALOG_ADD_OR_REMOVE_CONTACTS, DIALOG_STYLE_LIST, "Add/Remove contacts", "Add\nRemove", "Select", "Go back" );
  474.                 }
  475.                 case 7:
  476.                 {
  477.                     g_DialogString[ playerid ][ 0 ] = EOS;
  478.  
  479.                     if( g_CurrentPage[ playerid ] == g_ExtraPages[ playerid ] )
  480.                     {
  481.                         g_CurrentPage[ playerid ] --;
  482.                     }
  483.                     else
  484.                     {
  485.                         g_CurrentPage[ playerid ] ++;
  486.                     }
  487.                     g_ExtraContacts[ playerid ] = tempContacts;
  488.  
  489.                     OpenPhoneBook( playerid );
  490.                 }
  491.                 case 8: //g_CurrentPage != 0 && != g_Pages
  492.                 {
  493.                     g_CurrentPage[ playerid ] --;
  494.                     g_ExtraContacts[ playerid ] = tempContacts;
  495.  
  496.                     OpenPhoneBook( playerid );
  497.                 }
  498.             }
  499.             return true;
  500.         }
  501.         case DIALOG_ADD_OR_REMOVE_CONTACTS:
  502.         {
  503.             if( !response )
  504.             {
  505.                 OpenPhoneBook( playerid );
  506.                 return true;
  507.             }
  508.             else if( listitem == 0 )
  509.             {
  510.                 if( g_Contacts[ playerid ] == MAX_CONTACTS )
  511.                 {
  512.                     new
  513.                         errorString[ 49 ];
  514.  
  515.                     format( errorString, sizeof( errorString ), "You can only have %d contacts in your phonebook", MAX_CONTACTS );
  516.                     ShowPlayerDialog( playerid, DIALOG_CONTACT_CHANGES_MESSAGE, DIALOG_STYLE_MSGBOX, "Error", errorString, "OK", "" );
  517.                 }
  518.                 else
  519.                 {
  520.                     ShowPlayerDialog( playerid, DIALOG_ADD_CONTACT, DIALOG_STYLE_INPUT, "Add new contact", "Enter phone number", "Next", "Cancel" );
  521.                 }
  522.             }
  523.             else
  524.             {
  525.                 if( g_Contacts[ playerid ] < 1 )
  526.                 {
  527.                     ShowPlayerDialog( playerid, DIALOG_CONTACT_CHANGES_MESSAGE, DIALOG_STYLE_MSGBOX, "Error", "You don't have any entries in your phonebook", "OK", "" );
  528.                 }
  529.                 else
  530.                 {
  531.                     SetFlag( g_PlayerFlag[ playerid ], PLAYER_IS_REMOVING_CONTACT );
  532.                     OpenPhoneBook( playerid );
  533.                 }
  534.             }
  535.             return true;
  536.         }
  537.         case DIALOG_ADD_CONTACT:
  538.         {
  539.             if( !response )
  540.             {
  541.                 if( CheckFlag( g_PlayerFlag[ playerid ], PLAYER_IS_ADDING_CONTACT ))
  542.                 {
  543.                     ShowPlayerDialog( playerid, DIALOG_ADD_CONTACT, DIALOG_STYLE_INPUT, "Add new contact", "Enter phone number", "Next", "Cancel" );
  544.                 }
  545.                 else
  546.                 {
  547.                     OpenPhoneBook( playerid );
  548.                 }
  549.             }
  550.             else
  551.             {
  552.                 if( !CheckFlag( g_PlayerFlag[ playerid ], PLAYER_IS_ADDING_CONTACT ))
  553.                 {
  554.                     if( !IsPhoneNumber( inputtext ))
  555.                     {
  556.                         ShowPlayerDialog( playerid, DIALOG_ADD_CONTACT, DIALOG_STYLE_INPUT, "Add new contact", "Not valid - try again", "Next", "Cancel" );
  557.                     }
  558.                     else
  559.                     {
  560.                         format( g_TempContactNumber[ playerid ], sizeof( g_TempContactNumber[] ), "%s", inputtext );
  561.                         SetFlag( g_PlayerFlag[ playerid ], PLAYER_IS_ADDING_CONTACT );
  562.                         ShowPlayerDialog( playerid, DIALOG_ADD_CONTACT, DIALOG_STYLE_INPUT, "Add new contact", "Enter chosen name", "Add", "Go back" );
  563.                     }
  564.                 }
  565.                 else
  566.                 {
  567.                     TryAddingContact( playerid, inputtext, g_TempContactNumber[ playerid ] );
  568.                 }
  569.             }
  570.             return true;
  571.         }
  572.         case DIALOG_REMOVE_CONTACT:
  573.         {
  574.             new
  575.                 tempContacts = g_ExtraContacts[ playerid ];
  576.  
  577.             if( !response )
  578.             {
  579.                 ResetFlag( g_PlayerFlag[ playerid ], PLAYER_IS_REMOVING_CONTACT );
  580.                 OpenPhoneBook( playerid );
  581.                 return true;
  582.             }
  583.             switch( listitem )
  584.             {
  585.                 case 0:
  586.                 {
  587.                     if( !strcmp( g_PhoneBook[ playerid ][ ( 0 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbName ], "- empty -" ))
  588.                     {
  589.                         ShowPlayerDialog( playerid, DIALOG_REMOVE_CONTACT, DIALOG_STYLE_LIST, "Remove contacts", g_DialogString[ playerid ], "Select", "Go back" );
  590.                         return true;
  591.                         }
  592.                     g_RemovingContact[ playerid ] = ( 0 + ( 6 * g_CurrentPage[ playerid ] ));
  593.                     ShowPlayerDialog( playerid, DIALOG_VERIFY_REMOVAL, DIALOG_STYLE_MSGBOX, "Confirm", "Are you sure you want to remove this contact?", "Yes", "No" );
  594.                 }
  595.                 case 1:
  596.                 {
  597.                     if( !strcmp( g_PhoneBook[ playerid ][ ( 1 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbName ], "- empty -" ))
  598.                     {
  599.                         ShowPlayerDialog( playerid, DIALOG_REMOVE_CONTACT, DIALOG_STYLE_LIST, "Remove contacts", g_DialogString[ playerid ], "Select", "Go back" );
  600.                         return true;
  601.                     }
  602.                     g_RemovingContact[ playerid ] = ( 1 + ( 6 * g_CurrentPage[ playerid ] ));
  603.                     ShowPlayerDialog( playerid, DIALOG_VERIFY_REMOVAL, DIALOG_STYLE_MSGBOX, "Confirm", "Are you sure you want to remove this contact?", "Yes", "No" );
  604.                 }
  605.                 case 2:
  606.                 {
  607.                     if( !strcmp( g_PhoneBook[ playerid ][ ( 2 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbName ], "- empty -" ))
  608.                     {
  609.                         ShowPlayerDialog( playerid, DIALOG_REMOVE_CONTACT, DIALOG_STYLE_LIST, "Remove contacts", g_DialogString[ playerid ], "Select", "Go back" );
  610.                         return true;
  611.                     }
  612.                     g_RemovingContact[ playerid ] = ( 2 + ( 6 * g_CurrentPage[ playerid ] ));
  613.                     ShowPlayerDialog( playerid, DIALOG_VERIFY_REMOVAL, DIALOG_STYLE_MSGBOX, "Confirm", "Are you sure you want to remove this contact?", "Yes", "No" );
  614.                 }
  615.                 case 3:
  616.                 {
  617.                     if( !strcmp( g_PhoneBook[ playerid ][ ( 3 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbName ], "- empty -" ))
  618.                     {
  619.                         ShowPlayerDialog( playerid, DIALOG_REMOVE_CONTACT, DIALOG_STYLE_LIST, "Remove contacts", g_DialogString[ playerid ], "Select", "Go back" );
  620.                         return true;
  621.                     }
  622.                     g_RemovingContact[ playerid ] = ( 3 + ( 6 * g_CurrentPage[ playerid ] ));
  623.                     ShowPlayerDialog( playerid, DIALOG_VERIFY_REMOVAL, DIALOG_STYLE_MSGBOX, "Confirm", "Are you sure you want to remove this contact?", "Yes", "No" );
  624.                 }
  625.                 case 4:
  626.                 {
  627.                     if( !strcmp( g_PhoneBook[ playerid ][ ( 4 + ( 6 * g_CurrentPage[ playerid ] ) )][ pbName ], "- empty -" ))
  628.                     {
  629.                         ShowPlayerDialog( playerid, DIALOG_REMOVE_CONTACT, DIALOG_STYLE_LIST, "Remove contacts", g_DialogString[ playerid ], "Select", "Go back" );
  630.                         return true;
  631.                     }
  632.                     g_RemovingContact[ playerid ] = ( 4 + ( 6 * g_CurrentPage[ playerid ] ));
  633.                     ShowPlayerDialog( playerid, DIALOG_VERIFY_REMOVAL, DIALOG_STYLE_MSGBOX, "Confirm", "Are you sure you want to remove this contact?", "Yes", "No" );
  634.                 }
  635.                 case 5:
  636.                 {
  637.                     if( !strcmp( g_PhoneBook[ playerid ][ ( 5 + ( 6 * g_CurrentPage[ playerid ] )) ][ pbName ], "- empty -" ))
  638.                     {
  639.                         ShowPlayerDialog( playerid, DIALOG_REMOVE_CONTACT, DIALOG_STYLE_LIST, "Remove contacts", g_DialogString[ playerid ], "Select", "Go back" );
  640.                         return true;
  641.                     }
  642.                     g_RemovingContact[ playerid ] = ( 5 + ( 6 * g_CurrentPage[ playerid ] ));
  643.                     ShowPlayerDialog( playerid, DIALOG_VERIFY_REMOVAL, DIALOG_STYLE_MSGBOX, "Confirm", "Are you sure you want to remove this contact?", "Yes", "No" );
  644.                 }
  645.                 case 6:
  646.                 {
  647.                     g_DialogString[ playerid ][ 0 ] = EOS;
  648.  
  649.                     if( g_CurrentPage[ playerid ] == g_ExtraPages[ playerid ] )
  650.                     {
  651.                         g_CurrentPage[ playerid ] --;
  652.                     }
  653.                     else
  654.                     {
  655.                         g_CurrentPage[ playerid ] ++;
  656.                     }
  657.                     g_ExtraContacts[ playerid ] = tempContacts;
  658.  
  659.                     OpenPhoneBook( playerid );
  660.                 }
  661.                 case 7: //g_CurrentPage != 0 && != g_Pages
  662.                 {
  663.                     g_CurrentPage[ playerid ] --;
  664.                     g_ExtraContacts[ playerid ] = tempContacts;
  665.  
  666.                     OpenPhoneBook( playerid );
  667.                 }
  668.             }
  669.         }
  670.         case DIALOG_VERIFY_REMOVAL:
  671.         {
  672.             if( response )
  673.             {
  674.                 TryRemovingContact( playerid, g_PhoneBook[ playerid ][ g_RemovingContact[ playerid ]][ pbName ] );
  675.             }
  676.             else
  677.             {
  678.                 OpenPhoneBook( playerid );
  679.             }
  680.             return true;
  681.         }
  682.         case DIALOG_CONTACT_CHANGES_MESSAGE:
  683.         {
  684.             if( response )
  685.             {
  686.                 if( CheckFlag( g_PlayerFlag[ playerid ], PLAYER_IS_ADDING_CONTACT ))
  687.                 {
  688.                     ResetFlag( g_PlayerFlag[ playerid ], PLAYER_IS_ADDING_CONTACT );
  689.                 }
  690.                 else if( CheckFlag( g_PlayerFlag[ playerid ], PLAYER_IS_REMOVING_CONTACT ))
  691.                 {
  692.                     ResetFlag( g_PlayerFlag[ playerid ], PLAYER_IS_REMOVING_CONTACT );
  693.                 }
  694.                 OpenPhoneBook( playerid );
  695.             }
  696.             return true;
  697.         }
  698.     }
  699.     return false;
  700. }
  701.  
  702. // -------------------------------------------------------------------------- //
  703. // -------------------------------------------------------------------------- //
  704.  
  705. CMD:phonebook(playerid, params[])
  706. {
  707.     OpenPhoneBook( playerid );
  708.     return true;
  709. }
  710.  
  711. CMD:call(playerid, params[])
  712. {
  713.     new
  714.         target[ MAX_PLAYER_NAME ];
  715.  
  716.     if( sscanf( params, "s[24]", target ))
  717.     {
  718.         SendClientMessage( playerid, 0xFFFF00FF, "[USAGE] {FFFFFF}/call [phone number or contact-name]" );
  719.         SendClientMessage( playerid, 0xFFFF00FF, "  * [phone number] {FFFFFF}= An exisiting - and public - phone number" );
  720.         SendClientMessage( playerid, 0xFFFF00FF, "  * [contact-name] {FFFFFF}= An entry from your /phonebook" );
  721.         return SendClientMessage( playerid, 0xFFFF00FF, "[/USAGE]" );
  722.     }
  723.  
  724.     if( IsPhoneNumber( target ))
  725.     {
  726.         if( !IsPlayerConnected( PhoneNumberToPlayerid( target )) )
  727.         {
  728.             SendClientMessage( playerid, 0xFF0000FF, "[ERROR] {FFFFFF}Not found" );
  729.         }
  730.         else
  731.         {
  732.             TryPhoneCall( playerid, PhoneNumberToPlayerid( target ));
  733.         }
  734.     }
  735.     else
  736.     {
  737.         for( new i = 0; i < g_Contacts[ playerid ]; i ++ )
  738.         {
  739.             if( !strcmp( g_PhoneBook[ playerid ][ i ][ pbName ], target, true ))
  740.             {
  741.                 TryPhoneCall( playerid, PhoneNumberToPlayerid( g_PhoneBook[ playerid ][ i ][ pbNumber ] ));
  742.                 return true;
  743.             }
  744.         }
  745.         SendClientMessage( playerid, 0xFF0000FF, "[ERROR] {FFFFFF}Not found" );
  746.     }
  747.     return true;
  748. }
  749.  
  750. CMD:hangup(playerid, params[])
  751. {
  752.     if( g_Dialer[ playerid ] == INVALID_PLAYER_ID || g_TargetDial[ playerid ] == INVALID_PLAYER_ID )
  753.     {
  754.         SendClientMessage( playerid, 0xFF000FF, "[ERROR] {FFFFFF}You can't end a call you're not in" );
  755.         return true;
  756.     }
  757.  
  758.     if( !CheckFlag( g_PlayerFlag[ playerid ], PLAYER_IS_IN_PHONECALL ) && g_Dialer[ playerid ] != INVALID_PLAYER_ID )
  759.     {
  760.         KillTimer( g_DialTimer[ g_Dialer[ playerid ]] );
  761.         ShowPlayerDialog( g_Dialer[ playerid ], DIALOG_MESSAGE, DIALOG_STYLE_MSGBOX, "Missed call from", PlayerName( playerid ), "OK", "" );
  762.     }
  763.     else if( !CheckFlag( g_PlayerFlag[ playerid ], PLAYER_IS_IN_PHONECALL ) && g_TargetDial[ playerid ] != INVALID_PLAYER_ID )
  764.     {
  765.         KillTimer( g_DialTimer[ playerid ] );
  766.         ShowPlayerDialog( g_TargetDial[ playerid ], DIALOG_MESSAGE, DIALOG_STYLE_MSGBOX, "Missed call from", PlayerName( playerid ), "OK", "" );
  767.     }
  768.     else
  769.     {
  770.         ShowPlayerDialog( playerid, DIALOG_MESSAGE, DIALOG_STYLE_MSGBOX, "Call ended", "", "OK", "" );
  771.         ShowPlayerDialog(( (g_TargetDial[ playerid ] == INVALID_PLAYER_ID) ? (g_Dialer[ playerid ]) : (g_TargetDial[ playerid ]) ), DIALOG_MESSAGE, DIALOG_STYLE_MSGBOX, "Call ended", "", "OK", "" );
  772.     }
  773.  
  774.     if( g_Dialer[ playerid ] == INVALID_PLAYER_ID )
  775.     {
  776.         g_Dialer[ g_TargetDial[ playerid ]] = INVALID_PLAYER_ID;
  777.         g_TargetDial[ playerid ] = INVALID_PLAYER_ID;
  778.  
  779.         RemovePlayerAttachedObject( g_TargetDial[ playerid ], 0 );
  780.         SetPlayerSpecialAction( g_TargetDial[ playerid ], SPECIAL_ACTION_STOPUSECELLPHONE );
  781.  
  782.     }
  783.     else
  784.     {
  785.         g_Dialer[ playerid ] = INVALID_PLAYER_ID;
  786.         g_TargetDial[ g_Dialer[ playerid ]] = INVALID_PLAYER_ID;
  787.  
  788.         RemovePlayerAttachedObject( g_Dialer[ playerid ], 0 );
  789.         SetPlayerSpecialAction( g_Dialer[ playerid ], SPECIAL_ACTION_STOPUSECELLPHONE );
  790.     }
  791.  
  792.     RemovePlayerAttachedObject( playerid, 0 );
  793.     SetPlayerSpecialAction( playerid, SPECIAL_ACTION_STOPUSECELLPHONE );
  794.  
  795.  
  796.     return true;
  797. }
  798.  
  799. CMD:addcontact(playerid, params[])
  800. {
  801.     new
  802.         number[ PHONE_NUMBER_LENGTH ],
  803.         name[ MAX_PLAYER_NAME ];
  804.  
  805.     if( sscanf( params, "s[8]s[24]", number, name ))
  806.     {
  807.         SendClientMessage( playerid, 0xFFFF00FF, "[USAGE] {FFFFFF}/addcontact [phone number] [contact-name]" );
  808.         SendClientMessage( playerid, 0xFFFF00FF, "  * [phone number] {FFFFFF}= A player's phone number - ask them to get it" );
  809.         SendClientMessage( playerid, 0xFFFF00FF, "  * [contact-name] {FFFFFF}= Chosen name for the contact" );
  810.         return SendClientMessage( playerid, 0xFFFF00FF, "[/USAGE]" );
  811.     }
  812.  
  813.     if( !IsPhoneNumber( number ))
  814.     {
  815.         return SendClientMessage( playerid, 0xFF0000FF, "[ERROR] {FFFFFF}Phone numbers can only contain digits" );
  816.     }
  817.  
  818.     TryAddingContact( playerid, name, number );
  819.  
  820.     return true;
  821. }
  822.  
  823. CMD:removecontact(playerid, params[])
  824. {
  825.     new
  826.         name[ MAX_PLAYER_NAME ];
  827.  
  828.     if( sscanf( params, "s[MAX_PLAYER_NAME]", name ))
  829.     {
  830.         SendClientMessage( playerid, 0xFFFF00FF, "[USAGE] {FFFFFF}/removecontact [contact-name]" );
  831.         SendClientMessage( playerid, 0xFFFF00FF, "  * [contact-name] {FFFFFF}= Chosen name for the contact" );
  832.         return SendClientMessage( playerid, 0xFFFF00FF, "[/USAGE]" );
  833.     }
  834.  
  835.     TryRemovingContact( playerid, name );
  836.  
  837.     return true;
  838. }
  839.  
  840. CMD:privatephone(playerid, params[])
  841. {
  842.     if( !g_PrivatePhones_Enabled )
  843.     {
  844.         return false;
  845.     }
  846.  
  847.     new
  848.         str[ 45 ];
  849.  
  850.     if( CheckFlag( g_PlayerFlag[ playerid ], PLAYER_PHONE_IS_PRIVATE ))
  851.     {
  852.         ResetFlag( g_PlayerFlag[ playerid ], PLAYER_PHONE_IS_PRIVATE );
  853.     }
  854.     else
  855.     {
  856.         SetFlag( g_PlayerFlag[ playerid ], PLAYER_PHONE_IS_PRIVATE );
  857.     }
  858.  
  859.     format( str, sizeof( str ), "[INFO] {FFFFFF}Phone number set to %s", ( CheckFlag( g_PlayerFlag[ playerid ], PLAYER_PHONE_IS_PRIVATE ) ? ("private") : ("public") ));
  860.     SendClientMessage( playerid, 0xFFFF00FF, str);
  861.  
  862.     return true;
  863. }
  864.  
  865. CMD:phonehelp(playerid, params[])
  866. {
  867.     new
  868.         message[ 40 ];
  869.     format( message, sizeof( message ), "  * {FFFFFF}Your number is: %s.", g_PlayerPhone[ playerid ] );
  870.     SendClientMessage( playerid, 0xFFFF00FF, message );
  871.     SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}You can add contacts to your phonebook by entering /phonebook then press Add Contact - or do /addcontact." );
  872.     SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}to do so, you'll need their number; ask them!" );
  873.     SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}You can \"call\" players by either entering /call [contact/number], accessing your /phonebook" );
  874.     SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}or press tab and doubleclick a player (only if enabled)." );
  875.     SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}Your cellphone is public - this means that any player can call you by doubleclicking your name." );
  876.     SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}to disable this, simply enter /privatephone (toggle - only if enabled)." );
  877.     SendClientMessage( playerid, 0xFFFF00FF, "  * {FFFFFF}You may type /phonehelp anytime to re-read these messages." );
  878.     return true;
  879. }
  880.  
  881.  
  882. // -------------------------------------------------------------------------- //
  883. // -------------------------------------------------------------------------- //
  884.  
  885. forward DialTimer(caller, reciever);
  886. public DialTimer(caller, reciever)
  887. {
  888.     g_TargetDial[ caller ] = INVALID_PLAYER_ID;
  889.     g_Dialer[ reciever ] = INVALID_PLAYER_ID;
  890.  
  891.     ShowPlayerDialog( reciever, DIALOG_MESSAGE, DIALOG_STYLE_MSGBOX, "Missed call from", PlayerName( caller ), "OK", "" );
  892.     ShowPlayerDialog( caller, DIALOG_MESSAGE, DIALOG_STYLE_MSGBOX, "No answer", "The person you tried to call did not pick up.", "OK", "" );
  893.  
  894.     RemovePlayerAttachedObject( caller, 0 );
  895.     SetPlayerSpecialAction( caller, SPECIAL_ACTION_STOPUSECELLPHONE );
  896.  
  897.     return true;
  898. }
  899.  
  900. forward FS_Config(tag[], name[], value[]);
  901. public FS_Config(tag[], name[], value[])
  902. {
  903.     INI_Bool( "privatenumbers_enabled", g_PrivatePhones_Enabled );
  904.     INI_Bool( "tabclickcall_enabled", g_TabClickCall_Enabled );
  905.     return true;
  906. }
  907.  
  908. forward PhoneNumbers(tag[], name[], value[]);
  909. public PhoneNumbers(tag[], name[], value[])
  910. {
  911.     INI_String( "owner", g_PhoneNumbers[ strval( tag ) ], sizeof( g_PhoneNumbers[] ));
  912.     return true;
  913. }
  914.  
  915. forward PhoneBook(playerid, tag[], name[], value[]);
  916. public PhoneBook(playerid, tag[], name[], value[])
  917. {
  918.     if( !strcmp( tag, "statistics", true ))
  919.     {
  920.         INI_Int( "contacts", g_Contacts[ playerid ] );
  921.     }
  922.     else
  923.     {
  924.         INI_String( "name", g_PhoneBook[ playerid ][ ( strval( tag )) ][ pbName ], MAX_PLAYER_NAME );
  925.         INI_String( "number", g_PhoneBook[ playerid ][ ( strval( tag )) ][ pbNumber ], 9 );
  926.     }
  927.     return true;
  928. }
  929.  
  930. // -------------------------------------------------------------------------- //
  931. // -------------------------------------------------------------------------- //
  932.  
  933. OpenPhoneBook(playerid)
  934. {
  935.     g_DialogString[ playerid ][ 0 ] = EOS;
  936.  
  937.     while( g_ExtraContacts[ playerid ] > 6 )
  938.     {
  939.         g_ExtraPages[ playerid ] ++;
  940.         g_ExtraContacts[ playerid ] -= 6;
  941.     }
  942.  
  943.     new
  944.         tempContacts = g_ExtraContacts[ playerid ];
  945.  
  946.     if( g_CurrentPage[ playerid ] == 0 )
  947.     {
  948.         if( g_ExtraPages[ playerid ] > 0 )
  949.         {
  950.             if( g_ExtraContacts[ playerid ] < 6 )
  951.             {
  952.                 g_ExtraContacts[ playerid ] = 6;
  953.             }
  954.             for( new i = 0; i < 6; i ++ )
  955.             {
  956.                 format( g_DialogString[ playerid ], sizeof( g_DialogString[] ), "%s%s\n", g_DialogString[ playerid ][ playerid ], g_PhoneBook[ playerid ][ i ][ pbName ] );
  957.             }
  958.             if( CheckFlag( g_PlayerFlag[ playerid ], PLAYER_IS_REMOVING_CONTACT ))
  959.             {
  960.                 format( g_DialogString[ playerid ], sizeof( g_DialogString[] ), "%sNext page", g_DialogString[ playerid ] );
  961.             }
  962.             else
  963.             {
  964.                 format( g_DialogString[ playerid ], sizeof( g_DialogString[] ), "%s\nAdd/Remove Contact\nNext page", g_DialogString[ playerid ] );
  965.             }
  966.         }
  967.         else
  968.         {
  969.             if( g_ExtraContacts[ playerid ] < 6 )
  970.             {
  971.                 g_ExtraContacts[ playerid ] = 6;
  972.             }
  973.             for( new i = 0; i < g_ExtraContacts[ playerid ]; i ++ )
  974.             {
  975.                 format( g_DialogString[ playerid ], sizeof( g_DialogString[] ), "%s%s\n", g_DialogString[ playerid ], g_PhoneBook[ playerid ][ i ][ pbName ] );
  976.             }
  977.             if( !CheckFlag( g_PlayerFlag[ playerid ], PLAYER_IS_REMOVING_CONTACT ))
  978.             {
  979.                 format( g_DialogString[ playerid ], sizeof( g_DialogString[] ), "%s\nAdd/Remove Contact", g_DialogString[ playerid ] );
  980.             }
  981.         }
  982.     }
  983.     else if( g_CurrentPage[ playerid ] == g_ExtraPages[ playerid ] )
  984.     {
  985.         if( g_ExtraContacts[ playerid ] < 6 )
  986.         {
  987.             g_ExtraContacts[ playerid ] = 6;
  988.         }
  989.  
  990.         for( new i = 0; i < g_ExtraContacts[ playerid ]; i ++ )
  991.         {
  992.             format( g_DialogString[ playerid ], sizeof( g_DialogString[] ), "%s%s\n", g_DialogString[ playerid ], g_PhoneBook[ playerid ][ i + ( 6 * g_CurrentPage[ playerid ] ) ][ pbName ] );
  993.         }
  994.  
  995.         if( g_ExtraPages[ playerid ] < 2 ) // if( g_ExtraPages[ playerid ] == 1 )
  996.         {
  997.             format( g_DialogString[ playerid ], sizeof( g_DialogString[] ), "%sAdd/Remove Contact\nPrevious", g_DialogString[ playerid ] );
  998.         }
  999.         else // if( g_ExtraPages[ playerid ] >= 2 )
  1000.         {
  1001.             format( g_DialogString[ playerid ], sizeof( g_DialogString[] ), "%sAdd/Remove Contact\nNext page\nPrevious page", g_DialogString[ playerid ] );
  1002.         }
  1003.     }
  1004.     else
  1005.     {
  1006.         if( g_ExtraContacts[ playerid ] < 6 )
  1007.         {
  1008.             g_ExtraContacts[ playerid ] = 6;
  1009.         }
  1010.         for( new i = 0; i < g_ExtraContacts[ playerid ]; i ++ )
  1011.         {
  1012.             format( g_DialogString[ playerid ], sizeof( g_DialogString[] ), "%s%s\n", g_DialogString, g_PhoneBook[ playerid ][ i + ( 6 * g_CurrentPage[ playerid ] ) ][ pbName ] );
  1013.         }
  1014.         format( g_DialogString[ playerid ], sizeof( g_DialogString[] ), "%sAdd/Remove Contact\nNext page\nPrevious page", g_DialogString[ playerid ] );
  1015.     }
  1016.  
  1017.     g_ExtraContacts[ playerid ] = tempContacts;
  1018.  
  1019.     if( CheckFlag( g_PlayerFlag[ playerid ], PLAYER_IS_REMOVING_CONTACT ))
  1020.     {
  1021.         ShowPlayerDialog( playerid, DIALOG_REMOVE_CONTACT, DIALOG_STYLE_LIST, "Remove contacts", g_DialogString[ playerid ], "Select", "Go back" );
  1022.     }
  1023.     else
  1024.     {
  1025.         ShowPlayerDialog( playerid, DIALOG_PHONEBOOK, DIALOG_STYLE_LIST, "Contacts", g_DialogString[ playerid ], "Select", "Close" );
  1026.     }
  1027.     return true;
  1028. }
  1029.  
  1030. TryAddingContact(playerid, name[], number[])
  1031. {
  1032.     format( g_PhoneBook[ playerid ][ g_Contacts[ playerid ]][ pbName ], MAX_PLAYER_NAME, "%s", name );
  1033.     format( g_PhoneBook[ playerid ][ g_Contacts[ playerid ]][ pbNumber ], PHONE_NUMBER_LENGTH, "%s", number );
  1034.  
  1035.     g_Contacts[ playerid ] ++;
  1036.     g_ExtraContacts[ playerid ] ++;
  1037.  
  1038.     if( g_ExtraContacts[ playerid ] > 6 )
  1039.     {
  1040.         g_ExtraContacts[ playerid ] -= 6;
  1041.         g_ExtraPages[ playerid ] ++;
  1042.     }
  1043.     ShowPlayerDialog( playerid, DIALOG_CONTACT_CHANGES_MESSAGE, DIALOG_STYLE_MSGBOX, "Success", "Contact added!", "OK", "" );
  1044.  
  1045.     return true;
  1046. }
  1047.  
  1048. TryRemovingContact(playerid, name[])
  1049. {
  1050.     new
  1051.         bool:found;
  1052.  
  1053.     for( new i = 0; i < g_Contacts[ playerid ]; i ++ )
  1054.     {
  1055.         new
  1056.             j = ( i + 1 );
  1057.  
  1058.         if( found )
  1059.         {
  1060.             if( g_Contacts[ playerid ] == j )
  1061.             {
  1062.                 format( g_PhoneBook[ playerid ][ j ][ pbName ], MAX_PLAYER_NAME, "- empty -" );
  1063.                 g_PhoneBook[ playerid ][ j ][ pbNumber ][ 0 ] = EOS;
  1064.             }
  1065.             else
  1066.             {
  1067.                 if( strcmp( g_PhoneBook[ playerid ][ j ][ pbName ], "- empty -" ))
  1068.                 {
  1069.                     format( g_PhoneBook[ playerid ][ i ][ pbName ], MAX_PLAYER_NAME, "%s", g_PhoneBook[ playerid ][ j ][ pbName ] );
  1070.                     format( g_PhoneBook[ playerid ][ i ][ pbNumber ], MAX_PLAYER_NAME, "%s", g_PhoneBook[ playerid ][ j ][ pbNumber ] );
  1071.                     format( g_PhoneBook[ playerid ][ j ][ pbName ], MAX_PLAYER_NAME, "- empty -" );
  1072.                     g_PhoneBook[ playerid ][ j ][ pbNumber ][ 0 ] = EOS;
  1073.                 }
  1074.             }
  1075.         }
  1076.  
  1077.         if( !strcmp( g_PhoneBook[ playerid ][ i ][ pbName ], name, true ) && !found )
  1078.         {
  1079.             if( g_Contacts[ playerid ] == j )
  1080.             {
  1081.                 format( g_PhoneBook[ playerid ][ i ][ pbName ], MAX_PLAYER_NAME, "- empty -" );
  1082.                 g_PhoneBook[ playerid ][ i ][ pbNumber ][ 0 ] = EOS;
  1083.             }
  1084.             else
  1085.             {
  1086.                 if( strcmp( g_PhoneBook[ playerid ][ j ][ pbName ], "- empty -" ))
  1087.                 {
  1088.                     format( g_PhoneBook[ playerid ][ i ][ pbName ], MAX_PLAYER_NAME, "%s", g_PhoneBook[ playerid ][ j ][ pbName ] );
  1089.                     format( g_PhoneBook[ playerid ][ i ][ pbNumber ], MAX_PLAYER_NAME, "%s", g_PhoneBook[ playerid ][ j ][ pbNumber ] );
  1090.                     format( g_PhoneBook[ playerid ][ j ][ pbName ], MAX_PLAYER_NAME, "- empty -" );
  1091.                     g_PhoneBook[ playerid ][ j ][ pbNumber ][ 0 ] = EOS;
  1092.                 }
  1093.             }
  1094.             found = true;
  1095.         }
  1096.         else if( i == ( g_Contacts[ playerid ] - 1 ) && !found )
  1097.         {
  1098.             SendClientMessage( playerid, 0xFF0000FF, "[ERROR] {FFFFFF}The contact could not be found in your phonebook" );
  1099.             return false;
  1100.         }
  1101.     }
  1102.  
  1103.     g_Contacts[ playerid ] --;
  1104.     g_ExtraContacts[ playerid ] --;
  1105.  
  1106.     if( g_ExtraContacts[ playerid ] == 0 && g_ExtraPages[ playerid ] > 0 )
  1107.     {
  1108.         g_ExtraContacts[ playerid ] = 6;
  1109.         g_ExtraPages[ playerid ] --;
  1110.     }
  1111.     ShowPlayerDialog( playerid, DIALOG_CONTACT_CHANGES_MESSAGE, DIALOG_STYLE_MSGBOX, "Success", "Contact removed!", "OK", "" );
  1112.  
  1113.     return true;
  1114. }
  1115.  
  1116. TryPhoneCall(caller, reciever)
  1117. {
  1118.     g_CurrentPage[ caller ] = 0;
  1119.  
  1120.     if( reciever == INVALID_PLAYER_ID )
  1121.     {
  1122.         SendClientMessage( caller, 0xFF0000FF, "[ERROR] {FFFFFF}This player isn't online" );
  1123.         return false;
  1124.     }
  1125.     else if( caller == reciever )
  1126.     {
  1127.         SendClientMessage( caller, 0xFF0000FF, "[ERROR] {FFFFFF}You cannot call yourself." );
  1128.         return false;
  1129.     }
  1130.     else if( CheckFlag( g_PlayerFlag[ reciever ], PLAYER_PHONE_IS_PRIVATE ))
  1131.     {
  1132.         for( new i = 0; i < g_Contacts[ caller ]; i ++ )
  1133.         {
  1134.             if( !strcmp( g_PhoneBook[ caller ][ i ][ pbNumber ], g_PlayerPhone[ reciever ], true ))
  1135.             {
  1136.                 break;
  1137.             }
  1138.             else if( i == ( g_Contacts[ caller ] - 1 ))
  1139.             {
  1140.                 SendClientMessage( caller, 0xFF0000FF, "[ERROR] {FFFFFF}The player you're trying to call has set his phone to private." );
  1141.                 return false;
  1142.             }
  1143.         }
  1144.     }
  1145.     else if( g_TargetDial[ caller ] != INVALID_PLAYER_ID || g_Dialer[ caller ] != INVALID_PLAYER_ID )
  1146.     {
  1147.         SendClientMessage( caller, 0xFF0000FF, "[ERROR] {FFFFFF}You need to end your current phone call before starting a new one." );
  1148.         return false;
  1149.     }
  1150.     else if( g_Dialer[ reciever ] != INVALID_PLAYER_ID || g_TargetDial[ reciever ] != INVALID_PLAYER_ID )
  1151.     {
  1152.         SendClientMessage( caller, 0xFF0000FF, "[ERROR] {FFFFFF}The person you are calling is unavailable." );
  1153.         return false;
  1154.     }
  1155.  
  1156.     g_TargetDial[ caller ] = reciever;
  1157.     g_Dialer[ reciever ] = caller;
  1158.  
  1159.     SetPlayerAttachedObject( caller, 0, 330, 6 );
  1160.     SetPlayerSpecialAction( caller, SPECIAL_ACTION_USECELLPHONE );
  1161.  
  1162.     PlayerPlaySound( caller, 16001, 0.0, 0.0, 0.0 );
  1163.     PlayerPlaySound( reciever, 20600, 0.0, 0.0, 0.0 );
  1164.  
  1165.     ShowPlayerDialog( caller, DIALOG_DIALING, DIALOG_STYLE_MSGBOX, "Calling...", PlayerName( reciever ), "Cancel", "" );
  1166.     ShowPlayerDialog( reciever, DIALOG_INCOMING_CALL, DIALOG_STYLE_MSGBOX, "Incoming call from:", PlayerName( caller ), "Accept", "Decline" );
  1167.  
  1168.  
  1169.  
  1170.     g_DialTimer[ caller ] = SetTimerEx( "DialTimer", ( 10 * 1000 ), false, "ii", caller, reciever );
  1171.  
  1172.     return true;
  1173. }
  1174.  
  1175. PhoneBookPath(playerid)
  1176. {
  1177.     new
  1178.         path[ 42 ],
  1179.         pname[ 24 ];
  1180.  
  1181.     GetPlayerName( playerid, pname, sizeof( pname ));
  1182.     format( path, sizeof( path ), PHONE_BOOK_PATH, pname);
  1183.     return path;
  1184. }
  1185.  
  1186. PlayerName(playerid)
  1187. {
  1188.     new
  1189.         name[ MAX_PLAYER_NAME ];
  1190.  
  1191.     GetPlayerName( playerid, name, sizeof( name ));
  1192.     return name;
  1193. }
  1194.  
  1195. PhoneNumberToPlayerid(number[])
  1196. {
  1197.     foreach( Player, i )
  1198.     {
  1199.         if( !strcmp( g_PlayerPhone[ i ], number ))
  1200.         {
  1201.             return i;
  1202.         }
  1203.     }
  1204.     return INVALID_PLAYER_ID;
  1205. }
  1206.  
  1207. IsPhoneNumber(string[])
  1208. {
  1209.     if( strfind( string, "-", true ) == 3 && strlen( string ) == 8 )
  1210.     {
  1211.         new i;
  1212.         while( i < PHONE_NUMBER_LENGTH )
  1213.         {
  1214.             if(( string[ i ] < '0' || string[ i ] > '9' ) && string[ i ] != EOS )
  1215.             {
  1216.                 return false;
  1217.             }
  1218.             if( i == 2 ) //skip the  '-'
  1219.             {
  1220.                 i ++;
  1221.             }
  1222.             i ++;
  1223.         }
  1224.         return true;
  1225.     }
  1226.     return false;
  1227. }
  1228.  
  1229. valstr2(val)
  1230. {
  1231.     new str[12];
  1232.     valstr(str, val);
  1233.     return str;
  1234. }
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.                                                                                                                                                 // This was made by LarzI aka zCourge - All rights reserved
Advertisement
Add Comment
Please, Sign In to add comment