MrmirvC

score sys

Oct 16th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.06 KB | None | 0 0
  1. #define PATH "/Giocatori/%s.ini"
  2.  
  3. forward CaricaDati_data(playerid,name[],value[]);
  4.  
  5. enum Giocatore
  6. {
  7.     Password,
  8.     Soldi,
  9.     Admin,
  10.     Banned,
  11.     Score,
  12.     bool:Loggato[MAX_PLAYERS]
  13. }
  14. new InfoGiocatore[MAX_PLAYERS][Giocatore];
  15.  
  16. PercorsoUtente(playerid)
  17. {
  18.     new string[128],playername[MAX_PLAYER_NAME];
  19.     GetPlayerName(playerid,playername,sizeof(playername));
  20.     format(string,sizeof(string),PATH,playername);
  21.     return string;
  22. }
  23.  
  24. udb_hash(buf[])
  25. {
  26.     new length=strlen(buf);
  27.     new s1 = 1;
  28.     new s2 = 0;
  29.     new n;
  30.     for (n=0; n<length; n++)
  31.     {
  32.        s1 = (s1 + buf[n]) % 65521;
  33.        s2 = (s2 + s1)     % 65521;
  34.     }
  35.     return (s2 << 16) + s1;
  36. }
  37.  
  38. public CaricaDati_data(playerid,name[],value[])
  39. {
  40.     INI_Int("Password", InfoGiocatore[playerid][Password]);
  41.     INI_Int("Soldi", InfoGiocatore[playerid][Soldi]);
  42.     INI_Int("Admin", InfoGiocatore[playerid][Admin]);
  43.     INI_Int("Banned", InfoGiocatore[playerid][Banned]);
  44.     INI_Int("Score", InfoGiocatore[playerid][Score]);
  45.     return 1;
  46. }
  47.  
  48. public OnPlayerDisconnect(playerid, reason)
  49. {
  50.     if(InfoGiocatore[playerid][Loggato])
  51.     {
  52.         INI_SetTag(File,"data");
  53.         INI_WriteInt(File,"Soldi",GetPlayerMoney(playerid));
  54.         INI_WriteInt(File,"Admin",InfoGiocatore[playerid][Admin]);
  55.         INI_WriteInt(File,"Banned",InfoGiocatore[playerid][Banned]);
  56.         INI_WriteInt(File,"Score",InfoGiocatore[playerid][Score]);
  57.         INI_Close(File);
  58.     }
  59.     return 1;
  60. }
  61.  
  62.  
  63. //Registration
  64.  
  65. /*Registazione */
  66.     if(dialogid == REGISTRAZIONE)
  67.     {
  68.         if(!response) return Kick(playerid);
  69.         if(response)
  70.         {
  71.             if(!strlen(inputtext) || strlen(inputtext) < 4 || strlen(inputtext) > 16) return ShowPlayerDialog(playerid, REGISTRAZIONE, DIALOG_STYLE_INPUT, "Registrazione", "ERRORE: La password deve essere compresa fra i 4 e 16 caratteri.\nDigita la password:", "Avanti", "Esci");
  72.             new INI:File = INI_Open(PercorsoUtente(playerid));
  73.             INI_WriteInt(File, "Password", udb_hash(inputtext));
  74.             INI_WriteInt(File, "Soldi",0);
  75.             INI_WriteInt(File, "Admin",0);
  76.             INI_WriteInt(File, "Banned",0);
  77.             INI_WriteInt(File, "Score",0);
  78.             INI_Close(File);
  79.             InfoGiocatore[playerid][Loggato] = true;
  80.         }
  81.     }
  82. /* Login */
  83.     if(dialogid == LOGIN)
  84.     {
  85.         if(!response) return Kick(playerid);
  86.         if(response)
  87.         {
  88.             if(udb_hash(inputtext) == InfoGiocatore[playerid][Password])
  89.             {
  90.                 INI_ParseFile(PercorsoUtente(playerid), "CaricaDati_%s", .bExtra = true, .extra = playerid);
  91.                 if(InfoGiocatore[playerid][Banned] == 1) return Kick(playerid);
  92.                 GivePlayerMoney(playerid, InfoGiocatore[playerid][Soldi]);
  93.                 SetPlayerScore(playerid, InfoGiocatore[playerid][Score]);
  94.                 InfoGiocatore[playerid][Loggato] = true;
  95.             }
  96.             else ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_INPUT, "Login", "Digita la password:", "Avanti", "Esci");
  97.         }
  98.     }
  99.     return 1;
  100. }
  101.  
  102.  
  103. CMD:punti(playerid, params[])
  104. {
  105.     new targetid, score;
  106.     if(InfoGiocatore[playerid][Admin] > 0)
  107.     {
  108.         if(sscanf(params,"ui", targetid, score)) return print("Giocatore ggo");
  109.         SetPlayerScore(targetid, score);
  110.     }
  111.     return 1;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment