daily pastebin goal
77%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // includes
  2.  
  3. #include <a_samp>
  4. #include <a_mysql>
  5. #include <Pawn.CMD>
  6.  
  7. // defines
  8.  
  9. #define MYSQL_HOST                      "localhost"
  10. #define MYSQL_USER                      "root"
  11. #define MYSQL_DB                        "db1"
  12. #define MYSQL_PASS                      ""
  13. #define SCM                             SendClientMessage
  14.  
  15. // new
  16.  
  17. new mysql_id;
  18.  
  19. new Random_Skin_Male[] = {
  20.     292, 293
  21. };
  22. new Random_Skin_Female[] = {
  23.     12, 138
  24. };
  25.  
  26. // enums
  27.  
  28. enum {
  29.     D_LANGUAGE, D_REG, D_REG_SEX,
  30.     D_LOGIN,
  31.     D_ATM,
  32.     D_SETTINGS,
  33. };
  34.  
  35. enum player_info {
  36.     ID,
  37.     Name[MAX_PLAYER_NAME],
  38.     Password[24],
  39.     Language, // 1 - Russian, 2 - English
  40.     Sex,
  41.     Skin,
  42. };
  43. new pInfo[MAX_PLAYERS][player_info];
  44.  
  45. main(){}
  46.  
  47. public OnGameModeInit() {
  48.     mysql_id = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DB, MYSQL_PASS);
  49.     SetGameModeText(" ");
  50.     return true;
  51. }
  52.  
  53. public OnGameModeExit() {
  54.     mysql_close(mysql_id);
  55.     return true;
  56. }
  57.  
  58. public OnPlayerRequestClass(playerid, classid) {
  59.     if(GetPVarInt(playerid, "Is_Authed")) return SpawnPlayer(playerid);
  60.     return true;
  61. }
  62.  
  63. public OnPlayerConnect(playerid) {
  64.     GetPlayerName(playerid, pInfo[playerid][Name], MAX_PLAYER_NAME);
  65.     //
  66.     new query[40+MAX_PLAYER_NAME];
  67.     mysql_format(mysql_id, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name`='%s'", pInfo[playerid][Name]);
  68.     mysql_function_query(mysql_id, query, true, "@_FindPlayerInTable", "i", playerid);
  69.     return true;
  70. }
  71.  
  72. public OnPlayerDisconnect(playerid, reason) {
  73.     RemovePlayerInfo(playerid);
  74.     DeletePVar(playerid, "Is_Authed");
  75.     return true;
  76. }
  77.  
  78. public OnPlayerSpawn(playerid) {
  79.     SetPlayerPos(playerid, 0.0, 0.0, 5.0);
  80.     SetPlayerSkin(playerid, pInfo[playerid][Skin]);
  81.     return true;
  82. }
  83.  
  84. public OnPlayerDeath(playerid, killerid, reason)
  85. {
  86.     return true;
  87. }
  88.  
  89. public OnVehicleSpawn(vehicleid)
  90. {
  91.     return true;
  92. }
  93.  
  94. public OnVehicleDeath(vehicleid, killerid)
  95. {
  96.     return true;
  97. }
  98.  
  99. public OnPlayerText(playerid, text[])
  100. {
  101.     return true;
  102. }
  103.  
  104. public OnPlayerCommandText(playerid, cmdtext[]) {
  105.     return 0;
  106. }
  107.  
  108. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  109. {
  110.     return true;
  111. }
  112.  
  113. public OnPlayerExitVehicle(playerid, vehicleid)
  114. {
  115.     return true;
  116. }
  117.  
  118. public OnPlayerStateChange(playerid, newstate, oldstate)
  119. {
  120.     return true;
  121. }
  122.  
  123. public OnPlayerEnterCheckpoint(playerid)
  124. {
  125.     return true;
  126. }
  127.  
  128. public OnPlayerLeaveCheckpoint(playerid)
  129. {
  130.     return true;
  131. }
  132.  
  133. public OnPlayerEnterRaceCheckpoint(playerid)
  134. {
  135.     return true;
  136. }
  137.  
  138. public OnPlayerLeaveRaceCheckpoint(playerid)
  139. {
  140.     return true;
  141. }
  142.  
  143. public OnRconCommand(cmd[])
  144. {
  145.     return true;
  146. }
  147.  
  148. public OnPlayerRequestSpawn(playerid)
  149. {
  150.     return true;
  151. }
  152.  
  153. public OnObjectMoved(objectid)
  154. {
  155.     return true;
  156. }
  157.  
  158. public OnPlayerObjectMoved(playerid, objectid)
  159. {
  160.     return true;
  161. }
  162.  
  163. public OnPlayerPickUpPickup(playerid, pickupid)
  164. {
  165.     return true;
  166. }
  167.  
  168. public OnVehicleMod(playerid, vehicleid, componentid)
  169. {
  170.     return true;
  171. }
  172.  
  173. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  174. {
  175.     return true;
  176. }
  177.  
  178. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  179. {
  180.     return true;
  181. }
  182.  
  183. public OnPlayerSelectedMenuRow(playerid, row)
  184. {
  185.     return true;
  186. }
  187.  
  188. public OnPlayerExitedMenu(playerid)
  189. {
  190.     return true;
  191. }
  192.  
  193. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  194. {
  195.     return true;
  196. }
  197.  
  198. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  199.     if(newkeys & 1024) { // alt
  200.         if(IsPlayerInRangeOfPoint(playerid, 5.0, 0, 0, 5)) {
  201.             if(pInfo[playerid][Language] == 1) return ShowPlayerDialog(playerid, D_ATM, DIALOG_STYLE_LIST, "Áàíêîìàò", "1. Ïîïîëíèòü ñ÷¸ò\n2. Ñíÿòü ñî ñ÷¸òà", "Âûáðàòü", "Îòìåíà");
  202.             else ShowPlayerDialog(playerid, D_ATM, DIALOG_STYLE_LIST, "ATM", "1. Deposit\n2. Withdraw", "Choose", "Cancel");
  203.         }
  204.     }
  205.     return true;
  206. }
  207.  
  208. public OnRconLoginAttempt(ip[], password[], success)
  209. {
  210.     return true;
  211. }
  212.  
  213. public OnPlayerUpdate(playerid)
  214. {
  215.     return true;
  216. }
  217.  
  218. public OnPlayerStreamIn(playerid, forplayerid)
  219. {
  220.     return true;
  221. }
  222.  
  223. public OnPlayerStreamOut(playerid, forplayerid)
  224. {
  225.     return true;
  226. }
  227.  
  228. public OnVehicleStreamIn(vehicleid, forplayerid)
  229. {
  230.     return true;
  231. }
  232.  
  233. public OnVehicleStreamOut(vehicleid, forplayerid)
  234. {
  235.     return true;
  236. }
  237.  
  238. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  239.     switch(dialogid) {
  240.         case D_LANGUAGE: {
  241.             if(!response)
  242.                 return Kick(playerid);
  243.             pInfo[playerid][Language] = listitem+1;
  244.             Show_Register(playerid);
  245.             return true;
  246.         }
  247.         case D_REG: {
  248.             if(!response) return Kick(playerid);
  249.             if(!(0 <= strlen(inputtext) <= 24)) return Show_Register(playerid);
  250.             strmid(pInfo[playerid][Password], inputtext, 0, 64, 255);
  251.             if(pInfo[playerid][Language] == 1)
  252.                 return ShowPlayerDialog(playerid, D_REG_SEX, DIALOG_STYLE_LIST,
  253.                     "Âûáåðåòå âàø ïîë",
  254.                     "1. Ìóæñêîé\n2. Æåíñêèé",
  255.                     "Äàëåå", "Îòìåíà");
  256.             else ShowPlayerDialog(playerid, D_REG_SEX, DIALOG_STYLE_LIST,
  257.                 "Choose your sex",
  258.                 "1. Male\n2. Female",
  259.                 "Next", "Exit");
  260.             return true;
  261.         }
  262.         case D_REG_SEX: {
  263.             if(!response)
  264.                 return Kick(playerid);
  265.             pInfo[playerid][Sex] = listitem + 1;
  266.             pInfo[playerid][Skin] = (listitem == 0) ?
  267.             (Random_Skin_Male[random(sizeof(Random_Skin_Male))]) :
  268.             (Random_Skin_Female[random(sizeof(Random_Skin_Female))]);
  269.             CreateNewAccount(playerid);
  270.             return true;
  271.         }
  272.         case D_LOGIN: {
  273.             if(!response)
  274.                 return Kick(playerid);
  275.             if(!(0 <= strlen(inputtext) <= 24))
  276.                 return Show_Login(playerid);
  277.             if(!strcmp(pInfo[playerid][Password], inputtext)) {
  278.                 new query[44+24];
  279.                 mysql_format(mysql_id, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Password`='%s'", inputtext);
  280.                 mysql_function_query(mysql_id, query, true, "@_LoadAccount", "i", playerid);
  281.             } else {
  282.                 SetPVarInt(playerid, "Wrong_Pass", GetPVarInt(playerid, "Wrong_Pass") + 1);
  283.                 SCM(playerid, -1, "You have entered the wrong password many times, so they were kicked.");
  284.                 Show_Login(playerid);
  285.                 if(GetPVarInt(playerid, "Wrong_Pass") >= 3)
  286.                     return Kick(playerid);
  287.             }
  288.             return true;
  289.         }
  290.         case D_SETTINGS: {
  291.             if(!response) return true;
  292.             switch(listitem) {
  293.                 case 0: {
  294.                     if(pInfo[playerid][Language] == 1)
  295.                         return SCM(playerid, -1, "Âû ñìåíèëè ÿçûê íà Àíãëèéñêèé.");
  296.                     else SCM(playerid, -1, "You changed your language to Russian.");
  297.                 }
  298.             }
  299.             pInfo[playerid][Language] = listitem+1;
  300.             return true;
  301.         }
  302.     }
  303.     return true;
  304. }
  305.  
  306. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  307. {
  308.     return true;
  309. }
  310.  
  311. // publics, forwards, stocks
  312.  
  313. @_FindPlayerInTable(playerid);
  314. @_FindPlayerInTable(playerid) {
  315.     new rows, fields;
  316.     cache_get_data(rows, fields);
  317.     if(!rows) ShowPlayerDialog(playerid, D_LANGUAGE, DIALOG_STYLE_LIST,
  318.         "Choose a language",
  319.         "1. Ðóññêèé\n2. English",
  320.         "Äàëåå", "Îòìåíà");
  321.     else {
  322.         cache_get_field_content(0, "Password", pInfo[playerid][Password], mysql_id, 24);
  323.         pInfo[playerid][Language] = cache_get_field_content_int(0, "Language", mysql_id);
  324.         Show_Login(playerid);
  325.     }
  326.     return true;
  327. }
  328.  
  329. Show_Register(playerid) {
  330.     if(pInfo[playerid][Language] == 1) {
  331.         ShowPlayerDialog(playerid, D_REG, DIALOG_STYLE_INPUT,
  332.             "Ðåãèñòðàöèÿ",
  333.             "Ââåäèòå âàø áóäóùèé ïàðîëü â îêíî íèæå",
  334.             "Äàëåå", "Îòìåíà");
  335.     } else {
  336.         ShowPlayerDialog(playerid, D_REG, DIALOG_STYLE_INPUT,
  337.             "Registration",
  338.             "Enter your future password in the window below",
  339.             "Next", "Exit");
  340.     }
  341.     return true;
  342. }
  343.  
  344. Show_Login(playerid) {
  345.     if(pInfo[playerid][Language] == 1) {
  346.         ShowPlayerDialog(playerid, D_LOGIN, DIALOG_STYLE_INPUT,
  347.             "Àâòîðèçàöèÿ",
  348.             "Ââåäèòå âàø ïàðîëü â îêíî íèæå",
  349.             "Äàëåå", "Îòìåíà");
  350.     } else {
  351.         ShowPlayerDialog(playerid, D_LOGIN, DIALOG_STYLE_INPUT,
  352.             "Authorization",
  353.             "Enter your password in the window below",
  354.             "Next", "Exit");
  355.     }
  356.     return true;
  357. }
  358.  
  359. @_LoadAccount(playerid);
  360. @_LoadAccount(playerid) {
  361.     pInfo[playerid][ID] = cache_get_field_content_int(0, "ID", mysql_id);
  362.     pInfo[playerid][Sex] = cache_get_field_content_int(0, "Sex", mysql_id);
  363.     pInfo[playerid][Skin] = cache_get_field_content_int(0, "Skin", mysql_id);
  364.     if(pInfo[playerid][Language] == 1)
  365.         return SCM(playerid, -1, "Âû óñïåøíî àâòîðèçîâàëèñü.");
  366.     else SCM(playerid, -1, "You have been successfully authorized.");
  367.     SetPVarInt(playerid, "Is_Authed", true);
  368.     DeletePVar(playerid, "Wrong_Pass");
  369.     SpawnPlayer(playerid);
  370.     return true;
  371. }
  372.  
  373. RemovePlayerInfo(playerid) {
  374.     pInfo[playerid][ID] = EOS; pInfo[playerid][Password] = EOS; pInfo[playerid][Language] = EOS; pInfo[playerid][Sex] = EOS; pInfo[playerid][Skin] = EOS;
  375. }
  376.  
  377. Show_Settings(playerid) {
  378.     if(pInfo[playerid][Language] == 1) {
  379.         static const frm_setting[] = "\
  380.             1. Ñìåíèòü ÿçûê [Ðóññêèé]";
  381.         new str_setting[sizeof(frm_setting)];
  382.         format(str_setting, sizeof(str_setting), frm_setting);
  383.         ShowPlayerDialog(playerid, D_SETTINGS, DIALOG_STYLE_LIST,
  384.             "Íàñòðîéêè",
  385.             str_setting,
  386.             "Âûáðàòü", "Îòìåíà");
  387.     } if(pInfo[playerid][Language] == 2) {
  388.         static const frm_setting[] = "\
  389.             1. Change language [English]";
  390.         new str_setting[sizeof(frm_setting)];
  391.         format(str_setting, sizeof(str_setting), frm_setting);
  392.         ShowPlayerDialog(playerid, D_SETTINGS, DIALOG_STYLE_LIST,
  393.             "Settings",
  394.             str_setting,
  395.             "Choose", "Cancel");
  396.     }
  397.     return true;
  398. }
  399.  
  400. CreateNewAccount(playerid) {
  401.     new query[107+MAX_PLAYER_NAME+24];
  402.     mysql_format(mysql_id, query, sizeof(query),
  403.     "INSERT INTO `accounts` (`Name`, `Password`, `Language`, `Sex`, `Skin`) VALUE ('%s', '%s', '%d', '%d', '%d')",
  404.     pInfo[playerid][Name], pInfo[playerid][Password], pInfo[playerid][Language], pInfo[playerid][Sex], pInfo[playerid][Skin]);
  405.     mysql_function_query(mysql_id, query, false, "", "");
  406.     SetPVarInt(playerid, "Is_Authed", true);
  407.     SpawnPlayer(playerid);
  408.     return true;
  409. }
  410.  
  411. // commands
  412.  
  413. cmd:settings(playerid, params[]) {
  414.     Show_Settings(playerid);
  415.     return true;
  416. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top