Advertisement
cL_

DOF2 SA-MP ~cL_

cL_
Nov 2nd, 2022
1,836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.75 KB | Source Code | 0 0
  1. #include <a_samp>
  2. #include <dof2>
  3.  
  4. #define MAX_LENGHT_IP       (16)
  5. #define MAX_LENGHT_PASS     (16)
  6.  
  7. enum
  8. {
  9.     dialog_unknown,
  10.     dialog_register,
  11.     dialog_login
  12. };
  13.  
  14. enum PlayerData
  15. {
  16.     pName[MAX_PLAYER_NAME + 1],
  17.     pIP[MAX_LENGHT_IP],
  18.     pPassword[MAX_LENGHT_PASS],
  19.  
  20.     pSkin,
  21.     pMoney,
  22.     pScore,
  23.  
  24.     pWrong,
  25.     bool:pLogged
  26. };
  27. new PlayerInfo[MAX_PLAYERS][PlayerData];
  28. new pArchive[64];
  29.  
  30. main(){}
  31.  
  32. public OnGameModeInit()
  33. {
  34.     if(!fexist("contas"))
  35.     {                      
  36.         print("\n\n[ERRO] Crie a pasta \"contas\" em \"scriptfiles\"\n\n");
  37.         SendRconCommand("exit");
  38.     }
  39.     return 1;
  40. }
  41.  
  42. public OnGameModeExit()
  43. {
  44.     DOF2_Exit();
  45.     return 1;
  46. }
  47.  
  48. public OnPlayerRequestClass(playerid, classid)
  49. {
  50.     format(pArchive, sizeof(pArchive), "contas/%s.ini", PlayerInfo[playerid][pName]);
  51.     if(DOF2_FileExists(pArchive))
  52.     {
  53.         format(PlayerInfo[playerid][pPassword], MAX_LENGHT_PASS, DOF2_GetString(pArchive, "password"));    
  54.         ShowPlayerDialog(playerid, dialog_login, DIALOG_STYLE_INPUT, "Logar-se", "Insira sua senha abaixo:", "Logar", "X");
  55.     } else {
  56.         ShowPlayerDialog(playerid, dialog_register, DIALOG_STYLE_INPUT, "Registre-se", "Insira uma senha abaixo:", "Registrar", "X");
  57.     }
  58.     return 1;
  59. }
  60.  
  61. public OnPlayerConnect(playerid)
  62. {
  63.     GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME + 1);
  64.     GetPlayerIp(playerid, PlayerInfo[playerid][pIP], MAX_LENGHT_IP);
  65.     return 1;
  66. }
  67.  
  68. public OnPlayerDisconnect(playerid, reason)
  69. {
  70.     Player_Save(playerid);
  71.     Player_Reset(playerid);
  72.     return 1;
  73. }
  74.  
  75. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  76. {
  77.     switch(dialogid)
  78.     {
  79.         case dialog_login:
  80.         {
  81.             if(!response)
  82.                 return Kick(playerid);
  83.  
  84.             if(response)
  85.             {
  86.                 if(!strlen(inputtext))
  87.                     return ShowPlayerDialog(playerid, dialog_login, DIALOG_STYLE_INPUT, "Logar-se", "ERRO: Insira algo na box.\nInsira sua senha abaixo:", "Logar", "X");
  88.  
  89.                 if(strcmp(PlayerInfo[playerid][pPassword], inputtext, true) == 0)
  90.                 {
  91.                     Player_Load(playerid);             
  92.                 } else {
  93.                     ShowPlayerDialog(playerid, dialog_login, DIALOG_STYLE_INPUT, "Logar-se", "ERRO: Senha incorreta.\nInsira sua senha abaixo:", "Logar", "X");
  94.                     PlayerInfo[playerid][pWrong]++;
  95.  
  96.                     if(PlayerInfo[playerid][pWrong] >= 3)
  97.                         return Kick(playerid);
  98.                 }
  99.             }
  100.         }
  101.         case dialog_register:
  102.         {
  103.             if(!response)
  104.                 return Kick(playerid);
  105.  
  106.             if(response)
  107.             {
  108.                 if(!strlen(inputtext))
  109.                     return ShowPlayerDialog(playerid, dialog_register, DIALOG_STYLE_INPUT, "Registre-se", "ERRO: Insira algo na box.\nInsira uma senha abaixo:", "Registrar", "X");
  110.  
  111.                 if(strlen(inputtext) < 4 || strlen(inputtext) > MAX_LENGHT_PASS)
  112.                     return ShowPlayerDialog(playerid, dialog_register, DIALOG_STYLE_INPUT, "Registre-se", "Insira uma senha abaixo:", "Registrar", "X");
  113.  
  114.                 format(PlayerInfo[playerid][pPassword], MAX_LENGHT_PASS, inputtext);
  115.                 Player_Create(playerid, PlayerInfo[playerid][pName], PlayerInfo[playerid][pIP], PlayerInfo[playerid][pPassword]);
  116.             }
  117.         }
  118.     }
  119.     return 1;
  120. }
  121.  
  122. Player_Create(playerid, name[], ip[], password[])
  123. {
  124.     format(pArchive, sizeof(pArchive), "contas/%s.ini", name);
  125.     if(!DOF2_FileExists(pArchive))
  126.     {
  127.         DOF2_CreateFile(pArchive);
  128.  
  129.         DOF2_SetString(pArchive, "name", name);
  130.         DOF2_SetString(pArchive, "ip", ip);
  131.         DOF2_SetString(pArchive, "password", password);
  132.  
  133.         DOF2_SetInt(pArchive, "skin", random(311));
  134.         DOF2_SetInt(pArchive, "money", 250);
  135.         DOF2_SetInt(pArchive, "score", 1);
  136.  
  137.         DOF2_SaveFile();
  138.  
  139.         Player_Load(playerid);
  140.     }
  141.     return 1;
  142. }
  143.  
  144. Player_Load(playerid)
  145. {  
  146.     format(pArchive, sizeof(pArchive), "contas/%s.ini", PlayerInfo[playerid][pName]);
  147.     if(DOF2_FileExists(pArchive))
  148.     {
  149.         PlayerInfo[playerid][pSkin]     = DOF2_GetInt(pArchive, "skin");
  150.         PlayerInfo[playerid][pMoney]    = DOF2_GetInt(pArchive, "money");
  151.         PlayerInfo[playerid][pScore]    = DOF2_GetInt(pArchive, "score");
  152.  
  153.         PlayerInfo[playerid][pWrong]    = 0;
  154.         PlayerInfo[playerid][pLogged]   = true;
  155.  
  156.         SetSpawnInfo(playerid, NO_TEAM, PlayerInfo[playerid][pSkin], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  157.         SpawnPlayer(playerid);
  158.     }
  159.     return 1;
  160. }
  161.  
  162. Player_Save(playerid)
  163. {
  164.     if(PlayerInfo[playerid][pLogged])
  165.     {
  166.         format(pArchive, sizeof(pArchive), "contas/%s.ini", PlayerInfo[playerid][pName]);
  167.         if(DOF2_FileExists(pArchive))
  168.         {
  169.             DOF2_SetString(pArchive, "name", PlayerInfo[playerid][pName]);
  170.             DOF2_SetString(pArchive, "ip", PlayerInfo[playerid][pIP]);
  171.             DOF2_SetString(pArchive, "password", PlayerInfo[playerid][pPassword]);
  172.  
  173.             DOF2_SetInt(pArchive, "skin", PlayerInfo[playerid][pSkin]);
  174.             DOF2_SetInt(pArchive, "money", PlayerInfo[playerid][pMoney]);
  175.             DOF2_SetInt(pArchive, "score", PlayerInfo[playerid][pScore]);
  176.  
  177.             DOF2_SaveFile();
  178.         }
  179.     }
  180.     return 1;
  181. }
  182.  
  183. Player_Reset(playerid)
  184. {
  185.     new dummy[PlayerData];
  186.     PlayerInfo[playerid] = dummy;
  187.     return 1;
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement