Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.60 KB | None | 0 0
  1. /*
  2. Includes & Plugins:
  3.     I-ZCMD 0.2.3.0: http://forum.sa-mp.com/showthread.php?t=576114
  4.     MySQL R39-6: http://forum.sa-mp.com/showthread.php?t=56564 | https://github.com/pBlueG/SA-MP-MySQL/releases/tag/R39-6
  5.     Streamer 2.9.0: http://forum.sa-mp.com/showthread.php?t=102865
  6.     Foreach: http://forum.sa-mp.com/showthread.php?t=570868
  7.     sscanf 2.8.2: http://forum.sa-mp.com/showthread.php?t=570927
  8.    
  9.     All work completed in this script was with the help of iGetty:
  10.         http://forum.sa-mp.com/member.php?u=105293
  11.         https://www.youtube.com/channel/UCBWCX6AxNL7-O3xuvSKaG-A
  12.        
  13.     This is the work of XXXXXXXXX, for the roleplay script.
  14. */
  15.  
  16. #include <a_samp>
  17. #include <izcmd>
  18. #include <a_mysql>
  19. #include <streamer>
  20. #include <foreach>
  21. #include <sscanf2>
  22.  
  23. #include "../gamemodes/modules/defines.pwn"
  24. #include "../gamemodes/modules/vars.pwn"
  25. #include "../gamemodes/modules/publics.pwn"
  26.  
  27. #include "../gamemodes/modules/commands/generalcommands.pwn"
  28.  
  29. main(){}
  30.  
  31. public OnGameModeInit()
  32. {
  33.     mysql_log(LOG_ERROR | LOG_WARNING, LOG_TYPE_HTML);
  34.  
  35.     sqlConnection = mysql_connect(SQL_HOST, SQL_USER, SQL_DATABASE, SQL_PASSWORD);
  36.  
  37.     OneSecondTimer = SetTimer("TIMER_OneSecondTimer", 999, true);
  38.     return true;
  39. }
  40.  
  41. public OnGameModeExit()
  42. {
  43.     KillTimer(OneSecondTimer);
  44.  
  45.     mysql_close(sqlConnection);
  46.     return true;
  47. }
  48.  
  49. public OnPlayerConnect(playerid)
  50. {
  51.     DoesPlayerExist(playerid);
  52.     return true;
  53. }
  54.  
  55. public OnPlayerSpawn(playerid)
  56. {
  57.     SetPlayerPos(playerid, pInfo[playerid][pLastPos][0], pInfo[playerid][pLastPos][1], pInfo[playerid][pLastPos][2]);
  58.     SetPlayerFacingAngle(playerid, pInfo[playerid][pLastPos][3]);
  59.     return true;
  60. }
  61.  
  62. public OnPlayerDisconnect(playerid, reason)
  63. {
  64.     LoadDefaultValues(playerid);
  65.     return true;
  66. }
  67.  
  68. public OnPlayerDeath(playerid, killerid, reason)
  69. {
  70.     return true;
  71. }
  72.  
  73. public OnPlayerUpdate(playerid)
  74. {
  75.     if(GetPlayerMoney(playerid) != pInfo[playerid][pMoney]){
  76.         ResetPlayerMoney(playerid);
  77.         GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
  78.     }
  79.  
  80.     return true;
  81. }
  82.  
  83. public OnPlayerText(playerid, text[])
  84. {
  85.     if(!LoggedIn[playerid])return true;
  86.  
  87.     new string[128];
  88.     format(string, sizeof(string), "%s: %s", RPName(playerid), text);
  89.     SendLocalMessage(playerid, COLOR_WHITE, string);
  90.     return false;
  91. }
  92.  
  93. // Stocks and other functions
  94. /*GetIP(playerid) {
  95.     new ip[20];
  96.     GetPlayerIp(playerid, ip, sizeof(ip));
  97.     return ip;
  98. }*/
  99.  
  100. GetName(playerid) {
  101.     new name[MAX_PLAYER_NAME];
  102.     GetPlayerName(playerid, name, sizeof(name));
  103.     return name;
  104. }
  105.  
  106. stock strmatch(const String1[], const String2[])
  107. {
  108.     if((strcmp(String1, String2, true, strlen(String2)) == 0) && (strlen(String2) == strlen(String1)))
  109.     {
  110.         return true;
  111.     }
  112.     else
  113.     {
  114.         return false;
  115.     }
  116. }
  117.  
  118.  
  119. // ------------------------------------
  120.  
  121. /*---------------- Dialogs ---------------------*/
  122. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  123. {
  124.     switch(dialogid) {
  125.         case DIALOG_REGISTER:
  126.         {
  127.             if(!response)return Kick(playerid); // kick the player if they do not respond
  128.  
  129.             // Check if entered password is less than 3 and more than 30.
  130.             if(strlen(inputtext) < 3 || strlen(inputtext) > 30) {
  131.                 ShowRegisterDialog(playerid, "Please ensure your password is more than 2 characters and below 30 characters.");
  132.                 return true;
  133.             }
  134.  
  135.             // Add the player to the database.
  136.             new query[128];
  137.             mysql_format(sqlConnection, query, sizeof(query), "INSERT INTO users (Name, Password) VALUES ('%e', sha1('%e'))", GetName(playerid), inputtext);
  138.             mysql_pquery(sqlConnection, query, "SQL_AccountRegistered", "i", playerid);
  139.         }
  140.         case DIALOG_LOGIN:
  141.         {
  142.             if(!response)return Kick(playerid);// kick the player if they do not respond
  143.  
  144.             // Check if entered password is less than 3 and more than 30.
  145.             if(strlen(inputtext) < 3 || strlen(inputtext) > 30) {
  146.                 ShowLoginDialog(playerid, "Please ensure your password is more than 2 characters and below 30 characters.");
  147.                 return true;
  148.             }
  149.  
  150.             // Login the player.
  151.             new query[128];
  152.             mysql_format(sqlConnection, query, sizeof(query), "SELECT id FROM users WHERE Name = '%e' AND Password = sha1('%e') LIMIT 1", GetName(playerid), inputtext);
  153.             mysql_pquery(sqlConnection, query, "SQL_AccountLogin", "i", playerid);
  154.         }
  155.     }
  156.     return false;
  157. }
  158.  
  159. // ----------------------------- functions -------------------------------------
  160. RPName(playerid)
  161. {
  162.     new name[MAX_PLAYER_NAME];
  163.     GetPlayerName(playerid, name, sizeof(name));
  164.  
  165.     for(new i = 0; i < strlen(name); i++) {
  166.         if(name[i] == '_'){
  167.             name[i] = ' ';
  168.         }
  169.     }
  170.  
  171.     return name;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement