Advertisement
Larceny

Untitled

Sep 17th, 2011
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.29 KB | None | 0 0
  1. /*                 
  2.                     ********************************
  3.                         SFS - Simple Friend Sys.
  4.                     ********************************
  5. Descrição:
  6.     Permite interagir com amigos de um servidor.
  7. Versão:
  8.     1.0
  9. Developer:
  10.     Luke "Larceny" G.
  11.     "Lós" .
  12. ChangeLOG:
  13.     17/09/2011:
  14.         Primeira versão.
  15. Thanks To:
  16.     ZeeX            - ZCMD Command Processor.
  17.     Y_Less          - Efficient and Powerful sscanf & foreach.
  18.     Double-O-Seven  - DOF2 Fast INI file system.
  19.     Protioso        - PSF include.
  20.     SA-MP Team      - For All.
  21. */
  22.  
  23. #define FILTERSCRIPT
  24. #define AMIGODIALOG 9876
  25. #define MESGEDIALOG 9877
  26.  
  27. #include <a_samp>
  28. #include <zcmd>
  29. #include <DOF2>
  30. #include <sscanf2>
  31. #include <foreach>
  32. #include <PSF>
  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 carregado com sucesso.");
  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, "Bem Vindo:");
  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, "Amigos 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 conectou-se.", 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), "Bem-vindo %s,~n~~n~Conectado com sucesso.~n~~n~Amigos 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 desconectou-se.", 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, "(*) Ele recusou o convite.");
  200.                 DeletePVar(playerid, "AmigoRequest");
  201.                 SendClientMessage(playerid, 0x33AA33AA, "(*) Você recusou o convite.");
  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.             SendClientMessage(giveplayerid, 0x33AA33AA, "(*) Ele aceitou o convite.");
  211.             SendClientMessage(playerid, 0x33AA33AA, "(*) Você aceitou o convite.");
  212.             DeletePVar(playerid, "AmigoRequest");
  213.         }
  214.         case MESGEDIALOG:
  215.         {
  216.             if(!response) return 1;
  217.             new command[128];
  218.             format(command, sizeof(command), "%i %s", GetPVarInt(playerid, "ClickedPlayer"), inputtext);
  219.             cmd_msn(playerid, command);
  220.         }
  221.     }  
  222.     return 1;
  223. }
  224.  
  225. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  226. {
  227.     new USER_FILE[64];
  228.     format(USER_FILE, sizeof(USER_FILE), "SFSUsers /%s.ini", GetPlayerNameEx(playerid));
  229.     if(DOF2_GetInt(USER_FILE, GetPlayerNameEx(clickedplayerid)) == 0) return SendClientMessage(playerid, 0x33AA33AA, "(*) Você não é amigo deste jogador.");
  230.     SetPVarInt(playerid, "ClickedPlayer", clickedplayerid);
  231.     ShowPlayerDialog(playerid, MESGEDIALOG, DIALOG_STYLE_INPUT, "Enviando mensagem para amigo.", "Digite a mensagem.", "Enviar", "Cancelar");
  232.     return 1;
  233. }
  234.  
  235. CMD:amigo(playerid, params[])
  236. {
  237.     new giveplayerid;
  238.     if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid, 0x33AA33AA, "(*) /amigo [playerid]");
  239.     if(playerid == giveplayerid) return SendClientMessage(playerid, 0x33AA33AA, "(*) Você não pode ser amigo de você mesmo.");
  240.     new USER_FILE[64];
  241.     format(USER_FILE, sizeof(USER_FILE), "SFSUsers /%s.ini", GetPlayerNameEx(playerid));
  242.     if(DOF2_GetInt(USER_FILE, GetPlayerNameEx(giveplayerid)) == 1) return SendClientMessage(playerid, 0x33AA33AA, "(*) Você já é amigo deste jogador.");
  243.     new iStr[70];
  244.     format(iStr, sizeof(iStr), "(*) Você enviou um convite a %s para serem amigos.", GetPlayerNameEx(giveplayerid));
  245.     SendClientMessage(playerid, 0x33AA33AA, iStr);
  246.     format(iStr, sizeof(iStr), "%s deseja se tornar seu amigo.\nVocê aceita?", GetPlayerNameEx(playerid));
  247.     ShowPlayerDialog(giveplayerid, AMIGODIALOG, DIALOG_STYLE_MSGBOX, "Deseja ser meu amigo?", iStr, "Sim", "Não");
  248.     SetPVarInt(giveplayerid, "AmigoRequest", playerid);
  249.     return 1;
  250. }
  251.  
  252. CMD:deletaramigo(playerid, params[])
  253. {
  254.     new giveplayerid;
  255.     if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid, 0x33AA33AA, "(*) /deletaramigo [playerid]");
  256.     if(playerid == giveplayerid) return SendClientMessage(playerid, 0x33AA33AA, "(*) Você não pode deletar você mesmo.");
  257.     new USER_FILE[64];
  258.     format(USER_FILE, sizeof(USER_FILE), "SFSUsers /%s.ini", GetPlayerNameEx(playerid));
  259.     if(DOF2_GetInt(USER_FILE, GetPlayerNameEx(giveplayerid)) != 1) return SendClientMessage(playerid, 0x33AA33AA, "(*) Você não é amigo deste jogador.");
  260.     new iStr[70];
  261.     format(iStr, sizeof(iStr), "(*) Você deletou %s de seus amigos.", GetPlayerNameEx(giveplayerid));
  262.     SendClientMessage(playerid, 0x33AA33AA, iStr);
  263.     format(iStr, sizeof(iStr), "%s deletou você como amigo.", GetPlayerNameEx(playerid));
  264.     SendClientMessage(giveplayerid, 0x33AA33AA, iStr);
  265.     DOF2_SetInt(USER_FILE, GetPlayerNameEx(giveplayerid), 0);
  266.     //
  267.     new FRIEND_FILE[64];
  268.     format(FRIEND_FILE, sizeof(FRIEND_FILE), "SFSUsers /%s.ini", GetPlayerNameEx(giveplayerid));
  269.     DOF2_SetInt(FRIEND_FILE, GetPlayerNameEx(playerid), 0);
  270.     return 1;
  271. }
  272.  
  273. CMD:meusamigos(playerid, params[])
  274. {
  275.     new count = 0;
  276.     new iStr[1024] = "Amigos Online:~n~";
  277.     foreach(Player, i)
  278.     {
  279.         new USER_FILE[64];
  280.         format(USER_FILE, sizeof(USER_FILE), "SFSUsers /%s.ini", GetPlayerNameEx(playerid));
  281.         if(DOF2_GetInt(USER_FILE, GetPlayerNameEx(i)) == 1)
  282.         {
  283.             strins(iStr, GetPlayerNameIns(i), strlen(iStr));
  284.             count++;
  285.         }
  286.        
  287.     }
  288.     if(count == 0)
  289.     {
  290.         SetFriendBoxForPlayer(playerid, "Amigos Online:~n~Nenhum amigo online.");
  291.         FriendTimer[playerid] = SetTimerEx("HideFriendBoxForPlayer", 6000, false, "i", playerid);
  292.     }
  293.     else
  294.     {
  295.         SetFriendBoxForPlayer(playerid, iStr);
  296.         FriendTimer[playerid] = SetTimerEx("HideFriendBoxForPlayer", 6000, false, "i", playerid);
  297.     }
  298.     return 1;
  299. }
  300.  
  301. CMD:creditosfs(playerid, params[])
  302. {
  303.     SendClientMessage(playerid, 0xA9C4E4FF, "Simple Friend System - Credits");
  304.     SendClientMessage(playerid, 0xA9C4E4FF, "Delevelopers:");
  305.     SendClientMessage(playerid, 0x33AA33AA, "Luke ''Larceny'' G.");
  306.     SendClientMessage(playerid, 0x33AA33AA, "Los.");
  307.     return 1;
  308. }
  309.  
  310. CMD:ajudafs(playerid, params[])
  311. {
  312.     SendClientMessage(playerid, 0xA9C4E4FF, "Comandos:");
  313.     SendClientMessage(playerid, 0xA9C4E4FF, "/amigo(convidar um amigo) - /deletaramigo - /msn(enviar mensagem[ou clicar tab]) - /creditosfs - /ajudafs - /meusamigos(ver amigos online)");
  314.     return 1;
  315. }
  316.  
  317. CMD:msn(playerid, params[])
  318. {
  319.     new giveplayerid, gMsg[128];
  320.     if(sscanf(params, "us[128]", giveplayerid, gMsg)) return SendClientMessage(playerid, 0x33AA33AA, "(*) /msn [playerid] [mensagem]");
  321.     if(playerid == giveplayerid) return SendClientMessage(playerid, 0x33AA33AA, "(*) Você não pode enviar mensagens para você mesmo.");
  322.     if(strcmp(gMsg,"^",true) == 0) return SendClientMessage(playerid, 0x33AA33AA, "(*) ''^'' não é um caractere permitido.");
  323.     if(strcmp(gMsg,"~",true) == 0) return SendClientMessage(playerid, 0x33AA33AA, "(*) ''~'' não é um caractere permitido.");
  324.     new iStr[256], gStr[164];
  325.     format(iStr, sizeof(iStr), "%s diz: ~n~%s", GetPlayerNameEx(playerid), gMsg);
  326.     format(gStr, sizeof(gStr), "%s diz: %s", GetPlayerNameEx(playerid), gMsg);
  327.     iStr = psf_FormatarStrTexto(iStr);
  328.     SetMessageBoxForPlayer(giveplayerid, iStr);
  329.     StringTimer[giveplayerid] = SetTimerEx("HideMessageBoxForPlayer", 6000, false, "i", giveplayerid);
  330.     SendClientMessage(giveplayerid, -1, gStr);
  331.     //
  332.     format(iStr, sizeof(iStr), "para %s: ~n~%s", GetPlayerNameEx(giveplayerid), gMsg);
  333.     format(gStr, sizeof(gStr), "para %s: %s", GetPlayerNameEx(giveplayerid), gMsg);
  334.     iStr = psf_FormatarStrTexto(iStr);
  335.     SetMessageBoxForPlayer(playerid, iStr);
  336.     StringTimer[playerid] = SetTimerEx("HideMessageBoxForPlayer", 6000, false, "i", playerid);
  337.     SendClientMessage(playerid, -1, gStr);
  338.     return 1;
  339. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement