Guest User

SA:MP - Scratch Card

a guest
Aug 14th, 2014
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 13.43 KB | None | 0 0
  1. /*==============================================================================
  2. |                                                                              |
  3. |                       Scratch Card by JIDAVID v1                     |
  4. |                           http://forum.sa-mp.com/                        |
  5. |                                                                              |
  6. ==============================================================================*/
  7.  
  8. #include <a_samp>
  9.  
  10. #define SLOTS           500     //SLOTS of your server
  11. #define DIALOG_CARD         7777        //Dialog ID
  12.  
  13. new Card[SLOTS];
  14. new LNumber1[SLOTS];
  15. new LNumber2[SLOTS];
  16. new LNumber3[SLOTS];
  17. new LTimer1[SLOTS];
  18. new LTimer2[SLOTS];
  19. new LTimer3[SLOTS];
  20. new bool:CActive[SLOTS];
  21. new bool:ActivedCard[SLOTS];
  22. new bool:Spawned[SLOTS];
  23.  
  24. new Text:TextCard0;
  25. new Text:TextCard1;
  26. new Text:TextCard2;
  27. new Text:TextCard3;
  28. new Text:TextCard4;
  29. new Text:ScratchArea1[SLOTS];
  30. new Text:ScratchArea2[SLOTS];
  31. new Text:ScratchArea3[SLOTS];
  32. new Text:TextCard5;
  33. new Text:TextCard6;
  34.  
  35. forward ShowNumber2(playerid);
  36. forward ShowNumber3(playerid);
  37. forward HideCard(playerid);
  38.  
  39. public OnFilterScriptInit()
  40. {
  41.     TextCard0 = TextDrawCreate(297.000000, 332.000000, "_");
  42.     TextDrawAlignment(TextCard0, 2);
  43.     TextDrawBackgroundColor(TextCard0, -65281);
  44.     TextDrawFont(TextCard0, 1);
  45.     TextDrawLetterSize(TextCard0, 0.500000, 9.799998);
  46.     TextDrawColor(TextCard0, -65281);
  47.     TextDrawSetOutline(TextCard0, 0);
  48.     TextDrawSetProportional(TextCard0, 1);
  49.     TextDrawSetShadow(TextCard0, 1);
  50.     TextDrawUseBox(TextCard0, 1);
  51.     TextDrawBoxColor(TextCard0, -5614081);
  52.     TextDrawTextSize(TextCard0, 0.000000, 150.000000);
  53.  
  54.     TextCard1 = TextDrawCreate(399.000000, 379.000000, "_");
  55.     TextDrawAlignment(TextCard1, 2);
  56.     TextDrawBackgroundColor(TextCard1, -65281);
  57.     TextDrawFont(TextCard1, 1);
  58.     TextDrawLetterSize(TextCard1, 0.500000, 4.600000);
  59.     TextDrawColor(TextCard1, -65281);
  60.     TextDrawSetOutline(TextCard1, 0);
  61.     TextDrawSetProportional(TextCard1, 1);
  62.     TextDrawSetShadow(TextCard1, 1);
  63.     TextDrawUseBox(TextCard1, 1);
  64.     TextDrawBoxColor(TextCard1, -1061109505);
  65.     TextDrawTextSize(TextCard1, 0.000000, -51.000000);
  66.  
  67.     TextCard2 = TextDrawCreate(378.000000, 380.000000, "1 = 1 000$ ~n~5 = 5 000$ ~n~10 = 10 000$ ~n~25 = 25 000$ ~n~50 = 50 000$");
  68.     TextDrawBackgroundColor(TextCard2, 255);
  69.     TextDrawFont(TextCard2, 1);
  70.     TextDrawLetterSize(TextCard2, 0.160000, 0.900000);
  71.     TextDrawColor(TextCard2, 16711935);
  72.     TextDrawSetOutline(TextCard2, 1);
  73.     TextDrawSetProportional(TextCard2, 1);
  74.  
  75.     TextCard3 = TextDrawCreate(399.000000, 362.000000, "Prices");
  76.     TextDrawAlignment(TextCard3, 2);
  77.     TextDrawBackgroundColor(TextCard3, 255);
  78.     TextDrawFont(TextCard3, 0);
  79.     TextDrawLetterSize(TextCard3, 0.500000, 1.400000);
  80.     TextDrawColor(TextCard3, -1);
  81.     TextDrawSetOutline(TextCard3, 1);
  82.     TextDrawSetProportional(TextCard3, 1);
  83.     TextDrawUseBox(TextCard3, 1);
  84.     TextDrawBoxColor(TextCard3, -8388353);
  85.     TextDrawTextSize(TextCard3, 0.000000, -51.000000);
  86.  
  87.     TextCard4 = TextDrawCreate(252.000000, 334.000000, "Lottery San Andreas");
  88.     TextDrawBackgroundColor(TextCard4, 255);
  89.     TextDrawFont(TextCard4, 0);
  90.     TextDrawLetterSize(TextCard4, 0.390000, 1.100000);
  91.     TextDrawColor(TextCard4, -8388353);
  92.     TextDrawSetOutline(TextCard4, 1);
  93.     TextDrawSetProportional(TextCard4, 1);
  94.  
  95.     for(new i=0; i<SLOTS; i++)
  96.     {
  97.     ScratchArea1[i] = TextDrawCreate(255.000000, 390.000000, "_");
  98.     TextDrawAlignment(ScratchArea1[i], 2);
  99.     TextDrawBackgroundColor(ScratchArea1[i], 255);
  100.     TextDrawFont(ScratchArea1[i], 1);
  101.     TextDrawLetterSize(ScratchArea1[i], 0.500000, 2.600000);
  102.     TextDrawColor(ScratchArea1[i], -1);
  103.     TextDrawSetOutline(ScratchArea1[i], 1);
  104.     TextDrawSetProportional(ScratchArea1[i], 1);
  105.     TextDrawUseBox(ScratchArea1[i], 1);
  106.     TextDrawBoxColor(ScratchArea1[i], -8388353);
  107.     TextDrawTextSize(ScratchArea1[i], 0.000000, -33.000000);
  108.     TextDrawSetSelectable(ScratchArea1[i], 0);
  109.     }
  110.  
  111.     for(new i=0; i<SLOTS; i++)
  112.     {
  113.     ScratchArea2[i] = TextDrawCreate(297.000000, 390.000000, "_");
  114.     TextDrawAlignment(ScratchArea2[i], 2);
  115.     TextDrawBackgroundColor(ScratchArea2[i], 255);
  116.     TextDrawFont(ScratchArea2[i], 1);
  117.     TextDrawLetterSize(ScratchArea2[i], 0.500000, 2.600000);
  118.     TextDrawColor(ScratchArea2[i], -1);
  119.     TextDrawSetOutline(ScratchArea2[i], 1);
  120.     TextDrawSetProportional(ScratchArea2[i], 1);
  121.     TextDrawUseBox(ScratchArea2[i], 1);
  122.     TextDrawBoxColor(ScratchArea2[i], -8388353);
  123.     TextDrawTextSize(ScratchArea2[i], 0.000000, -33.000000);
  124.     TextDrawSetSelectable(ScratchArea2[i], 0);
  125.     }
  126.  
  127.     for(new i=0; i<SLOTS; i++)
  128.     {
  129.     ScratchArea3[i] = TextDrawCreate(340.000000, 390.000000, "_");
  130.     TextDrawAlignment(ScratchArea3[i], 2);
  131.     TextDrawBackgroundColor(ScratchArea3[i], 255);
  132.     TextDrawFont(ScratchArea3[i], 1);
  133.     TextDrawLetterSize(ScratchArea3[i], 0.500000, 2.600000);
  134.     TextDrawColor(ScratchArea3[i], -1);
  135.     TextDrawSetOutline(ScratchArea3[i], 1);
  136.     TextDrawSetProportional(ScratchArea3[i], 1);
  137.     TextDrawUseBox(ScratchArea3[i], 1);
  138.     TextDrawBoxColor(ScratchArea3[i], -8388353);
  139.     TextDrawTextSize(ScratchArea3[i], 0.000000, -33.000000);
  140.     TextDrawSetSelectable(ScratchArea3[i], 0);
  141.     }
  142.  
  143.     TextCard5 = TextDrawCreate(238.000000, 351.000000, "Click to START. ~n~3 same numbers is win.");
  144.     TextDrawBackgroundColor(TextCard5, 65535);
  145.     TextDrawFont(TextCard5, 1);
  146.     TextDrawLetterSize(TextCard5, 0.220000, 0.899999);
  147.     TextDrawColor(TextCard5, -1);
  148.     TextDrawSetOutline(TextCard5, 1);
  149.     TextDrawSetProportional(TextCard5, 1);
  150.  
  151.     TextCard6 = TextDrawCreate(297.500000, 373.000000, "START");
  152.     TextDrawAlignment(TextCard6, 2);
  153.     TextDrawBackgroundColor(TextCard6, 0x000000FF);
  154.     TextDrawFont(TextCard6, 1);
  155.     TextDrawLetterSize(TextCard6, 0.330000, 1.000000);
  156.     TextDrawColor(TextCard6, 0xFF0000FF);
  157.     TextDrawSetOutline(TextCard6, 1);
  158.     TextDrawSetProportional(TextCard6, 1);
  159.     TextDrawSetSelectable(TextCard6, 1);
  160.     return 1;
  161. }
  162.  
  163. public OnFilterScriptExit()
  164. {
  165.     return 1;
  166. }
  167.  
  168. public OnPlayerConnect(playerid)
  169. {
  170.     Card[playerid] = 0;
  171.     LNumber1[playerid] = 0;
  172.     LNumber2[playerid] = 0;
  173.     LNumber3[playerid] = 0;
  174.     CActive[playerid] = false;
  175.     ActivedCard[playerid] = false;
  176.     Spawned[playerid] = false;
  177.     return 1;
  178. }
  179.  
  180. public OnPlayerDisconnect(playerid, reason)
  181. {
  182.     Card[playerid] = 0;
  183.     LNumber1[playerid] = 0;
  184.     LNumber2[playerid] = 0;
  185.     LNumber3[playerid] = 0;
  186.     CActive[playerid] = false;
  187.     ActivedCard[playerid] = false;
  188.     Spawned[playerid] = false;
  189.     return 1;
  190. }
  191.  
  192. public OnPlayerSpawn(playerid)
  193. {
  194.     Spawned[playerid] = true;
  195.     if(CActive[playerid] == true)
  196.     {
  197.         TextDrawHideForPlayer(playerid, TextCard0);
  198.         TextDrawHideForPlayer(playerid, TextCard1);
  199.         TextDrawHideForPlayer(playerid, TextCard2);
  200.         TextDrawHideForPlayer(playerid, TextCard3);
  201.         TextDrawHideForPlayer(playerid, TextCard4);
  202.         TextDrawHideForPlayer(playerid, TextCard5);
  203.         TextDrawHideForPlayer(playerid, ScratchArea1[playerid]);
  204.         TextDrawHideForPlayer(playerid, ScratchArea2[playerid]);
  205.         TextDrawHideForPlayer(playerid, ScratchArea3[playerid]);
  206.         CActive[playerid] = false;
  207.     }
  208.  
  209.     CancelSelectTextDraw(playerid);
  210.     return 1;
  211. }
  212.  
  213. public OnPlayerDeath(playerid, killerid, reason)
  214. {
  215.     Spawned[playerid] = false;
  216.     return 1;
  217. }
  218.  
  219. public OnPlayerCommandText(playerid, cmdtext[])
  220. {
  221.     if(strcmp("/scratchcard", cmdtext, true, 12) == 0)
  222.     {
  223.     if(CActive[playerid] == true) return SendClientMessage(playerid, 0xFF0000FF, "[ ! ] {FFFFFF}You can scratching only one card now!");
  224.     if(Card[playerid] < 1) return SendClientMessage(playerid, 0xFF0000FF, "[ ! ] {FFFFFF}You don't have scratch card!");
  225.     if(Spawned[playerid] == false) return SendClientMessage(playerid, 0xFF0000FF, "[ ! ] {FFFFFF}You must be in game!");
  226.  
  227.     new string[128];
  228.     format(string, sizeof string, "{FFFFFF}Are you sure, you want to scratch your card? \nYou own {FF8000}%d {FFFFFF}scratch cards.", Card[playerid]);
  229.     ShowPlayerDialog(playerid, DIALOG_CARD, DIALOG_STYLE_MSGBOX, "{FF8000}Scratch card by JIDAVID", string, "Scratch", "Cancel");
  230.     return 1;
  231.     }
  232.    
  233.     if(strcmp("/buycard", cmdtext, true, 8) == 0)
  234.     {
  235.     if(GetPlayerMoney(playerid) < 3000) return SendClientMessage(playerid, 0xFF0000FF, "[ ! ] {FFFFFF}You don't have 3000$ to buy scratch card!");
  236.     GivePlayerMoney(playerid, -3000);
  237.    
  238.     Card[playerid] ++;
  239.     SendClientMessage(playerid, 0x00FF00FF, "[ ! ] {FFFFFF}You have successfully bought scratch card for 3000$!");
  240.     return 1;
  241.     }
  242.     return 0;
  243. }
  244.  
  245. public OnPlayerClickTextDraw(playerid, Text:clickedid)
  246. {
  247.     if(clickedid == TextCard6)
  248.     {
  249.     if(ActivedCard[playerid] == true)
  250.     {
  251.     TextDrawSetSelectable(TextCard6, 0);
  252.     TextDrawHideForPlayer(playerid, TextCard6);
  253.    
  254.     ActivedCard[playerid] = false;
  255.  
  256.     new RCislo = random(5);
  257.     if(RCislo == 0){ LNumber1[playerid] = 1; }
  258.     else if(RCislo == 1){ LNumber1[playerid] = 5; }
  259.     else if(RCislo == 2){ LNumber1[playerid] = 10; }
  260.     else if(RCislo == 3){ LNumber1[playerid] = 25; }
  261.     else if(RCislo == 4){ LNumber1[playerid] = 50; }
  262.  
  263.     TextDrawHideForPlayer(playerid, ScratchArea1[playerid]);
  264.     new la[50];
  265.     format(la, sizeof la, "%d", LNumber1[playerid]);
  266.     TextDrawSetString(ScratchArea1[playerid], la);
  267.     TextDrawShowForPlayer(playerid, ScratchArea1[playerid]);
  268.  
  269.     new Float:X, Float:Y, Float:Z;
  270.     GetPlayerPos(playerid, X, Y, Z);
  271.     PlayerPlaySound(playerid, 1056, X, Y, Z);
  272.  
  273.     LTimer1[playerid] = SetTimerEx("ShowNumber2", 1000, 0, "i", playerid);
  274.     LTimer2[playerid] = SetTimerEx("ShowNumber3", 2000, 0, "i", playerid);
  275.     LTimer3[playerid] = SetTimerEx("HideCard", 3500, 0, "i", playerid);
  276.     }
  277.     }
  278.  
  279.     if(_:clickedid == INVALID_TEXT_DRAW)
  280.     {
  281.         if(CActive[playerid] == true)
  282.         {
  283.         KillTimer(LTimer1[playerid]), KillTimer(LTimer2[playerid]), KillTimer(LTimer3[playerid]);
  284.         TextDrawHideForPlayer(playerid, TextCard0);
  285.         TextDrawHideForPlayer(playerid, TextCard1);
  286.         TextDrawHideForPlayer(playerid, TextCard2);
  287.         TextDrawHideForPlayer(playerid, TextCard3);
  288.         TextDrawHideForPlayer(playerid, TextCard4);
  289.         TextDrawHideForPlayer(playerid, TextCard5);
  290.         TextDrawHideForPlayer(playerid, TextCard6);
  291.         TextDrawHideForPlayer(playerid, ScratchArea1[playerid]);
  292.         TextDrawHideForPlayer(playerid, ScratchArea2[playerid]);
  293.         TextDrawHideForPlayer(playerid, ScratchArea3[playerid]);
  294.         CActive[playerid] = false;
  295.         ActivedCard[playerid] = false;
  296.         }
  297.     }
  298.     return 1;
  299. }
  300.  
  301. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  302. {
  303.     if(dialogid == DIALOG_CARD)
  304.     {
  305.     if(response == 1)
  306.     {
  307.         Card[playerid] --;
  308.         TextDrawSetString(ScratchArea1[playerid], "_");
  309.         TextDrawSetString(ScratchArea2[playerid], "_");
  310.         TextDrawSetString(ScratchArea3[playerid], "_");
  311.         TextDrawSetSelectable(TextCard6, 1);
  312.         TextDrawShowForPlayer(playerid, TextCard0);
  313.         TextDrawShowForPlayer(playerid, TextCard1);
  314.         TextDrawShowForPlayer(playerid, TextCard2);
  315.         TextDrawShowForPlayer(playerid, TextCard3);
  316.         TextDrawShowForPlayer(playerid, TextCard4);
  317.         TextDrawShowForPlayer(playerid, TextCard5);
  318.         TextDrawShowForPlayer(playerid, TextCard6);
  319.         TextDrawShowForPlayer(playerid, ScratchArea1[playerid]);
  320.         TextDrawShowForPlayer(playerid, ScratchArea2[playerid]);
  321.         TextDrawShowForPlayer(playerid, ScratchArea3[playerid]);
  322.         SelectTextDraw(playerid, 0x00FF00FF);
  323.         CActive[playerid] = true;
  324.         ActivedCard[playerid] = true;
  325.     }
  326.     }
  327.     return 1;
  328. }
  329.  
  330. public HideCard(playerid)
  331. {
  332.     TextDrawHideForPlayer(playerid, TextCard0);
  333.     TextDrawHideForPlayer(playerid, TextCard1);
  334.     TextDrawHideForPlayer(playerid, TextCard2);
  335.     TextDrawHideForPlayer(playerid, TextCard3);
  336.     TextDrawHideForPlayer(playerid, TextCard4);
  337.     TextDrawHideForPlayer(playerid, TextCard5);
  338.     TextDrawHideForPlayer(playerid, TextCard6);
  339.     TextDrawHideForPlayer(playerid, ScratchArea1[playerid]);
  340.     TextDrawHideForPlayer(playerid, ScratchArea2[playerid]);
  341.     TextDrawHideForPlayer(playerid, ScratchArea3[playerid]);
  342.     CActive[playerid] = false;
  343.     CancelSelectTextDraw(playerid);
  344. }
  345.  
  346. public ShowNumber2(playerid)
  347. {
  348.     new QRCislo = random(5);
  349.     if(QRCislo == 0){ LNumber2[playerid] = 1; }
  350.     else if(QRCislo == 1){ LNumber2[playerid] = 5; }
  351.     else if(QRCislo == 2){ LNumber2[playerid] = 10; }
  352.     else if(QRCislo == 3){ LNumber2[playerid] = 25; }
  353.     else if(QRCislo == 4){ LNumber2[playerid] = 50; }
  354.  
  355.     new Float:X, Float:Y, Float:Z;
  356.     GetPlayerPos(playerid, X, Y, Z);
  357.  
  358.     TextDrawHideForPlayer(playerid, ScratchArea2[playerid]);
  359.     new string[6];
  360.     format(string, sizeof string, "%d", LNumber2[playerid]);
  361.     TextDrawSetString(ScratchArea2[playerid], string);
  362.     TextDrawShowForPlayer(playerid, ScratchArea2[playerid]);
  363.  
  364.     PlayerPlaySound(playerid, 1056, X, Y, Z);
  365. }
  366.  
  367. public ShowNumber3(playerid)
  368. {
  369.     new QQRCislo = random(5);
  370.     if(QQRCislo == 0){ LNumber3[playerid] = 1; }
  371.     else if(QQRCislo == 1){ LNumber3[playerid] = 5; }
  372.     else if(QQRCislo == 2){ LNumber3[playerid] = 10; }
  373.     else if(QQRCislo == 3){ LNumber3[playerid] = 25; }
  374.     else if(QQRCislo == 4){ LNumber3[playerid] = 50; }
  375.  
  376.     TextDrawHideForPlayer(playerid, ScratchArea3[playerid]);
  377.     new string1[6];
  378.     format(string1, sizeof string1, "%d", LNumber3[playerid]);
  379.     TextDrawSetString(ScratchArea3[playerid], string1);
  380.     TextDrawShowForPlayer(playerid, ScratchArea3[playerid]);
  381.  
  382.     new Float:X, Float:Y, Float:Z;
  383.     GetPlayerPos(playerid, X, Y, Z);
  384.  
  385.     if(LNumber1[playerid] == LNumber2[playerid] && LNumber2[playerid] == LNumber3[playerid] && LNumber3[playerid] == LNumber1[playerid])
  386.     {
  387.     new x = LNumber1[playerid]*1000;
  388.  
  389.     new string[30];
  390.     GivePlayerMoney(playerid, x);
  391.     format(string, sizeof string, "You won ~n~~g~~h~%d$ !", x);
  392.     GameTextForPlayer(playerid, string, 4000, 4);
  393.     PlayerPlaySound(playerid, 1057, X, Y, Z);
  394.     }
  395.     else
  396.     {
  397.     PlayerPlaySound(playerid, 1055, X, Y, Z);
  398.     GameTextForPlayer(playerid, "~r~~h~You lose!", 3000, 4);
  399.     }
  400. }
Advertisement
Add Comment
Please, Sign In to add comment