SHARE
TWEET

Simple Friend System [ENG]

Larceny Oct 4th, 2011 962 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*                                     
  2.                                         ********************************
  3.                                                 SFS - Simple Friend Sys.
  4.                                         ********************************
  5. Descrição:
  6.         Lets you interact with friends from a server.
  7. Versão:
  8.         1.1
  9. Developer:
  10.         Luke "Larceny" G.
  11.         "Lós" .
  12. ChangeLOG:
  13.         04/10/2011:
  14.                 Group chat.
  15.         17/09/2011:
  16.                 First release.
  17. Very thanks to:
  18.         ZeeX                    - ZCMD Command Processor.
  19.         Y_Less                  - Efficient and Powerful sscanf & foreach.
  20.         Double-O-Seven  - DOF2 Fast INI file system.
  21.         SA-MP Team              - For All.
  22. */
  23.  
  24. #define FILTERSCRIPT
  25. #define AMIGODIALOG 9876
  26. #define MESGEDIALOG 9877
  27.  
  28. #include <a_samp>
  29. #include <zcmd>
  30. #include <DOF2>
  31. #include <sscanf2>
  32. #include <foreach>
  33.  
  34. new Text:BackGround;
  35. new Text:TextString[MAX_PLAYERS] = {Text:INVALID_TEXT_DRAW, ...};
  36. new Text:ListString[MAX_PLAYERS] = {Text:INVALID_TEXT_DRAW, ...};
  37.  
  38. new StringTimer[MAX_PLAYERS];
  39. new FriendTimer[MAX_PLAYERS];
  40.  
  41. forward HideMessageBoxForPlayer(playerid);
  42. forward HideFriendBoxForPlayer(playerid);
  43. forward SetMessageBoxForPlayer(playerid, string[]);
  44. forward SetFriendBoxForPlayer(playerid, string[]);
  45.  
  46. stock GetPlayerNameEx(playerid)
  47. {
  48.     new string[MAX_PLAYER_NAME];
  49.     GetPlayerName(playerid, string, MAX_PLAYER_NAME);
  50.     return string;
  51. }
  52.  
  53. stock GetPlayerNameIns(playerid)
  54. {
  55.     new string[MAX_PLAYER_NAME];
  56.     GetPlayerName(playerid, string, MAX_PLAYER_NAME);
  57.         new stringLength = strlen(string);
  58.         strins(string, "~n~", stringLength);
  59.     return string;
  60. }
  61.  
  62. public OnFilterScriptInit()
  63. {
  64.         print("\n-------------------------------------------");
  65.         print("Simple Friend System loaded successfully.");
  66.         print("-------------------------------------------\n");
  67.         //
  68.         BackGround = TextDrawCreate(640.000000, 336.000000, "_");
  69.         TextDrawBackgroundColor(BackGround, 255);
  70.         TextDrawFont(BackGround, 1);
  71.         TextDrawLetterSize(BackGround, 0.600000, 12.000000);
  72.         TextDrawColor(BackGround, -1);
  73.         TextDrawSetOutline(BackGround, 0);
  74.         TextDrawSetProportional(BackGround, 1);
  75.         TextDrawSetShadow(BackGround, 1);
  76.         TextDrawUseBox(BackGround, 1);
  77.         TextDrawBoxColor(BackGround, 119);
  78.         TextDrawTextSize(BackGround, 480.000000, 0.000000);
  79.         return 1;
  80. }
  81.  
  82. public OnFilterScriptExit()
  83. {
  84.         DOF2_Exit();
  85.         return 1;
  86. }
  87.  
  88. public SetMessageBoxForPlayer(playerid, string[])
  89. {
  90.         KillTimer(StringTimer[playerid]);
  91.         TextDrawSetString(TextString[playerid], string);
  92.         TextDrawShowForPlayer(playerid, BackGround);
  93.         TextDrawShowForPlayer(playerid, TextString[playerid]);
  94.         return 1;
  95. }
  96.  
  97. public SetFriendBoxForPlayer(playerid, string[])
  98. {
  99.         KillTimer(FriendTimer[playerid]);
  100.         TextDrawSetString(ListString[playerid], string);
  101.         TextDrawShowForPlayer(playerid, ListString[playerid]);
  102.         return 1;
  103. }
  104.  
  105. public HideFriendBoxForPlayer(playerid)
  106. {
  107.         KillTimer(FriendTimer[playerid]);
  108.         TextDrawHideForPlayer(playerid, ListString[playerid]);
  109.         return 1;
  110. }
  111.  
  112. public HideMessageBoxForPlayer(playerid)
  113. {
  114.         KillTimer(StringTimer[playerid]);
  115.         TextDrawHideForPlayer(playerid, BackGround);
  116.         TextDrawHideForPlayer(playerid, TextString[playerid]);
  117.         return 1;
  118. }
  119.  
  120. public OnPlayerConnect(playerid)
  121. {
  122.         TextString[playerid] = TextDrawCreate(483.000000, 337.000000, "Welcome:");
  123.         TextDrawBackgroundColor(TextString[playerid], 255);
  124.         TextDrawFont(TextString[playerid], 1);
  125.         TextDrawLetterSize(TextString[playerid], 0.210000, 1.400000);
  126.         TextDrawColor(TextString[playerid], -1);
  127.         TextDrawSetOutline(TextString[playerid], 0);
  128.         TextDrawSetProportional(TextString[playerid], 1);
  129.         TextDrawSetShadow(TextString[playerid], 1);
  130.         TextDrawUseBox(TextString[playerid], 1);
  131.         TextDrawBoxColor(TextString[playerid], 0xFFFFFF00);
  132.         TextDrawTextSize(TextString[playerid], 638.000000, 0.000000);
  133.         //
  134.         ListString[playerid] = TextDrawCreate(156.000000, 165.000000, "Friends Online:");
  135.         TextDrawBackgroundColor(ListString[playerid], 255);
  136.         TextDrawFont(ListString[playerid], 1);
  137.         TextDrawLetterSize(ListString[playerid], 0.410000, 0.799999);
  138.         TextDrawColor(ListString[playerid], -1);
  139.         TextDrawSetOutline(ListString[playerid], 0);
  140.         TextDrawSetProportional(ListString[playerid], 1);
  141.         TextDrawSetShadow(ListString[playerid], 1);
  142.         TextDrawUseBox(ListString[playerid], 1);
  143.         TextDrawBoxColor(ListString[playerid], 119);
  144.         TextDrawTextSize(ListString[playerid], 390.000000, 20.000000);
  145.         //
  146.         new USER_FILE[64], AmigosOnline;
  147.         format(USER_FILE, sizeof(USER_FILE), "SFSUsers/%s.ini", GetPlayerNameEx(playerid));
  148.         if(!DOF2_FileExists(USER_FILE)) DOF2_CreateFile(USER_FILE);
  149.         foreach(Player, i)
  150.         {
  151.                 if(DOF2_GetInt(USER_FILE, GetPlayerNameEx(i)) == 1)
  152.                 {
  153.                         AmigosOnline++;
  154.                         new iStr[50];
  155.                         format(iStr, sizeof(iStr), "~n~~n~%s has connected.", GetPlayerNameEx(playerid));
  156.                         SetMessageBoxForPlayer(i, iStr);
  157.                         StringTimer[i] = SetTimerEx("HideMessageBoxForPlayer", 6000, false, "i", i);
  158.                 }
  159.         }
  160.         //
  161.         new iStr[128];
  162.         format(iStr, sizeof(iStr), "Welcome %s,~n~~n~Connected successfully.~n~~n~Friends Online: %i", GetPlayerNameEx(playerid), AmigosOnline);
  163.         TextDrawSetString(TextString[playerid], iStr);
  164.         TextDrawShowForPlayer(playerid, BackGround);
  165.         TextDrawShowForPlayer(playerid, TextString[playerid]);
  166.         StringTimer[playerid] = SetTimerEx("HideMessageBoxForPlayer", 6000, false, "i", playerid);
  167.         return 1;
  168. }
  169.  
  170. public OnPlayerDisconnect(playerid, reason)
  171. {
  172.         TextDrawDestroy(Text:TextString[playerid]);
  173.         TextDrawDestroy(Text:ListString[playerid]);
  174.         TextString[playerid] = Text:INVALID_TEXT_DRAW;
  175.         ListString[playerid] = Text:INVALID_TEXT_DRAW;
  176.         new USER_FILE[64];
  177.         format(USER_FILE, sizeof(USER_FILE), "SFSUsers/%s.ini", GetPlayerNameEx(playerid));
  178.         foreach(Player, i)
  179.         {
  180.                 if(DOF2_GetInt(USER_FILE, GetPlayerNameEx(i)) == 1)
  181.                 {
  182.                         new iStr[50];
  183.                         format(iStr, sizeof(iStr), "~n~~n~%s has disconnected.", GetPlayerNameEx(playerid));
  184.                         SetMessageBoxForPlayer(i, iStr);
  185.                         StringTimer[i] = SetTimerEx("HideMessageBoxForPlayer", 6000, false, "i", i);
  186.                 }
  187.         }
  188.         return 1;
  189. }
  190.  
  191. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  192. {
  193.         switch(dialogid)
  194.         {
  195.                 case AMIGODIALOG:
  196.                 {
  197.                         if(!response)
  198.                         {
  199.                                 SendClientMessage(GetPVarInt(playerid, "AmigoRequest"), 0x33AA33AA, "(*) The invitation has been declined.");
  200.                                 DeletePVar(playerid, "AmigoRequest");
  201.                                 SendClientMessage(playerid, 0x33AA33AA, "(*) You declined the invitation.");
  202.                                 return 1;
  203.                         }
  204.                         new USER_FILE[64], FRIEND_FILE[64];
  205.                         new giveplayerid = GetPVarInt(playerid, "AmigoRequest");
  206.                         format(USER_FILE, sizeof(USER_FILE), "SFSUsers/%s.ini", GetPlayerNameEx(playerid));
  207.                         DOF2_SetInt(USER_FILE, GetPlayerNameEx(giveplayerid), 1);
  208.                         format(FRIEND_FILE, sizeof(FRIEND_FILE), "SFSUsers/%s.ini", GetPlayerNameEx(giveplayerid));
  209.                         DOF2_SetInt(FRIEND_FILE, GetPlayerNameEx(playerid), 1);
  210.                         DOF2_SaveFile();
  211.                         SendClientMessage(giveplayerid, 0x33AA33AA, "(*) The invitation has been accepted.");
  212.                         SendClientMessage(playerid, 0x33AA33AA, "(*) You've accepted the invitation.");
  213.                         DeletePVar(playerid, "AmigoRequest");
  214.                 }
  215.                 case MESGEDIALOG:
  216.                 {
  217.                         if(!response) return 1;
  218.                         new command[128];
  219.                         format(command, sizeof(command), "%i %s", GetPVarInt(playerid, "ClickedPlayer"), inputtext);
  220.                         cmd_msg(playerid, command);
  221.                 }
  222.         }      
  223.         return 1;
  224. }
  225.  
  226. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  227. {
  228.         new USER_FILE[64];
  229.         format(USER_FILE, sizeof(USER_FILE), "SFSUsers/%s.ini", GetPlayerNameEx(playerid));
  230.         if(DOF2_GetInt(USER_FILE, GetPlayerNameEx(clickedplayerid)) == 0) return SendClientMessage(playerid, 0x33AA33AA, "(*) You are not friend of this player.");
  231.         SetPVarInt(playerid, "ClickedPlayer", clickedplayerid);
  232.         ShowPlayerDialog(playerid, MESGEDIALOG, DIALOG_STYLE_INPUT, "Sending message to friend.", "Write a message.", "Send", "Cancel");
  233.         return 1;
  234. }
  235.  
  236. CMD:friend(playerid, params[])
  237. {
  238.         new giveplayerid;
  239.         if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid, 0x33AA33AA, "(*) /friend [playerid]");
  240.         if(playerid == giveplayerid) return SendClientMessage(playerid, 0x33AA33AA, "(*) You cannot be friend of yourself.");
  241.         new USER_FILE[64];
  242.         format(USER_FILE, sizeof(USER_FILE), "SFSUsers/%s.ini", GetPlayerNameEx(playerid));
  243.         if(DOF2_GetInt(USER_FILE, GetPlayerNameEx(giveplayerid)) == 1) return SendClientMessage(playerid, 0x33AA33AA, "(*) You already are friend of this player.");
  244.         new iStr[70];
  245.         format(iStr, sizeof(iStr), "(*) You sent an invitation to %s for a friendship.", GetPlayerNameEx(giveplayerid));
  246.         SendClientMessage(playerid, 0x33AA33AA, iStr);
  247.         format(iStr, sizeof(iStr), "%s wants to become your friend.\nDo you accept?", GetPlayerNameEx(playerid));
  248.         ShowPlayerDialog(giveplayerid, AMIGODIALOG, DIALOG_STYLE_MSGBOX, "Want to be my friend?", iStr, "Yes", "No");
  249.         SetPVarInt(giveplayerid, "AmigoRequest", playerid);
  250.         return 1;
  251. }
  252.  
  253. CMD:deletefriend(playerid, params[])
  254. {
  255.         new giveplayerid;
  256.         if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid, 0x33AA33AA, "(*) /deletefriend [playerid]");
  257.         if(playerid == giveplayerid) return SendClientMessage(playerid, 0x33AA33AA, "(*) You may not delete yourself.");
  258.         new USER_FILE[64];
  259.         format(USER_FILE, sizeof(USER_FILE), "SFSUsers/%s.ini", GetPlayerNameEx(playerid));
  260.         if(DOF2_GetInt(USER_FILE, GetPlayerNameEx(giveplayerid)) != 1) return SendClientMessage(playerid, 0x33AA33AA, "(*) You are not friend of this player.");
  261.         new iStr[70];
  262.         format(iStr, sizeof(iStr), "(*) You deleted %s of your friends.", GetPlayerNameEx(giveplayerid));
  263.         SendClientMessage(playerid, 0x33AA33AA, iStr);
  264.         format(iStr, sizeof(iStr), "(*) %s deleted you as friend.", GetPlayerNameEx(playerid));
  265.         SendClientMessage(giveplayerid, 0x33AA33AA, iStr);
  266.         DOF2_SetInt(USER_FILE, GetPlayerNameEx(giveplayerid), 0);
  267.         //
  268.         new FRIEND_FILE[64];
  269.         format(FRIEND_FILE, sizeof(FRIEND_FILE), "SFSUsers/%s.ini", GetPlayerNameEx(giveplayerid));
  270.         DOF2_SetInt(FRIEND_FILE, GetPlayerNameEx(playerid), 0);
  271.         DOF2_SaveFile();
  272.         return 1;
  273. }
  274.  
  275. CMD:myfriends(playerid, params[])
  276. {
  277.         new count = 0;
  278.         new iStr[1024] = "Friends Online:~n~";
  279.         foreach(Player, i)
  280.         {
  281.                 new USER_FILE[64];
  282.                 format(USER_FILE, sizeof(USER_FILE), "SFSUsers/%s.ini", GetPlayerNameEx(playerid));
  283.                 if(DOF2_GetInt(USER_FILE, GetPlayerNameEx(i)) == 1)
  284.                 {
  285.                         strins(iStr, GetPlayerNameIns(i), strlen(iStr));
  286.                         count++;
  287.                 }
  288.                
  289.         }
  290.         if(count == 0)
  291.         {
  292.                 SetFriendBoxForPlayer(playerid, "Friends Online:~n~None friend online.");
  293.                 FriendTimer[playerid] = SetTimerEx("HideFriendBoxForPlayer", 6000, false, "i", playerid);
  294.         }
  295.         else
  296.         {
  297.                 SetFriendBoxForPlayer(playerid, iStr);
  298.                 FriendTimer[playerid] = SetTimerEx("HideFriendBoxForPlayer", 6000, false, "i", playerid);
  299.         }
  300.         return 1;
  301. }
  302.  
  303. CMD:creditsfs(playerid, params[])
  304. {
  305.         SendClientMessage(playerid, 0xA9C4E4FF, "Simple Friend System - Credits");
  306.         SendClientMessage(playerid, 0xA9C4E4FF, "Delevelopers:");
  307.         SendClientMessage(playerid, 0x33AA33AA, "Luke \"Larceny\" Godoy.");
  308.         SendClientMessage(playerid, 0x33AA33AA, "Los.");
  309.         return 1;
  310. }
  311.  
  312. CMD:helpfs(playerid, params[])
  313. {
  314.         SendClientMessage(playerid, 0xA9C4E4FF, "Commands:");
  315.         SendClientMessage(playerid, 0xA9C4E4FF, "/friend(invite a friend) - /deletefriend - /msg(send message[or click tab]) - /creditsfs - /helpfs - /myfriends(see friends online) - /msn - (chat with all friends online)");
  316.         return 1;
  317. }
  318.  
  319. CMD:msg(playerid, params[])
  320. {
  321.         new giveplayerid, gMsg[128];
  322.         if(sscanf(params, "us[128]", giveplayerid, gMsg)) return SendClientMessage(playerid, 0x33AA33AA, "(*) /msg [playerid] [message]");
  323.         if(playerid == giveplayerid) return SendClientMessage(playerid, 0x33AA33AA, "(*) You may not send message to yourself.");
  324.         if(strcmp(gMsg,"^",true) == 0) return SendClientMessage(playerid, 0x33AA33AA, "(*) ''^'' is not a character allowed.");
  325.         if(strcmp(gMsg,"~",true) == 0) return SendClientMessage(playerid, 0x33AA33AA, "(*) ''~'' is not a character allowed.");
  326.         new iStr[256], gStr[164];
  327.         format(iStr, sizeof(iStr), "%s Says: ~n~%s", GetPlayerNameEx(playerid), gMsg);
  328.         format(gStr, sizeof(gStr), "%s Says: %s", GetPlayerNameEx(playerid), gMsg);
  329.         SetMessageBoxForPlayer(giveplayerid, iStr);
  330.         StringTimer[giveplayerid] = SetTimerEx("HideMessageBoxForPlayer", 6000, false, "i", giveplayerid);
  331.         SendClientMessage(giveplayerid, -1, gStr);
  332.         //
  333.         format(iStr, sizeof(iStr), "To %s: ~n~%s", GetPlayerNameEx(giveplayerid), gMsg);
  334.         format(gStr, sizeof(gStr), "To %s: %s", GetPlayerNameEx(giveplayerid), gMsg);
  335.         SetMessageBoxForPlayer(playerid, iStr);
  336.         SetMessageBoxForPlayer(playerid, iStr);
  337.         StringTimer[playerid] = SetTimerEx("HideMessageBoxForPlayer", 6000, false, "i", playerid);
  338.         SendClientMessage(playerid, -1, gStr);
  339.         return 1;
  340. }
  341.  
  342. CMD:msn(playerid, params[])
  343. {
  344.         new gMsg[128];
  345.         if(sscanf(params, "s[128]", gMsg)) return SendClientMessage(playerid, 0x33AA33AA, "(*) /msn [message]");
  346.         if(strcmp(gMsg,"^",true) == 0) return SendClientMessage(playerid, 0x33AA33AA, "(*) ''^'' is not a character allowed.");
  347.         if(strcmp(gMsg,"~",true) == 0) return SendClientMessage(playerid, 0x33AA33AA, "(*) ''~'' is not a character allowed.");
  348.         new iStr[256], gStr[164];
  349.         format(iStr, sizeof(iStr), "[ALL] %s Says: ~n~%s", GetPlayerNameEx(playerid), gMsg);
  350.         format(gStr, sizeof(gStr), "[ALL] %s Says: %s", GetPlayerNameEx(playerid), gMsg);
  351.         foreach(Player, i)
  352.         {
  353.                 new USER_FILE[64];
  354.                 format(USER_FILE, sizeof(USER_FILE), "SFSUsers/%s.ini", GetPlayerNameEx(playerid));
  355.                 if(DOF2_GetInt(USER_FILE, GetPlayerNameEx(i)) == 1 && playerid != i)
  356.                 {
  357.                         SetMessageBoxForPlayer(i, iStr);
  358.                         StringTimer[i] = SetTimerEx("HideMessageBoxForPlayer", 6000, false, "i", i);
  359.                         SendClientMessage(i, -1, gStr);
  360.                 }
  361.                
  362.         }
  363.         //
  364.         format(iStr, sizeof(iStr), "To All: ~n~%s", gMsg);
  365.         format(gStr, sizeof(gStr), "To All: %s", gMsg);
  366.         SetMessageBoxForPlayer(playerid, iStr);
  367.         SetMessageBoxForPlayer(playerid, iStr);
  368.         StringTimer[playerid] = SetTimerEx("HideMessageBoxForPlayer", 6000, false, "i", playerid);
  369.         SendClientMessage(playerid, -1, gStr);
  370.         return 1;
  371. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top