Advertisement
Guest User

Untitled

a guest
May 7th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.54 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. //dini Include by DracoBlue (version 1.6)
  4. #include <dini>
  5.  
  6.     /*---------------------------
  7.     28/6/09
  8.     Login / Register Menu Test
  9.     - Copyright (C) 2009 Zezombia
  10.    
  11.     Permissions:
  12.     Edit or/and Use
  13.     NOT FOR REDISTRIBUTION
  14.     ---------------------------*/
  15.    
  16. //PRESSING Define by Alex "Y_Less" Cole
  17. #define PRESSING(%0,%1) \
  18.     (((%0) & (%1)) == (%1))
  19.    
  20. enum pInfo
  21. {
  22.     menuing,
  23.     option,
  24.     logged,
  25.     username[16],
  26.     password[16]
  27. }
  28.  
  29. enum sInfo
  30. {
  31.     Text:box1,
  32.     Text:box2,
  33.     Text:box3,
  34.     Text:box4,
  35.     Text:box5
  36. }
  37.  
  38. new PlayerInfo[MAX_PLAYERS][pInfo];
  39. new ServerInfo[sInfo];
  40.  
  41. main()
  42. {
  43.     print(" 28/6/09");
  44.     print(" Login / Register Menu Test");
  45.     print(" - Copyright (C) 2009 Zezombia");
  46. }
  47.  
  48. public OnGameModeInit()
  49. {
  50.     SetGameModeText("Login / Register");
  51.     AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  52.    
  53.     ServerInfo[box1] = TextDrawCreate(310, 200, "~r~>Login<~n~~w~Register");
  54.     TextDrawUseBox(ServerInfo[box1], 1);
  55.     TextDrawBoxColor(ServerInfo[box1], 0x00000099);
  56.     TextDrawTextSize(ServerInfo[box1], 0.000000, 450.000000);
  57.     TextDrawAlignment(ServerInfo[box1], 2);
  58.     TextDrawFont(ServerInfo[box1], 2);
  59.     TextDrawSetOutline(ServerInfo[box1], 1);
  60.     TextDrawSetShadow(ServerInfo[box1], 0);
  61.     TextDrawLetterSize(ServerInfo[box1], 0.5, 1.75);
  62.  
  63.     ServerInfo[box2] = TextDrawCreate(310, 236, "~g~Shift: Up - Space: Down - Ctrl: Accept");
  64.     TextDrawUseBox(ServerInfo[box2], 1);
  65.     TextDrawBoxColor(ServerInfo[box2], 0x00000099);
  66.     TextDrawTextSize(ServerInfo[box2], 0.000000, 450.000000);
  67.     TextDrawAlignment(ServerInfo[box2], 2);
  68.     TextDrawFont(ServerInfo[box2], 2);
  69.     TextDrawSetOutline(ServerInfo[box2], 1);
  70.     TextDrawSetShadow(ServerInfo[box2], 0);
  71.  
  72.     ServerInfo[box3] = TextDrawCreate(310, 194, "~r~>Username:<~n~~w~Password:~n~~w~Login");
  73.     TextDrawUseBox(ServerInfo[box3], 1);
  74.     TextDrawBoxColor(ServerInfo[box3], 0x00000099);
  75.     TextDrawTextSize(ServerInfo[box3], 0.000000, 450.000000);
  76.     TextDrawAlignment(ServerInfo[box3], 2);
  77.     TextDrawFont(ServerInfo[box3], 2);
  78.     TextDrawSetOutline(ServerInfo[box3], 1);
  79.     TextDrawSetShadow(ServerInfo[box3], 0);
  80.     TextDrawLetterSize(ServerInfo[box3], 0.5, 1.75);
  81.  
  82.     ServerInfo[box4] = TextDrawCreate(310, 246, "~g~Shift: Up - Space: Down - Ctrl: Accept");
  83.     TextDrawUseBox(ServerInfo[box4], 1);
  84.     TextDrawBoxColor(ServerInfo[box4], 0x00000099);
  85.     TextDrawTextSize(ServerInfo[box4], 0.000000, 450.000000);
  86.     TextDrawAlignment(ServerInfo[box4], 2);
  87.     TextDrawFont(ServerInfo[box4], 2);
  88.     TextDrawSetOutline(ServerInfo[box4], 1);
  89.     TextDrawSetShadow(ServerInfo[box4], 0);
  90.  
  91.     ServerInfo[box5] = TextDrawCreate(310, 194, "~r~>Username:<~n~~w~Password:~n~~w~Register");
  92.     TextDrawUseBox(ServerInfo[box5], 1);
  93.     TextDrawBoxColor(ServerInfo[box5], 0x00000099);
  94.     TextDrawTextSize(ServerInfo[box5], 0.000000, 450.000000);
  95.     TextDrawAlignment(ServerInfo[box5], 2);
  96.     TextDrawFont(ServerInfo[box5], 2);
  97.     TextDrawSetOutline(ServerInfo[box5], 1);
  98.     TextDrawSetShadow(ServerInfo[box5], 0);
  99.     TextDrawLetterSize(ServerInfo[box5], 0.5, 1.75);
  100.     return 1;
  101. }
  102.  
  103. public OnPlayerRequestClass(playerid, classid)
  104. {
  105.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  106.     SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  107.     SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  108.     return 1;
  109. }
  110.  
  111. public OnPlayerConnect(playerid)
  112. {
  113.     PlayerInfo[playerid][menuing] = 0;
  114.     PlayerInfo[playerid][logged] = 0;
  115.     return 1;
  116. }
  117.  
  118. public OnPlayerText(playerid, text[])
  119. {
  120.     new string[128];
  121.  
  122.     if(PlayerInfo[playerid][menuing] > 1 && PlayerInfo[playerid][option] == 0)
  123.     {
  124.         if(strlen(text) > 12)
  125.         {
  126.             GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Username too long", 5000, 3);
  127.             return 0;
  128.         }
  129.        
  130.         if(strfind(text, "~", true) != -1)
  131.         {
  132.             GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Invalid charactors", 5000, 3);
  133.             return 0;
  134.         }
  135.  
  136.         format(PlayerInfo[playerid][username], sizeof(string), "%s", text);
  137.  
  138.         if(PlayerInfo[playerid][menuing] == 2)
  139.         {
  140.             format(string, sizeof(string), "~r~>Username: ~y~%s~r~<~n~~w~Password: ~g~%s~n~~w~Login", PlayerInfo[playerid][username], PlayerInfo[playerid][password]);
  141.  
  142.             TextDrawHideForPlayer(playerid, ServerInfo[box3]);
  143.             TextDrawSetString(ServerInfo[box3], string);
  144.             TextDrawShowForPlayer(playerid, ServerInfo[box3]);
  145.         }
  146.         else if(PlayerInfo[playerid][menuing] == 3)
  147.         {
  148.             format(string, sizeof(string), "~r~>Username: ~y~%s~r~<~n~~w~Password: ~g~%s~n~~w~Register", PlayerInfo[playerid][username], PlayerInfo[playerid][password]);
  149.  
  150.             TextDrawHideForPlayer(playerid, ServerInfo[box5]);
  151.             TextDrawSetString(ServerInfo[box5], string);
  152.             TextDrawShowForPlayer(playerid, ServerInfo[box5]);
  153.         }
  154.         return 0;
  155.     }
  156.  
  157.     if(PlayerInfo[playerid][menuing] > 1 && PlayerInfo[playerid][option] == 1)
  158.     {
  159.         if(strlen(text) > 12)
  160.         {
  161.             GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Password too long", 5000, 3);
  162.             return 0;
  163.         }
  164.        
  165.         if(strfind(text, "~", true) != -1)
  166.         {
  167.             GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Invalid charactors", 5000, 3);
  168.             return 0;
  169.         }
  170.  
  171.         format(PlayerInfo[playerid][password], sizeof(string), "%s", text);
  172.  
  173.         if(PlayerInfo[playerid][menuing] == 2)
  174.         {
  175.             format(string, sizeof(string), "~w~Username: ~g~%s~n~~r~>Password: ~y~%s~r~<~n~~w~Login", PlayerInfo[playerid][username], PlayerInfo[playerid][password]);
  176.  
  177.             TextDrawHideForPlayer(playerid, ServerInfo[box3]);
  178.             TextDrawSetString(ServerInfo[box3], string);
  179.             TextDrawShowForPlayer(playerid, ServerInfo[box3]);
  180.         }
  181.         else if(PlayerInfo[playerid][menuing] == 3)
  182.         {
  183.             format(string, sizeof(string), "~w~Username: ~g~%s~n~~r~>Password: ~y~%s~r~<~n~~w~Register", PlayerInfo[playerid][username], PlayerInfo[playerid][password]);
  184.  
  185.             TextDrawHideForPlayer(playerid, ServerInfo[box5]);
  186.             TextDrawSetString(ServerInfo[box5], string);
  187.             TextDrawShowForPlayer(playerid, ServerInfo[box5]);
  188.         }
  189.         return 0;
  190.     }
  191.  
  192.     if(PlayerInfo[playerid][menuing] > 0) return 0;
  193.     return 1;
  194. }
  195.  
  196. public OnPlayerCommandText(playerid, cmdtext[])
  197. {
  198.     if(strcmp(cmdtext, "/menu", true) == 0)
  199.     {
  200.         if(PlayerInfo[playerid][menuing] == 1) return 1;
  201.         if(PlayerInfo[playerid][logged] == 1) return GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~You are already logged in", 5000, 3);
  202.  
  203.         PlayerInfo[playerid][menuing] = 1;
  204.         PlayerInfo[playerid][option] = 0;
  205.         PlayerInfo[playerid][username] = EOS;
  206.         PlayerInfo[playerid][password] = EOS;
  207.        
  208.         TogglePlayerControllable(playerid, 0);
  209.         SetCameraBehindPlayer(playerid);
  210.        
  211.         TextDrawSetString(ServerInfo[box1], "~r~>Login<~n~~w~Register");
  212.        
  213.         TextDrawShowForPlayer(playerid, ServerInfo[box1]);
  214.         TextDrawShowForPlayer(playerid, ServerInfo[box2]);
  215.         return 1;
  216.     }
  217.    
  218.     if(strcmp(cmdtext, "/gmx", true) == 0)
  219.     {
  220.         TextDrawHideForAll(ServerInfo[box1]);
  221.         TextDrawHideForAll(ServerInfo[box2]);
  222.         TextDrawHideForAll(ServerInfo[box3]);
  223.         TextDrawHideForAll(ServerInfo[box4]);
  224.  
  225.         SendRconCommand("gmx");
  226.         return 1;
  227.     }
  228.    
  229.     if(strcmp(cmdtext, "/kill", true) == 0)
  230.     {
  231.         SetPlayerHealth(playerid, 0);
  232.         return 1;
  233.     }
  234.     return 0;
  235. }
  236.  
  237. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  238. {
  239.     new string[128];
  240.  
  241.     if(PlayerInfo[playerid][menuing] == 0) return 1;
  242.    
  243.     if(PlayerInfo[playerid][menuing] == 1)
  244.     {
  245.         if(PRESSING(newkeys, KEY_JUMP))
  246.         {
  247.             PlayerInfo[playerid][option] = 0;
  248.  
  249.             TextDrawHideForPlayer(playerid, ServerInfo[box1]);
  250.             TextDrawSetString(ServerInfo[box1], "~r~>Login<~n~~w~Register");
  251.             TextDrawShowForPlayer(playerid, ServerInfo[box1]);
  252.         }
  253.  
  254.         if(PRESSING(newkeys, KEY_SPRINT))
  255.         {
  256.             PlayerInfo[playerid][option] = 1;
  257.  
  258.             TextDrawHideForPlayer(playerid, ServerInfo[box1]);
  259.             TextDrawSetString(ServerInfo[box1], "~w~Login~n~~r~>Register<");
  260.             TextDrawShowForPlayer(playerid, ServerInfo[box1]);
  261.         }
  262.  
  263.         if(PRESSING(newkeys, KEY_FIRE))
  264.         {
  265.             TextDrawHideForPlayer(playerid, ServerInfo[box1]);
  266.             TextDrawHideForPlayer(playerid, ServerInfo[box2]);
  267.  
  268.             if(PlayerInfo[playerid][option] == 0)
  269.             {
  270.                 TextDrawSetString(ServerInfo[box3], "~r~>Username:<~n~~w~Password:~n~~w~Login");
  271.                 PlayerInfo[playerid][menuing] = 2;
  272.                 PlayerInfo[playerid][option] = 0;
  273.                
  274.                 TextDrawShowForPlayer(playerid, ServerInfo[box3]);
  275.                 TextDrawShowForPlayer(playerid, ServerInfo[box4]);
  276.             }
  277.            
  278.             if(PlayerInfo[playerid][option] == 1)
  279.             {
  280.                 TextDrawSetString(ServerInfo[box5], "~r~>Username:<~n~~w~Password:~n~~w~Register");
  281.                 PlayerInfo[playerid][menuing] = 3;
  282.                 PlayerInfo[playerid][option] = 0;
  283.  
  284.                 TextDrawShowForPlayer(playerid, ServerInfo[box5]);
  285.                 TextDrawShowForPlayer(playerid, ServerInfo[box4]);
  286.             }
  287.         }
  288.     }
  289.     else if(PlayerInfo[playerid][menuing] == 2)
  290.     {
  291.         if(PRESSING(newkeys, KEY_JUMP))
  292.         {
  293.             if(PlayerInfo[playerid][option] == 1 || PlayerInfo[playerid][option] == 0)
  294.             {
  295.                 PlayerInfo[playerid][option] = 0;
  296.                 format(string, sizeof(string), "~r~>Username: ~y~%s~r~<~n~~w~Password: ~g~%s~n~~w~Login", PlayerInfo[playerid][username], PlayerInfo[playerid][password]);
  297.            
  298.                 TextDrawHideForPlayer(playerid, ServerInfo[box3]);
  299.                 TextDrawSetString(ServerInfo[box3], string);
  300.                 TextDrawShowForPlayer(playerid, ServerInfo[box3]);
  301.             }
  302.             else if(PlayerInfo[playerid][option] == 2)
  303.             {
  304.                 PlayerInfo[playerid][option] = 1;
  305.                 format(string, sizeof(string), "~w~Username: ~g~%s~n~~r~>Password: ~y~%s~r~<~n~~w~Login", PlayerInfo[playerid][username], PlayerInfo[playerid][password]);
  306.  
  307.                 TextDrawHideForPlayer(playerid, ServerInfo[box3]);
  308.                 TextDrawSetString(ServerInfo[box3], string);
  309.                 TextDrawShowForPlayer(playerid, ServerInfo[box3]);
  310.             }
  311.         }
  312.  
  313.         if(PRESSING(newkeys, KEY_SPRINT))
  314.         {
  315.             if(PlayerInfo[playerid][option] == 0)
  316.             {
  317.                 PlayerInfo[playerid][option] = 1;
  318.                 format(string, sizeof(string), "~w~Username: ~g~%s~n~~r~>Password: ~y~%s~r~<~n~~w~Login", PlayerInfo[playerid][username], PlayerInfo[playerid][password]);
  319.  
  320.                 TextDrawHideForPlayer(playerid, ServerInfo[box3]);
  321.                 TextDrawSetString(ServerInfo[box3], string);
  322.                 TextDrawShowForPlayer(playerid, ServerInfo[box3]);
  323.             }
  324.             else if(PlayerInfo[playerid][option] == 1 || PlayerInfo[playerid][option] == 2)
  325.             {
  326.                 PlayerInfo[playerid][option] = 2;
  327.                 format(string, sizeof(string), "~w~Username: ~g~%s~n~~w~Password: ~g~%s~n~~r~>Login<", PlayerInfo[playerid][username], PlayerInfo[playerid][password]);
  328.  
  329.                 TextDrawHideForPlayer(playerid, ServerInfo[box3]);
  330.                 TextDrawSetString(ServerInfo[box3], string);
  331.                 TextDrawShowForPlayer(playerid, ServerInfo[box3]);
  332.             }
  333.         }
  334.  
  335.         if(PRESSING(newkeys, KEY_FIRE))
  336.         {
  337.             if(PlayerInfo[playerid][option] == 0) GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Press F6 and type in your username", 5000, 3);
  338.             if(PlayerInfo[playerid][option] == 1) GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Press F6 and type in your password", 5000, 3);
  339.  
  340.             if(PlayerInfo[playerid][option] == 2)
  341.             {
  342.                 PlayerInfo[playerid][menuing] = 0;
  343.                 TogglePlayerControllable(playerid, 1);
  344.  
  345.                 TextDrawHideForPlayer(playerid, ServerInfo[box3]);
  346.                 TextDrawHideForPlayer(playerid, ServerInfo[box4]);
  347.                
  348.                 if(strlen(PlayerInfo[playerid][username]) == 0 || strlen(PlayerInfo[playerid][password]) == 0) return GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Invalid Syntax", 5000, 3);
  349.                 if(dini_Exists(PlayerInfo[playerid][username]) == 0) return GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Account does not exist", 5000, 3);
  350.                 if(strcmp(PlayerInfo[playerid][password], dini_Get(PlayerInfo[playerid][username], "password"), true) != 0) return GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Invalid Password", 5000, 3);
  351.                
  352.                 PlayerInfo[playerid][logged] = 1;
  353.                 GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~You are now logged in", 5000, 3);
  354.             }
  355.         }
  356.     }
  357.     else if(PlayerInfo[playerid][menuing] == 3)
  358.     {
  359.         if(PRESSING(newkeys, KEY_JUMP))
  360.         {
  361.             if(PlayerInfo[playerid][option] == 1 || PlayerInfo[playerid][option] == 0)
  362.             {
  363.                 PlayerInfo[playerid][option] = 0;
  364.                 format(string, sizeof(string), "~r~>Username: ~y~%s~r~<~n~~w~Password: ~g~%s~n~~w~Register", PlayerInfo[playerid][username], PlayerInfo[playerid][password]);
  365.  
  366.                 TextDrawHideForPlayer(playerid, ServerInfo[box5]);
  367.                 TextDrawSetString(ServerInfo[box5], string);
  368.                 TextDrawShowForPlayer(playerid, ServerInfo[box5]);
  369.             }
  370.             else if(PlayerInfo[playerid][option] == 2)
  371.             {
  372.                 PlayerInfo[playerid][option] = 1;
  373.                 format(string, sizeof(string), "~w~Username: ~g~%s~n~~r~>Password: ~y~%s~r~<~n~~w~Register", PlayerInfo[playerid][username], PlayerInfo[playerid][password]);
  374.  
  375.                 TextDrawHideForPlayer(playerid, ServerInfo[box5]);
  376.                 TextDrawSetString(ServerInfo[box5], string);
  377.                 TextDrawShowForPlayer(playerid, ServerInfo[box5]);
  378.             }
  379.         }
  380.  
  381.         if(PRESSING(newkeys, KEY_SPRINT))
  382.         {
  383.             if(PlayerInfo[playerid][option] == 0)
  384.             {
  385.                 PlayerInfo[playerid][option] = 1;
  386.                 format(string, sizeof(string), "~w~Username: ~g~%s~n~~r~>Password: ~y~%s~r~<~n~~w~Register", PlayerInfo[playerid][username], PlayerInfo[playerid][password]);
  387.  
  388.                 TextDrawHideForPlayer(playerid, ServerInfo[box5]);
  389.                 TextDrawSetString(ServerInfo[box5], string);
  390.                 TextDrawShowForPlayer(playerid, ServerInfo[box5]);
  391.             }
  392.             else if(PlayerInfo[playerid][option] == 1 || PlayerInfo[playerid][option] == 2)
  393.             {
  394.                 PlayerInfo[playerid][option] = 2;
  395.                 format(string, sizeof(string), "~w~Username: ~g~%s~n~~w~Password: ~g~%s~n~~r~>Register<", PlayerInfo[playerid][username], PlayerInfo[playerid][password]);
  396.  
  397.                 TextDrawHideForPlayer(playerid, ServerInfo[box5]);
  398.                 TextDrawSetString(ServerInfo[box5], string);
  399.                 TextDrawShowForPlayer(playerid, ServerInfo[box5]);
  400.             }
  401.         }
  402.  
  403.         if(PRESSING(newkeys, KEY_FIRE))
  404.         {
  405.             if(PlayerInfo[playerid][option] == 0) GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Press F6 and type in your username", 5000, 3);
  406.             if(PlayerInfo[playerid][option] == 1) GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Press F6 and type in your password", 5000, 3);
  407.  
  408.             if(PlayerInfo[playerid][option] == 2)
  409.             {
  410.                 PlayerInfo[playerid][menuing] = 0;
  411.                 TogglePlayerControllable(playerid, 1);
  412.  
  413.                 TextDrawHideForPlayer(playerid, ServerInfo[box5]);
  414.                 TextDrawHideForPlayer(playerid, ServerInfo[box4]);
  415.                
  416.                 if(strlen(PlayerInfo[playerid][username]) == 0 || strlen(PlayerInfo[playerid][password]) == 0) return GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Invalid Syntax", 5000, 3);
  417.                 if(dini_Exists(PlayerInfo[playerid][username]) == 1) return GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Account already exists - Please choose a diffrent username", 5000, 3);
  418.  
  419.                 dini_Create(PlayerInfo[playerid][username]);
  420.                 dini_Set(PlayerInfo[playerid][username], "Password", PlayerInfo[playerid][password]);
  421.                 GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~w~Account created - You may now login", 5000, 3);
  422.             }
  423.         }
  424.     }
  425.     return 1;
  426. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement