OKStyle

TextDraw Captcha

Mar 22nd, 2013
1,363
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <a_samp>
  2. // TextDraw Captcha by O.K.Style™
  3. new PlayerText:Captcha[40], TextArray[] = "1234567890QWERTYUIOPASDFGHJKLZXCVBNM";
  4. public OnPlayerConnect(playerid)
  5. {
  6.     for(new i = 0, cindex = 0; i < sizeof(Captcha); i++)
  7.     {
  8.         if(i == 0) Captcha[i] = CreatePlayerTextDraw(playerid, 269.0, 139.0, "Anti-bot captcha:");
  9.         if(i == 1)
  10.         {
  11.             new cstring[24];
  12.             format(cstring, sizeof(cstring), "%c%c%c%c%c", TextArray[random(sizeof(TextArray))], TextArray[random(sizeof(TextArray))], TextArray[random(sizeof(TextArray))], TextArray[random(sizeof(TextArray))], TextArray[random(sizeof(TextArray))]);
  13.             Captcha[i] = CreatePlayerTextDraw(playerid, 422.0, 139.0, cstring);
  14.             SetPVarString(playerid, "CaptchaCode", cstring);
  15.         }
  16.         if(i == 2) Captcha[i] = CreatePlayerTextDraw(playerid, 285.0, 174.0, "Please repeat:");
  17.         if(i == 3) Captcha[i] = CreatePlayerTextDraw(playerid, 427.0, 178.0, "-----");
  18.         if(i > 3)
  19.         {
  20.             new string[4];
  21.             format(string, sizeof(string), "%c", TextArray[i - 4]);
  22.             if(i >= 4) Captcha[i] = CreatePlayerTextDraw(playerid, 158.0 + (41.0 * cindex), 218.0, string);
  23.             if(i == 14) cindex = 0, Captcha[i] = CreatePlayerTextDraw(playerid, 158.0 + (41.0 * cindex), 259.0, string);
  24.             if(i > 14) Captcha[i] = CreatePlayerTextDraw(playerid, 158.0 + (41.0 * cindex), 259.0, string);
  25.             if(i == 24) cindex = 0, Captcha[i] = CreatePlayerTextDraw(playerid, 178.0 + (41.0 * cindex), 300.0, string);
  26.             if(i > 24) Captcha[i] = CreatePlayerTextDraw(playerid, 178.0 + (41.0 * cindex), 300.0, string);
  27.             if(i == 33) cindex = 0, Captcha[i] = CreatePlayerTextDraw(playerid, 220.0 + (41.0 * cindex), 341.0, string);
  28.             if(i > 33) Captcha[i] = CreatePlayerTextDraw(playerid, 220.0 + (41.0 * cindex), 341.0, string);
  29.             PlayerTextDrawUseBox(playerid, Captcha[i], 1);
  30.             PlayerTextDrawBoxColor(playerid, Captcha[i], 0x000000AA);
  31.             PlayerTextDrawTextSize(playerid, Captcha[i], 29.0, 29.0);
  32.             PlayerTextDrawSetSelectable(playerid, Captcha[i], 1);
  33.             cindex++;
  34.         }
  35.         PlayerTextDrawLetterSize(playerid, Captcha[i], 0.63, 3.4);
  36.         PlayerTextDrawAlignment(playerid, Captcha[i], 2);
  37.         PlayerTextDrawSetOutline(playerid, Captcha[i], 1);
  38.         PlayerTextDrawShow(playerid, Captcha[i]);
  39.         SelectTextDraw(playerid, 0xFDE39DFF);
  40.     }
  41.     return 1;
  42. }
  43. public OnPlayerClickTextDraw(playerid, Text:clickedid)
  44. {
  45.     if(!(_:clickedid ^ 0xFFFF)) return SelectTextDraw(playerid, 0xFDE39DFF);
  46.     return 1;
  47. }
  48. public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid)
  49. {
  50.     for(new i = 4; i < sizeof(Captcha); i++)
  51.     {
  52.         if(playertextid == Captcha[i])
  53.         {
  54.             new step = GetPVarInt(playerid, "CaptchaStep"), sstring[96];
  55.             GetPVarString(playerid, "CaptchaText", sstring, sizeof(sstring));
  56.             switch(step)
  57.             {
  58.                 case 0: format(sstring, sizeof(sstring), "%c", TextArray[i - 4]), strcat(sstring, "----"), SetPVarString(playerid, "CaptchaText", sstring);
  59.                 case 1: format(sstring, sizeof(sstring), "%s%c", sstring, TextArray[i - 4]), strdel(sstring, 1, 5), strcat(sstring, "---"), SetPVarString(playerid, "CaptchaText", sstring);
  60.                 case 2: format(sstring, sizeof(sstring), "%s%c", sstring, TextArray[i - 4]), strdel(sstring, 2, 5), strcat(sstring, "--"), SetPVarString(playerid, "CaptchaText", sstring);
  61.                 case 3: format(sstring, sizeof(sstring), "%s%c", sstring, TextArray[i - 4]), strdel(sstring, 3, 5), strcat(sstring, "-"), SetPVarString(playerid, "CaptchaText", sstring);
  62.                 case 4:
  63.                 {
  64.                     strdel(sstring, 4, 5);
  65.                     format(sstring, sizeof(sstring), "%s%c", sstring, TextArray[i - 4]);
  66.                     PlayerTextDrawSetString(playerid, Captcha[3], sstring);
  67.                     new cstring[24];
  68.                     GetPVarString(playerid, "CaptchaCode", cstring, sizeof(cstring));
  69.                     if(strcmp(cstring, sstring) != 0)
  70.                     {
  71.                         format(cstring, sizeof(cstring), "%c%c%c%c%c", TextArray[random(sizeof(TextArray) - 1)], TextArray[random(sizeof(TextArray) - 1)], TextArray[random(sizeof(TextArray) - 1)], TextArray[random(sizeof(TextArray) - 1)], TextArray[random(sizeof(TextArray) - 1)]);
  72.                         PlayerTextDrawSetString(playerid, Captcha[1], cstring);
  73.                         SetPVarString(playerid, "CaptchaCode", cstring);
  74.                         PlayerTextDrawSetString(playerid, Captcha[3], "-----");
  75.                         SendClientMessage(playerid, 0xFF0000FF, "Wrong anti-bot capthcha! Try again...");
  76.                         DeletePVar(playerid, "CaptchaStep");
  77.                         DeletePVar(playerid, "CaptchaText");
  78.                         return 1;
  79.                     }
  80.                     else
  81.                     {
  82.                         for(new l = 0; l < sizeof(Captcha); l++) PlayerTextDrawHide(playerid, Captcha[l]);
  83.                         DeletePVar(playerid, "CaptchaStep");
  84.                         DeletePVar(playerid, "CaptchaCode");
  85.                         DeletePVar(playerid, "CaptchaText");
  86.                         SetPVarInt(playerid, "CaptchaPass", 1);
  87.                         CancelSelectTextDraw(playerid);
  88.                         SendClientMessage(playerid, 0x00FF00FF, "OK! You are not a bot. Welcome!");
  89.                         return 1;
  90.                     }
  91.                 }
  92.             }
  93.             SetPVarInt(playerid, "CaptchaStep", step + 1);
  94.             PlayerTextDrawSetString(playerid, Captcha[3], sstring);
  95.         }
  96.     }
  97.     return 1;
  98. }
  99. public OnPlayerText(playerid, text[])
  100. {
  101.     if(GetPVarInt(playerid, "CaptchaPass") != 1) return 0;
  102.     return 1;
  103. }
  104. public OnPlayerCommandText(playerid, cmdtext[])
  105. {
  106.     if(GetPVarInt(playerid, "CaptchaPass") != 1) return 0;
  107.     return 1;
  108. }
  109. public OnPlayerRequestSpawn(playerid)
  110. {
  111.     if(GetPVarInt(playerid, "CaptchaPass") != 1) return 0;
  112.     return 1;
  113. }
  114. // etc.
RAW Paste Data