Guest User

fx-Accounts (English) by FoxHound || Gökhan Akın

a guest
Oct 27th, 2010
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.90 KB | None | 0 0
  1. /*
  2.  *              GUI dini Login-Register
  3.  *       (c) Copyright 2010-2011 by FoxHound
  4.  *
  5.  * @author    : FoxHound aka PSPgamer_10
  6.  * @date      : 27 October 2010
  7.  * @version   : v 1.0
  8.  *
  9.  * This file is provided as is (no warranties).
  10.  *
  11.  */
  12.  
  13. #include <a_samp>
  14. #include <Dini>
  15. //#pragma unused ret_memcpy
  16.  
  17.   //Options
  18.     #define USERFILE_DIRECTION "Accounts/%s.acc"    //This will be saved in scriptfiles/Accounts/PLAYERNAME.acc. (If you want to save directly in Scriptfiles, just type only "%s.acc"
  19.     #define MAX_LOG_TRIES 4     //Maximal tries to log-in
  20.  
  21.   //Dialogs
  22.     #define RegisterDialog 946
  23.     #define LoginDialog 945
  24.  
  25. forward OnPlayerUpdateEx(playerid);             //OnPlayerUpdate Alternative
  26. forward OnPlayerLogin(playerid, pass[]);
  27. forward OnPlayerRegister(playerid, pass[]);
  28.  
  29. enum pVariableData
  30. {
  31.     pSkin,
  32.     pKills, pDeaths,
  33.  
  34.     gPlayerLogged, gLogTries
  35. }
  36. new pData[MAX_PLAYERS][pVariableData];
  37.  
  38. public OnFilterScriptInit()
  39. {
  40.     print("\n<-+-----------------------------------------------+->");
  41.     print("\n<-| FoxHounds GUI-&-dini-supported Login-Register |->");
  42.     print("\n<-| Login-Register by: FoxHound                   |->");
  43.     print("\n<-| dini-System by: DracoBlue                     |->");
  44.     print("\n<-+-----------------------------------------------+->");
  45.     return 1;
  46. }
  47.  
  48. public OnPlayerConnect(playerid)
  49. {
  50.     new string[192],pName[MAX_PLAYER_NAME];
  51.     GetPlayerName(playerid,pName,sizeof(pName));
  52.   /************************* RESETTING PLAYER-VARIABLES *************************/
  53.     pData[playerid][pKills]=0; pData[playerid][pDeaths]=0;
  54.     pData[playerid][pSkin]=0;
  55.  
  56.     pData[playerid][gPlayerLogged]=0; pData[playerid][gLogTries]=0;
  57.   /******************************************************************************/
  58.     RandomPlayerScreen(playerid);   //Absolutely OPTIONAL
  59.     format(string,sizeof(string),USERFILE_DIRECTION,pName);
  60.     if(fexist(string))
  61.     {
  62.         format(string,sizeof(string),"Welcome back, %s !\nPlease log in with your Password:",pName);
  63.         ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", string, "Enter", "Cancel");
  64.     }
  65.     else
  66.     {
  67.         format(string,sizeof(string),"Hi, %s!\nOh, i see... You haven't got an account.\nYou must register and create one before you can play here.\nPlease enter your new Password in this case:",pName);
  68.         ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, "New Useraccount", string, "Enter", "Cancel");
  69.     }
  70.     return 1;
  71. }
  72.  
  73. public OnPlayerDisconnect(playerid, reason)
  74. {
  75.     OnPlayerUpdateEx(playerid);
  76.     return 1;
  77. }
  78.  
  79. public OnPlayerDeath(playerid, killerid, reason)
  80. {
  81.     pData[playerid][pDeaths]+=1;
  82.     if(killerid != INVALID_PLAYER_ID) { pData[killerid][pKills]+=1; }
  83.     return 1;
  84. }
  85.  
  86. public OnPlayerRequestSpawn(playerid)
  87. {
  88.     if(pData[playerid][gPlayerLogged]==1)
  89.     {
  90.         pData[playerid][pSkin]=GetPlayerSkin(playerid);
  91.         return 1;
  92.     }
  93.     return 0;
  94. }
  95.  
  96. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  97. {
  98.     OnPlayerUpdateEx(playerid);
  99.     return 1;
  100. }
  101.  
  102. public OnPlayerStreamIn(playerid, forplayerid)
  103. {
  104.     OnPlayerUpdateEx(playerid);
  105.     return 1;
  106. }
  107.  
  108. public OnPlayerRegister(playerid, pass[])
  109. {
  110.     new string[64],pName[MAX_PLAYER_NAME];
  111.     GetPlayerName(playerid,pName,sizeof(pName));
  112.     format(string,sizeof(string),USERFILE_DIRECTION,pName);
  113.     if(!dini_Exists(string))
  114.     {
  115.         dini_Create(string);
  116.         dini_Set(string,"Password",pass);
  117.         dini_IntSet(string,"Kills",pData[playerid][pKills]);
  118.         dini_IntSet(string,"Deaths",pData[playerid][pDeaths]);
  119.         dini_IntSet(string,"Skin",pData[playerid][pSkin]);
  120.         pData[playerid][gPlayerLogged]=1;
  121.         CallRemoteFunction("OnPlayerSpawn","i",playerid);
  122.         return 1;
  123.     }
  124.     return 1;
  125. }
  126.  
  127. public OnPlayerLogin(playerid, pass[])
  128. {
  129.     new string[128],pName[MAX_PLAYER_NAME];
  130.     GetPlayerName(playerid,pName,sizeof(pName));
  131.     format(string,sizeof(string),USERFILE_DIRECTION,pName);
  132.     if(!strcmp(pass,dini_Get(string,"Password"),false))
  133.     {
  134.         pData[playerid][pKills] = dini_Int(string,"Kills");
  135.         pData[playerid][pDeaths] = dini_Int(string,"Deaths");
  136.         pData[playerid][pSkin] = dini_Int(string,"Skin");
  137.         CallRemoteFunction("OnPlayerSpawn","i",playerid);
  138.         pData[playerid][gPlayerLogged] = 1;
  139.     }
  140.     else
  141.     {
  142.         pData[playerid][gLogTries]+=1;
  143.         if(pData[playerid][gLogTries] >= MAX_LOG_TRIES)
  144.         {
  145.             format(string,sizeof(string),"You entered %d times a wrong password and you got banned.\nThe Ban is here, to avoid Password-Phishing.\nIf you forgot your Password, please contact an Admin.",MAX_LOG_TRIES);
  146.             ShowPlayerDialog(playerid,947,DIALOG_STYLE_MSGBOX,"Login Failed",string,"~","~");
  147.             Ban(playerid);
  148.         }
  149.         else
  150.         {
  151.             format(string,sizeof(string),"Wrong User-password !\nPlease try again.\nRemaining tries: '%d'",(MAX_LOG_TRIES-pData[playerid][gLogTries]));
  152.             ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login Failed", string, "Enter", "Cancel");
  153.         }
  154.     }
  155.     return 1;
  156. }
  157.  
  158. public OnPlayerUpdateEx(playerid)
  159. {
  160.     new string[64],pName[MAX_PLAYER_NAME];
  161.     GetPlayerName(playerid,pName,sizeof(pName));
  162.     format(string,sizeof(string),USERFILE_DIRECTION,pName);
  163.     if(dini_Exists(string) && pData[playerid][gPlayerLogged])
  164.     {
  165.         dini_IntSet(string,"Kills",pData[playerid][pKills]);
  166.         dini_IntSet(string,"Deaths",pData[playerid][pDeaths]);
  167.         dini_IntSet(string,"Skin",GetPlayerSkin(playerid));
  168.         return 1;
  169.     }
  170.     return 1;
  171. }
  172.  
  173. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  174. {
  175.     #define RBUTTON 0 //Right Button
  176.     #define LBUTTON 1 //Left Button
  177.     new string[256],pName[MAX_PLAYER_NAME];
  178.     GetPlayerName(playerid,pName,sizeof(pName));
  179.     switch(dialogid)
  180.     {
  181.         case RegisterDialog:
  182.         {
  183.             switch(response)
  184.             {
  185.                 case RBUTTON: { return Kick(playerid); }
  186.                 case LBUTTON:
  187.                 {
  188.                     new tmp[256],tmppass[64],idx;
  189.                     tmp = strtok(inputtext, idx);
  190.                     if(!strlen(tmp)) {
  191.                         format(string,sizeof(string),"Hi, %s!\nOh, i see... You haven't got an account.\nYou must register and create one before you can play here.\nPlease enter your new Password in this case:",pName);
  192.                         return ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, "New Useraccount", string, "Enter", "Cancel"); }
  193.                     strmid(tmppass,tmp,0,strlen(inputtext),255);
  194.                     OnPlayerRegister(playerid, tmppass);
  195.                 }
  196.             }
  197.         }
  198.         case LoginDialog:
  199.         {
  200.             switch(response)
  201.             {
  202.                 case RBUTTON: { return Kick(playerid); }
  203.                 case LBUTTON:
  204.                 {
  205.                     new tmp[256],tmppass[64],idx;
  206.                     tmp = strtok(inputtext, idx);
  207.                     if(!strlen(tmp)) {
  208.                         format(string,sizeof(string),"Welcome back, %s !\nPlease log in with your Password:",pName);
  209.                         return ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", string, "Enter", "Cancel"); }
  210.                     strmid(tmppass,tmp,0,strlen(inputtext),255);
  211.                     OnPlayerLogin(playerid, tmppass);
  212.                 }
  213.             }
  214.         }
  215.     }
  216.     return 1;
  217. }
  218.  
  219. forward RandomPlayerScreen(playerid); //Absolutely OPTIONAL to Use (Look at Line '58')
  220. public RandomPlayerScreen(playerid) {
  221.     new screen = random(10);
  222.     SetPlayerInterior(playerid, 0);
  223.     switch(screen) {
  224.         case 0: {
  225.             SetPlayerPos(playerid,-346.083618,1599.942139,164.472366);
  226.             SetPlayerCameraPos(playerid,-345.877228,1601.342896,164.518951);
  227.             SetPlayerCameraLookAt(playerid,-340.641968,1938.658447,83.722984); }
  228.         case 1: {
  229.             SetPlayerPos(playerid,1485.0194,-892.1475,74.4098);
  230.             SetPlayerCameraPos(playerid,1479.7717,-886.2401,73.9461);
  231.             SetPlayerCameraLookAt(playerid,1415.3817,-807.9097,85.0613); }
  232.         case 2: {
  233.             SetPlayerPos(playerid,589.1550,373.1002,15.7948);
  234.             SetPlayerCameraPos(playerid,543.9864,349.3647,14.9968);
  235.             SetPlayerCameraLookAt(playerid,422.1727,599.0107,19.1812); }
  236.         case 3: {
  237.             SetPlayerPos(playerid,2155.0137,1129.7897,18.6397);
  238.             SetPlayerCameraPos(playerid,2149.3992,1132.6051,24.3125);
  239.             SetPlayerCameraLookAt(playerid,2105.0222,1156.5306,11.6470); }
  240.         case 4: {
  241.             SetPlayerPos(playerid,-2818.1499,1144.0898,19.2409);
  242.             SetPlayerCameraPos(playerid,-2808.0366,1161.1864,20.3125);
  243.             SetPlayerCameraLookAt(playerid,-2817.9348,1143.5291,19.3762); }
  244.         case 5: {
  245.             SetPlayerPos(playerid,2144.2822,1279.8054,7.9840);
  246.             SetPlayerCameraPos(playerid,2154.24,1306.50,41.46);
  247.             SetPlayerCameraLookAt(playerid,2273.45,1262.09,33.78); }
  248.         case 6: {
  249.             SetPlayerPos(playerid,-1771.7858,-565.5638,-0.5834);
  250.             SetPlayerCameraPos(playerid,-1771.4641,-566.3715,16.4844);
  251.             SetPlayerCameraLookAt(playerid,2105.0222,1156.5306,11.6470); }
  252.         case 7: {
  253.             SetPlayerPos(playerid,-1254.7159,953.9262,139.2734);
  254.             SetPlayerCameraPos(playerid,-1256.6115,953.2058,139.2734);
  255.             SetPlayerCameraLookAt(playerid,-1529.6639,689.2731,45.3311); }
  256.         case 8: {
  257.             SetPlayerPos(playerid,-2295.7979,712.2764,69.7422);
  258.             SetPlayerCameraPos(playerid,-2265.6101,730.9575,49.2969);
  259.             SetPlayerCameraLookAt(playerid,-2243.5103,731.5889,62.7217); }
  260.         case 9: {
  261.             SetPlayerPos(playerid,50.0000,50.0000,70.0000);
  262.             SetPlayerCameraPos(playerid,50.0000,50.0000,70.2203);
  263.             SetPlayerCameraLookAt(playerid,499.8851,504.5435,7.6593); } } }
Add Comment
Please, Sign In to add comment