Zsolesszka

[FS]Poker SA-MP 0.3e RC4

Mar 20th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 24.42 KB | None | 0 0
  1. // http://forum.sa-mp.com/showpost.php?p=1653624&postcount=1
  2. /*
  3.     Poker filterscript by.: Zsolesszka
  4.     2012.01.15 - 2012.01.27
  5. -   Update Poker [FS] 2012.03.20 Beta version
  6.    
  7.         samp 0.3e RC4 use new function
  8.         native TextDrawSetSelectable(Text:text, set); // the default is 0 (non-selectable)
  9.         native SelectTextDraw(playerid, hovercolor); // enables the mouse so the player can select a textdraw
  10.         native CancelSelectTextDraw(playerid);  // cancel textdraw selection with the mouse
  11.         forward OnPlayerClickTextDraw(playerid, Text:clickedid);
  12.        
  13.     Thank you SA-MP team.
  14. */
  15.  
  16. #include <a_samp>
  17.  
  18. enum
  19. {
  20.     TWO = 2,
  21.     THREE,
  22.     FOUR,
  23.     FIVE,
  24.     SIX,
  25.     SEVEN,
  26.     EIGHT,
  27.     NINE,
  28.     TEN,
  29.     JACK,
  30.     QUEEN,
  31.     KING,
  32.     ACE
  33. };
  34.  
  35. enum
  36. {
  37.     HIGH_CARD = 0,
  38.     ONE_PAIR,
  39.     TWO_PAIR,
  40.     THREE_OF_A_KIND,
  41.     STRAIGHT,
  42.     FLUSH,
  43.     FULL_HOUSE,
  44.     FOUR_OF_A_KIND,
  45.     STRAIGHT_FLUSH,
  46.     ROYAL_FLUSH
  47. };
  48.  
  49. new
  50.     rang_sor[][] =
  51. {
  52.     {"High card"},
  53.     {"One Pair"},
  54.     {"Two Pair"},
  55.     {"Three of a Kind"},
  56.     {"Straight"},
  57.     {"Flush"},
  58.     {"Full house"},
  59.     {"Four of Kind"},
  60.     {"Straight Flush"},
  61.     {"Royal Flush"}
  62. };
  63.  
  64. new
  65.     LD_POKE[][] =
  66. {
  67.     { "LD_POKE:cd2c" },
  68.     { "LD_POKE:cd3c" },
  69.     { "LD_POKE:cd4c" },
  70.     { "LD_POKE:cd5c" },
  71.     { "LD_POKE:cd6c" },
  72.     { "LD_POKE:cd7c" },
  73.     { "LD_POKE:cd8c" },
  74.     { "LD_POKE:cd9c" },
  75.     { "LD_POKE:cd10c" },
  76.     { "LD_POKE:cd11c" },
  77.     { "LD_POKE:cd12c" },
  78.     { "LD_POKE:cd13c" },
  79.     { "LD_POKE:cd1c" },
  80.  
  81.     { "LD_POKE:cd2d" },
  82.     { "LD_POKE:cd3d" },
  83.     { "LD_POKE:cd4d" },
  84.     { "LD_POKE:cd5d" },
  85.     { "LD_POKE:cd6d" },
  86.     { "LD_POKE:cd7d" },
  87.     { "LD_POKE:cd8d" },
  88.     { "LD_POKE:cd9d" },
  89.     { "LD_POKE:cd10d" },
  90.     { "LD_POKE:cd11d" },
  91.     { "LD_POKE:cd12d" },
  92.     { "LD_POKE:cd13d" },
  93.     { "LD_POKE:cd1d" },
  94.  
  95.     { "LD_POKE:cd2h" },
  96.     { "LD_POKE:cd3h" },
  97.     { "LD_POKE:cd4h" },
  98.     { "LD_POKE:cd5h" },
  99.     { "LD_POKE:cd6h" },
  100.     { "LD_POKE:cd7h" },
  101.     { "LD_POKE:cd8h" },
  102.     { "LD_POKE:cd9h" },
  103.     { "LD_POKE:cd10h" },
  104.     { "LD_POKE:cd11h" },
  105.     { "LD_POKE:cd12h" },
  106.     { "LD_POKE:cd13h" },
  107.     { "LD_POKE:cd1h" },
  108.  
  109.     { "LD_POKE:cd2s" },
  110.     { "LD_POKE:cd3s" },
  111.     { "LD_POKE:cd4s" },
  112.     { "LD_POKE:cd5s" },
  113.     { "LD_POKE:cd6s" },
  114.     { "LD_POKE:cd7s" },
  115.     { "LD_POKE:cd8s" },
  116.     { "LD_POKE:cd9s" },
  117.     { "LD_POKE:cd10s" },
  118.     { "LD_POKE:cd11s" },
  119.     { "LD_POKE:cd12s" },
  120.     { "LD_POKE:cd13s" },
  121.     { "LD_POKE:cd1s" }
  122. };
  123.  
  124. stock
  125.     HoldCardName[][] =
  126. {
  127.     { "{e00909}holdon" },
  128.     { "{9c8c8c}holdoff" }
  129. };
  130.  
  131. new
  132.     HoldCardText[][] =
  133. {
  134.     { "LD_POKE:holdon" },
  135.     { "LD_POKE:holdoff" },
  136.     { "LD_POKE:holdmid" }
  137. };
  138.  
  139. stock
  140.     BackGroundData[][] =
  141. {
  142.     { "LOADSUK:loadscuk" },
  143.     { "LOADSUK:loadsc9" },
  144.     { "LOADSUK:loadsc8" },
  145.     { "LOADSUK:loadsc7" },
  146.     { "LOADSUK:loadsc6" },
  147.     { "LOADSUK:loadsc5" },
  148.     { "LOADSUK:loadsc4" },
  149.     { "LOADSUK:loadsc3" },
  150.     { "LOADSUK:loadsc2" },
  151.     { "LOADSUK:loadsc14" },
  152.     { "LOADSUK:loadsc13" },
  153.     { "LOADSUK:loadsc12" },
  154.     { "LOADSUK:loadsc11" },
  155.     { "LOADSUK:loadsc10" },
  156.     { "LOADSUK:loadsc1" }
  157. };
  158.  
  159. stock
  160.     Card_Name[][] =
  161. {
  162.     "2c", "3c", "4c", "5c", "6c", "7c", "8c", "9c", "Tc", "Jc", "Qc", "Kc", "Ac",
  163.     "2d", "3d", "4d", "5d", "6d", "7d", "8d", "9d", "Td", "Jd", "Qd", "Kd", "Ad",
  164.     "2h", "3h", "4h", "5h", "6h", "7h", "8h", "9h", "Th", "Jh", "Qh", "Kh", "Ah",
  165.     "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "Ts", "Js", "Qs", "Ks", "As"
  166. };
  167.  
  168. new
  169.     Card_Value[] =
  170. {
  171.     TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE,
  172.     TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE,
  173.     TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE,
  174.     TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE
  175. };
  176.  
  177. new
  178.     Bynary_Mask[] =
  179. {
  180.     1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000,
  181.     1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000,
  182.     1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000,
  183.     1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000
  184. //      2   3   4   5   6   7   8   9   T   J   Q   K   A
  185. };
  186.  
  187. #define TREFF       0b1 //1 // "clubs"
  188. #define KARO        0b10 //2 // “diamonds”
  189. #define KOR         0b100 //4 // “hearts”
  190. #define PIKK        0b1000 //8 // “spades” or “shields”
  191.  
  192. new
  193.     Color_Mask[] =
  194. {
  195.     TREFF, TREFF, TREFF, TREFF, TREFF, TREFF, TREFF, TREFF, TREFF, TREFF, TREFF, TREFF, TREFF,  // 1 = 0b10
  196.     KARO, KARO, KARO, KARO, KARO, KARO, KARO, KARO, KARO, KARO, KARO, KARO, KARO,       // 2 = 0b100
  197.     KOR, KOR, KOR, KOR, KOR, KOR, KOR, KOR, KOR, KOR, KOR, KOR, KOR,                        // 4 = 0b1000
  198.     PIKK, PIKK, PIKK, PIKK, PIKK, PIKK, PIKK, PIKK, PIKK, PIKK, PIKK, PIKK, PIKK                    // 8 = 0b10000
  199. };
  200.  
  201. new
  202.     pot[] = { 0, 0, 2, 3, 4, 5, 7, 20, 50, 250 };
  203.  
  204. new
  205.     Text:BackGroundText[MAX_PLAYERS],
  206.     Text:CardsText[MAX_PLAYERS][6],
  207.     Text:HoldsText[MAX_PLAYERS][5],
  208.     Text:WinText[MAX_PLAYERS],
  209.     Text:BetCreditText[MAX_PLAYERS];
  210.  
  211. #define MIN_BET 5   // $5
  212. #define MAX_BET 100 // $100
  213.  
  214. #define FIRST_DIVID     (false) // enable hold card
  215. #define SECOND_DIVID    (true)  // disable hold card
  216. #define HOLDON      (false)
  217. #define HOLDOFF (true) // Not modified
  218.  
  219. forward TextDrawDizajn(playerid, index);
  220. forward TextDrawDizajn2(playerid, win, One_pair, Two_pair);
  221.  
  222. enum
  223.     Poker_PlayerInfoEnum
  224. {
  225.     bool:PokerAktive,
  226.     fivecards_hand[10],
  227.     bool:holdstate[5],
  228.     bool:hold,
  229.     Bet,
  230.     Credit
  231. };
  232.  
  233. new
  234.     PP_Info[MAX_PLAYERS][Poker_PlayerInfoEnum];
  235.  
  236. public
  237.     OnFilterScriptInit()
  238. {
  239.     print("\nPoker filterscript loaded.\n\t * * * Created by Zsolesszka * * *\n");
  240.     return 1;
  241. }
  242.  
  243. public
  244.     OnFilterScriptExit()
  245. {
  246.     for(new i; i < MAX_PLAYERS; i++)
  247.     {
  248.         if(BackGroundText[i] != Text:INVALID_TEXT_DRAW)
  249.         {  
  250.             Delete_PokerTextDraw(i);
  251.         }
  252.     }
  253.     return 1;
  254. }
  255.  
  256. public
  257.     OnPlayerConnect(playerid)
  258. {
  259.     BackGroundText[playerid] = Text:INVALID_TEXT_DRAW;
  260.     WinText[playerid] = Text:INVALID_TEXT_DRAW;
  261.     BetCreditText[playerid] = Text:INVALID_TEXT_DRAW;
  262.     for(new i; i < 5; i++)
  263.     {
  264.         CardsText[playerid][i] = Text:INVALID_TEXT_DRAW;
  265.         HoldsText[playerid][i] = Text:INVALID_TEXT_DRAW;
  266.     }
  267.     CardsText[playerid][5] = Text:INVALID_TEXT_DRAW;
  268.     return 1;
  269. }
  270.  
  271. public
  272.     OnPlayerDisconnect(playerid, reason)
  273. {
  274.     if(BackGroundText[playerid] != Text:INVALID_TEXT_DRAW)
  275.     {
  276.         Delete_PokerTextDraw(playerid);
  277.     }
  278.     return 1;
  279. }
  280.  
  281. public
  282.     OnPlayerCommandText(playerid, cmdtext[])
  283. {
  284.     new
  285.         idx,
  286.         cmd[20];
  287.     cmd = strtok(cmdtext, idx);
  288.     if(strcmp("/poker", cmd, true) == 0)
  289.     {
  290.         if(BackGroundText[playerid] != Text:INVALID_TEXT_DRAW)  return SendClientMessage(playerid, -1, "Usage: /exitpoker");
  291.         Create_PokerTextDraw(playerid);
  292.         cmd = strtok(cmdtext, idx);
  293.         new
  294.             credit = strval(cmd);
  295.         if(strlen(cmd) == 0) SendClientMessage(playerid, -1, "{008888}Usage: {ffffff}/poker [0-100000]");
  296.         else if(GetPlayerMoney(playerid) < credit) return SendClientMessage(playerid, -1, "Not have enough money.");
  297.         else if(credit < 5 || credit > 100000) return SendClientMessage(playerid, -1, "{008888}Usage: {ffffff}/poker [0-100000]");
  298.         else
  299.         {
  300.             PP_Info[playerid][Credit] = credit;
  301.             GivePlayerMoney(playerid, -credit);
  302.             TogglePlayerControllable(playerid, false);
  303.             PP_Info[playerid][Bet] = MIN_BET;
  304.             PP_Info[playerid][hold] = FIRST_DIVID;
  305.  
  306.             TextDrawShowForPlayer(playerid, BackGroundText[playerid]);
  307.             TextDrawShowForPlayer(playerid, WinText[playerid]);
  308.             TextDrawShowForPlayer(playerid, BetCreditText[playerid]);
  309.             BetCredit(playerid);
  310.             WinnText(playerid, 0);
  311.  
  312.             for(new i; i < 5; i++)
  313.             {
  314.                 PP_Info[playerid][fivecards_hand][i] = 0;
  315.                 PP_Info[playerid][fivecards_hand][i + 5] = 0;
  316.                 PP_Info[playerid][holdstate][i] = HOLDOFF;
  317.                 TextDrawSetString(CardsText[playerid][i], "LD_TATT:8poker"); //"LD_POKE:backred");
  318.                 TextDrawSetString(HoldsText[playerid][i], "LD_POKE:holdon");
  319.                 TextDrawShowForPlayer(playerid, CardsText[playerid][i]);
  320.                 TextDrawShowForPlayer(playerid, HoldsText[playerid][i]);
  321.             }
  322.             TextDrawShowForPlayer(playerid, CardsText[playerid][5]);
  323.             SelectTextDraw(playerid, 0x9999BBBB);
  324.         }
  325.         return 1;
  326.     }
  327.  
  328.     if(strcmp(cmd, "/exitpoker",true) == 0)
  329.     {
  330.         if(BackGroundText[playerid] == Text:INVALID_TEXT_DRAW)  return SendClientMessage(playerid, -1, "{008888}Usage: {ffffff}/poker [0-100000]");
  331.         Delete_PokerTextDraw(playerid);
  332.     //--+
  333.         TogglePlayerControllable(playerid, true);
  334.     //--+
  335.         GivePlayerMoney(playerid, PP_Info[playerid][Credit]);
  336.         new
  337.             str[128];
  338.         format(str, sizeof str, "Thank you using the {ffffff}¤ [Fs]Poker script by.: Zsolesszka ¤{22a4b5} Add money : {ffffff}$%d", PP_Info[playerid][Credit]);
  339.         PP_Info[playerid][Credit] = 0;
  340.         SendClientMessage(playerid, 0x22a4b5AA, str);
  341.         CancelSelectTextDraw(playerid); // Call OnPlayerClickTextDraw(playerid, 65535 (INVALID_TEXT_DRAW))
  342.         return 1;
  343.     }
  344.     return 0;
  345. }
  346.  
  347. stock
  348.     getwin(const cards[], &One_Pair_Type, &Two_Pair_Type)
  349. {
  350.     new
  351.         i = 0,
  352.         getcolor,
  353.         straight;
  354.  
  355.     getcolor = Color_Mask[cards[0]] | Color_Mask[cards[1]] | Color_Mask[cards[2]] | Color_Mask[cards[3]] | Color_Mask[cards[4]];
  356.     getcolor = getcolor & (getcolor - 1);
  357.  
  358.     straight = (Bynary_Mask[cards[0]] | Bynary_Mask[cards[1]] | Bynary_Mask[cards[2]] | Bynary_Mask[cards[3]] | Bynary_Mask[cards[4]]);
  359.  
  360.     if(getcolor == 0)
  361.     {
  362.         if(straight == 31) return ROYAL_FLUSH;
  363.         if(HasStraight(straight)) return STRAIGHT_FLUSH;
  364.         return FLUSH;
  365.     } else {
  366.         new
  367.             two_pair,
  368.             three_of_a_kind,
  369.             match[13];
  370.         for(i = 0; i < 5; i++)
  371.         {
  372.             match[cards[i] % 13]++;
  373.         }
  374.         for(i = 0; i < 13; i++)
  375.         {
  376.             switch(match[i])
  377.             {
  378.                 case 2:
  379.                 {
  380.                     two_pair++;
  381.                     if(two_pair == 1)
  382.                         One_Pair_Type = i;
  383.                     else if(two_pair == 2)
  384.                         Two_Pair_Type = i;
  385.                 }
  386.                 case 3: three_of_a_kind++, One_Pair_Type = i;
  387.                 case 4: return One_Pair_Type = i, FOUR_OF_A_KIND;
  388.             }
  389.         }
  390.         if(two_pair == 1 && three_of_a_kind == 1) return FULL_HOUSE;
  391.         if(two_pair == 2) return TWO_PAIR;
  392.         if(two_pair == 1) return ONE_PAIR;
  393.         if(three_of_a_kind == 1) return THREE_OF_A_KIND;
  394.         if(HasStraight(straight)) return STRAIGHT;
  395.     }
  396.     return HIGH_CARD;
  397. }
  398.  
  399. stock
  400.     HasStraight(straight)
  401. {
  402.     switch(straight)
  403.     {
  404.         case 31, 62, 124, 248, 496, 992, 1984, 3968, 7936, 4111: return true;
  405.     }
  406.     return false;
  407. }
  408.  
  409. public
  410.     TextDrawDizajn(playerid, index)
  411. {
  412.     if(index == 5)
  413.     {
  414.         new
  415.             win,
  416.             One_pair,
  417.             Two_pair;
  418.         win = getwin(PP_Info[playerid][fivecards_hand], One_pair, Two_pair);
  419.         SetTimerEx("TextDrawDizajn2", 200, false, "iiii", playerid, win, One_pair, Two_pair);
  420.         return 1;
  421.     } else {
  422.         PlaySound(playerid, 20800);
  423.         TextDrawSetString(CardsText[playerid][index], "LD_POKE:cdback");
  424.         TextDrawSetString(HoldsText[playerid][index], "LD_POKE:holdoff");
  425.         SetTimerEx("TextDrawDizajn", 100, false, "ii", playerid, ++index);
  426.     }
  427.     return 1;
  428. }
  429.  
  430. public
  431.     TextDrawDizajn2(playerid, win, One_pair, Two_pair)
  432. {
  433. //--+
  434.     for(new i; i < 5; i++)
  435.     {
  436.         TextDrawSetString(CardsText[playerid][i], LD_POKE[PP_Info[playerid][fivecards_hand][i]]);
  437.         TextDrawSetString(HoldsText[playerid][i], "LD_POKE:holdoff");
  438.     }
  439. //--+
  440.     switch(win)
  441.     {
  442.         case STRAIGHT, FLUSH, STRAIGHT_FLUSH, FULL_HOUSE, ROYAL_FLUSH:
  443.         {
  444.             for(new i = 0; i < 5; i++)
  445.             {
  446.                 TextDrawSetString(HoldsText[playerid][i], "LD_POKE:holdon");
  447.                 PP_Info[playerid][holdstate][i] = HOLDON;
  448.             }
  449.         }
  450.         case TWO_PAIR:
  451.         {
  452.             for(new i = 0; i < 5; i++)
  453.             {
  454.                 if( Card_Value[One_pair] == Card_Value[PP_Info[playerid][fivecards_hand][i]] ||
  455.                     Card_Value[Two_pair] == Card_Value[PP_Info[playerid][fivecards_hand][i]])
  456.                 {
  457.                     TextDrawSetString(HoldsText[playerid][i], "LD_POKE:holdon");
  458.                     PP_Info[playerid][holdstate][i] = HOLDON;
  459.                 }
  460.             }
  461.         }
  462.         case ONE_PAIR, FOUR_OF_A_KIND, THREE_OF_A_KIND:
  463.         {
  464.             for(new i = 0; i < 5; i++)
  465.             {
  466.                 if(Card_Value[One_pair] == Card_Value[PP_Info[playerid][fivecards_hand][i]])
  467.                 {
  468.                     TextDrawSetString(HoldsText[playerid][i], "LD_POKE:holdon");
  469.                     PP_Info[playerid][holdstate][i] = HOLDON;
  470.                 }
  471.             }
  472.         }
  473.     }
  474. //--+
  475. //  Poker_Dialog(playerid, rang_sor[win]);
  476. //--+
  477.     WinnText(playerid, win);
  478. //--+
  479.     return 1;
  480. }
  481.  
  482. stock
  483.     WinnText(playerid, win)
  484. {
  485.     new
  486.         color[10] = { 'w', ... };
  487.  
  488.     color[win] = 'r';
  489.  
  490.     new
  491.         str[256];
  492.     format(str, sizeof str, "~%c~~n~Royal Flush \t \t\t\t:\t$ %d\
  493.                             ~%c~~n~Straight Flush \t :\t$ %d\
  494.                             ~%c~~n~4 of a Kind \t \t \t    :\t$ %d\
  495.                             ~%c~~n~Full House \t \t \t \t :\t$ %d\
  496.                             ~%c~~n~Flush \t \t \t \t \t \t \t \t:\t$ %d\
  497.                             ~%c~~n~Straight \t \t \t \t \t \t:\t$ %d\
  498.                             ~%c~~n~3 of a Kind\t \t \t \t \t:\t$ %d\
  499.                             ~%c~~n~Two Pair \t \t \t \t \t \t:\t$ %d",
  500.                     color[9], PP_Info[playerid][Bet] * pot[9],
  501.                     color[8], PP_Info[playerid][Bet] * pot[8],
  502.                     color[7], PP_Info[playerid][Bet] * pot[7],
  503.                     color[6], PP_Info[playerid][Bet] * pot[6],
  504.                     color[5], PP_Info[playerid][Bet] * pot[5],
  505.                     color[4], PP_Info[playerid][Bet] * pot[4],
  506.                     color[3], PP_Info[playerid][Bet] * pot[3],
  507.                     color[2], PP_Info[playerid][Bet] * pot[2]);
  508.  
  509.     TextDrawSetString(WinText[playerid], str);
  510. }
  511.  
  512. stock
  513.     BetCredit(playerid)
  514. {
  515.     new
  516.         str[128];
  517.     format(str, sizeof str, "~g~Bet: ~w~$%d                                    ~g~Credit: ~w~$%d",
  518.                             PP_Info[playerid][Bet],
  519.                             PP_Info[playerid][Credit]);
  520.  
  521.     TextDrawSetString(BetCreditText[playerid], str);
  522.     return 1;
  523. }
  524.  
  525. stock
  526.     Create_PokerTextDraw(playerid)
  527. {
  528.     BackGroundText[playerid] = TextDrawCreate(-0.500, -0.500, "loadsc8:loadsc8");
  529.     TextDrawFont(BackGroundText[playerid], 4);
  530.     TextDrawTextSize(BackGroundText[playerid], 640.000, 450.000);
  531.     TextDrawColor(BackGroundText[playerid], -1);
  532. // ..........................................
  533.     BetCreditText[playerid] = TextDrawCreate(320.000000, 379.000000, "_");
  534.     TextDrawAlignment(BetCreditText[playerid], 2);
  535.     TextDrawBackgroundColor(BetCreditText[playerid], 255);
  536.     TextDrawFont(BetCreditText[playerid], 3);
  537.     TextDrawLetterSize(BetCreditText[playerid], 0.300000, 1.600000);
  538.     TextDrawColor(BetCreditText[playerid], -1);
  539.     TextDrawSetOutline(BetCreditText[playerid], 0);
  540.     TextDrawSetProportional(BetCreditText[playerid], 1);
  541.     TextDrawSetShadow(BetCreditText[playerid], 1);
  542.     TextDrawUseBox(BetCreditText[playerid], 1);
  543.     TextDrawBoxColor(BetCreditText[playerid], 335595560);
  544.     TextDrawTextSize(BetCreditText[playerid], 6.000000, 302.000000);
  545. // ..........................................
  546.     WinText[playerid] = TextDrawCreate(167.500000, 144.000000, "_");
  547.     TextDrawAlignment(WinText[playerid], 1);
  548.     TextDrawBackgroundColor(WinText[playerid], 255);
  549.     TextDrawFont(WinText[playerid], 2);
  550.     TextDrawLetterSize(WinText[playerid], 0.260000, 1.400000);
  551.     TextDrawColor(WinText[playerid], -1);
  552.     TextDrawSetOutline(WinText[playerid], 1);
  553.     TextDrawSetProportional(WinText[playerid], 1);
  554. // ..........................................
  555.     CardsText[playerid][0] = TextDrawCreate(167.500, 270.500, "LD_POKE:backcyan");
  556.     TextDrawFont(CardsText[playerid][0], 4);
  557.     TextDrawTextSize(CardsText[playerid][0], 59.500, 88.000);
  558.     TextDrawColor(CardsText[playerid][0], -1); TextDrawSetSelectable(CardsText[playerid][0], 1);
  559.  
  560.     CardsText[playerid][1] = TextDrawCreate(229.000, 270.500, "LD_POKE:backcyan");
  561.     TextDrawFont(CardsText[playerid][1], 4);
  562.     TextDrawTextSize(CardsText[playerid][1], 59.500, 88.000);
  563.     TextDrawColor(CardsText[playerid][1], -1); TextDrawSetSelectable(CardsText[playerid][1], 1);
  564.  
  565.     CardsText[playerid][2] = TextDrawCreate(290.500, 270.500, "LD_POKE:backcyan");
  566.     TextDrawFont(CardsText[playerid][2], 4);
  567.     TextDrawTextSize(CardsText[playerid][2], 59.500, 88.000);
  568.     TextDrawColor(CardsText[playerid][2], -1); TextDrawSetSelectable(CardsText[playerid][2], 1);
  569.  
  570.     CardsText[playerid][3] = TextDrawCreate(352.000, 270.500, "LD_POKE:backcyan");
  571.     TextDrawFont(CardsText[playerid][3], 4);
  572.     TextDrawTextSize(CardsText[playerid][3], 59.500, 88.000);
  573.     TextDrawColor(CardsText[playerid][3], -1); TextDrawSetSelectable(CardsText[playerid][3], 1);
  574.  
  575.     CardsText[playerid][4] = TextDrawCreate(413.500, 270.500, "LD_POKE:backcyan");
  576.     TextDrawFont(CardsText[playerid][4], 4);
  577.     TextDrawTextSize(CardsText[playerid][4], 59.500, 88.000);
  578.     TextDrawColor(CardsText[playerid][4], -1); TextDrawSetSelectable(CardsText[playerid][4], 1);
  579.    
  580.     CardsText[playerid][5] = TextDrawCreate(290.500, 400.500, "LD_POKE:deal");
  581.     TextDrawFont(CardsText[playerid][5], 4);
  582.     TextDrawTextSize(CardsText[playerid][5], 59.500, 14.500);
  583.     TextDrawColor(CardsText[playerid][5], -1); TextDrawSetSelectable(CardsText[playerid][5], 1);
  584. // ..........................................
  585.     HoldsText[playerid][0] = TextDrawCreate(167.500, 360.500, "LD_POKE:holdoff");
  586.     TextDrawFont(HoldsText[playerid][0], 4);
  587.     TextDrawTextSize(HoldsText[playerid][0], 59.500, 14.500);
  588.     TextDrawColor(HoldsText[playerid][0], -1);
  589.  
  590.     HoldsText[playerid][1] = TextDrawCreate(229.000, 360.500, "LD_POKE:holdoff");
  591.     TextDrawFont(HoldsText[playerid][1], 4);
  592.     TextDrawTextSize(HoldsText[playerid][1], 59.500, 14.500);
  593.     TextDrawColor(HoldsText[playerid][1], -1);
  594.  
  595.     HoldsText[playerid][2] = TextDrawCreate(290.500, 360.500, "LD_POKE:holdoff");
  596.     TextDrawFont(HoldsText[playerid][2], 4);
  597.     TextDrawTextSize(HoldsText[playerid][2], 59.500, 14.500);
  598.     TextDrawColor(HoldsText[playerid][2], -1);
  599.  
  600.     HoldsText[playerid][3] = TextDrawCreate(352.000, 360.500, "LD_POKE:holdoff");
  601.     TextDrawFont(HoldsText[playerid][3], 4);
  602.     TextDrawTextSize(HoldsText[playerid][3], 59.500, 14.500);
  603.     TextDrawColor(HoldsText[playerid][3], -1);
  604.  
  605.     HoldsText[playerid][4] = TextDrawCreate(413.500, 360.500, "LD_POKE:holdoff");
  606.     TextDrawFont(HoldsText[playerid][4], 4);
  607.     TextDrawTextSize(HoldsText[playerid][4], 59.500, 14.500);
  608.     TextDrawColor(HoldsText[playerid][4], -1);
  609. }
  610.  
  611. stock
  612.     Delete_PokerTextDraw(playerid)
  613. {
  614.     TextDrawHideForPlayer(playerid, BackGroundText[playerid]);
  615.     TextDrawHideForPlayer(playerid, WinText[playerid]);
  616.     TextDrawHideForPlayer(playerid, BetCreditText[playerid]);
  617.     TextDrawDestroy(BackGroundText[playerid]);
  618.     TextDrawDestroy(WinText[playerid]);
  619.     TextDrawDestroy(BetCreditText[playerid]);
  620.     BackGroundText[playerid] = Text:INVALID_TEXT_DRAW;
  621.     WinText[playerid] = Text:INVALID_TEXT_DRAW;
  622.     BetCreditText[playerid] = Text:INVALID_TEXT_DRAW;
  623.  
  624.     for(new i = 0; i < 5; i++)
  625.     {
  626.         TextDrawHideForPlayer(playerid, CardsText[playerid][i]);
  627.         TextDrawHideForPlayer(playerid, HoldsText[playerid][i]);
  628.         TextDrawDestroy(CardsText[playerid][i]);
  629.         TextDrawDestroy(HoldsText[playerid][i]);
  630.         CardsText[playerid][i] = Text:INVALID_TEXT_DRAW;
  631.         HoldsText[playerid][i] = Text:INVALID_TEXT_DRAW;
  632.     }
  633.     TextDrawHideForPlayer(playerid, CardsText[playerid][5]);
  634.     TextDrawDestroy(CardsText[playerid][5]);
  635.     CardsText[playerid][5] = Text:INVALID_TEXT_DRAW;
  636.     return 1;
  637. }
  638.  
  639. stock
  640.     PlaySound(playerid, sound)
  641. {
  642.     new
  643.         Float:X,
  644.         Float:Y,
  645.         Float:Z;
  646.     GetPlayerPos(playerid, X, Y, Z);
  647.     PlayerPlaySound(playerid, sound, X, Y, Z);
  648.     return sound;
  649. }
  650.  
  651. stock
  652.     HasDuplicateValues(const array[], size = sizeof array)
  653. {
  654.     for(new f = 0; f < size - 1; ++f)
  655.     {
  656.         for(new c = f + 1; c < size; ++c)
  657.         {
  658.             if(array[f] == array[c])
  659.             {
  660.                 return true;
  661.             }
  662.         }
  663.     }
  664.     return false;
  665. }
  666.  
  667. stock
  668.     RandomNumber(value, array[], size = sizeof array)
  669. {
  670.     for(new p = 0; p < size; p++) array[p] = random(value);
  671. }
  672.  
  673. stock
  674.     Swap (&a, &b)
  675. {
  676.     new s;
  677.     s = a;
  678.     a = b;
  679.     b = s;
  680. }
  681.  
  682. stock
  683.     strtok(const string[], &index)
  684. {
  685.     new length = strlen(string);
  686.     while ((index < length) && (string[index] <= ' '))
  687.     {
  688.         index++;
  689.     }
  690.     new offset = index;
  691.     new result[20];
  692.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  693.     {
  694.         result[index - offset] = string[index];
  695.         index++;
  696.     }
  697.     result[index - offset] = EOS;
  698.     return result;
  699. }
  700.  
  701. public
  702.     OnPlayerClickTextDraw(playerid, Text:clickedid)
  703. {
  704.     if(clickedid == Text:INVALID_TEXT_DRAW) return 1; // called CancelSelectTextDraw(playerid);  OnPlayerClickTextDraw(playerid, 65535)
  705.     new msg[256+1];
  706.     format(msg,sizeof(msg),"(TextDraw) You selected: %d", int:clickedid);
  707.     SendClientMessage(playerid, 0xFFFFFFFF, msg);
  708.    
  709.     if(CardsText[playerid][5] == clickedid) // Deal
  710.     {
  711.         if(PP_Info[playerid][hold] == FIRST_DIVID)
  712.         {
  713.             if(PP_Info[playerid][Credit] < PP_Info[playerid][Bet]) return SendClientMessage(playerid, -1, "No credit");
  714. //--+
  715.             PP_Info[playerid][Credit] -= PP_Info[playerid][Bet];
  716.             PP_Info[playerid][hold] = SECOND_DIVID;
  717.             PlaySound(playerid, 43000);
  718. //--+
  719.             do
  720.             {
  721.                 RandomNumber(52, PP_Info[playerid][fivecards_hand], 10); // Pawn sizeof() does not work enum array
  722.             }
  723.             while(HasDuplicateValues(PP_Info[playerid][fivecards_hand], 10)) // Pawn sizeof() does not work enum array
  724. //--+
  725.             WinnText(playerid, 0);
  726.             BetCredit(playerid);
  727.             TextDrawDizajn(playerid, 0);
  728. /*          TextDrawSetSelectable(CardsText[playerid][0], 1); // dont work enable disable function
  729.             TextDrawSetSelectable(CardsText[playerid][1], 1);
  730.             TextDrawSetSelectable(CardsText[playerid][2], 1);
  731.             TextDrawSetSelectable(CardsText[playerid][3], 1);
  732.             TextDrawSetSelectable(CardsText[playerid][4], 1);*/
  733.         } else {       
  734. /*          TextDrawSetSelectable(CardsText[playerid][0], 0); // dont work enable disable function
  735.             TextDrawSetSelectable(CardsText[playerid][1], 0);
  736.             TextDrawSetSelectable(CardsText[playerid][2], 0);
  737.             TextDrawSetSelectable(CardsText[playerid][3], 0);
  738.             TextDrawSetSelectable(CardsText[playerid][4], 0);*/
  739. //--+
  740.             PP_Info[playerid][hold] = FIRST_DIVID;
  741. //--+
  742.             for(new i; i < 5; i++)
  743.             {
  744.                 if(PP_Info[playerid][holdstate][i] == HOLDON)
  745.                 {
  746.                     TextDrawSetString(HoldsText[playerid][i], "LD_POKE:holdoff");
  747.                     PP_Info[playerid][holdstate][i] = HOLDOFF;
  748.                 } else {
  749.                     Swap(PP_Info[playerid][fivecards_hand][i], PP_Info[playerid][fivecards_hand][i + 5]);
  750.                     TextDrawSetString(CardsText[playerid][i], LD_POKE[PP_Info[playerid][fivecards_hand][i]]);
  751.                 }
  752.             }
  753.             new
  754.                 One_pair,
  755.                 Two_pair,
  756.                 win;
  757. //--+
  758.             win = getwin(PP_Info[playerid][fivecards_hand], One_pair, Two_pair);
  759. //--+
  760.             if(win > ONE_PAIR)
  761.             {
  762. //--+
  763.                 PP_Info[playerid][Credit] += (pot[win] * PP_Info[playerid][Bet]);
  764. //--+
  765.                 new
  766.                     str[128];
  767.                 format(str, sizeof str, "Win:{00a6ff}%s | $%d", rang_sor[win], pot[win] * PP_Info[playerid][Bet]);
  768.                 SendClientMessage(playerid, -1, str);
  769. //--+
  770.                 switch(win)
  771.                 {
  772.                     case STRAIGHT, FLUSH, STRAIGHT_FLUSH, FULL_HOUSE, ROYAL_FLUSH:
  773.                     {
  774.                         for(new i = 0; i < 5; i++)
  775.                         {
  776.                             TextDrawSetString(HoldsText[playerid][i], "LD_POKE:holdmid");
  777.                         }
  778.                     }
  779.                     case TWO_PAIR:
  780.                     {
  781.                         for(new i = 0; i < 5; i++)
  782.                         {
  783.                             if( Card_Value[One_pair] == Card_Value[PP_Info[playerid][fivecards_hand][i]] ||
  784.                                 Card_Value[Two_pair] == Card_Value[PP_Info[playerid][fivecards_hand][i]])
  785.                             {
  786.                                 TextDrawSetString(HoldsText[playerid][i], "LD_POKE:holdmid");
  787.                             }
  788.                         }
  789.                     }
  790.                     case ONE_PAIR, FOUR_OF_A_KIND, THREE_OF_A_KIND:
  791.                     {
  792.                         for(new i = 0; i < 5; i++)
  793.                         {
  794.                             if(Card_Value[One_pair] == Card_Value[PP_Info[playerid][fivecards_hand][i]])
  795.                             {
  796.                                 TextDrawSetString(HoldsText[playerid][i], "LD_POKE:holdmid");
  797.                             }
  798.                         }
  799.                     }
  800.                 }
  801.                 PlaySound(playerid, 43001); //30800); //5448);
  802.                 WinnText(playerid, win);
  803.                 BetCredit(playerid);
  804. //--+
  805.             } else {
  806. //--+
  807.                 for(new i = 0; i < 5; i++)
  808.                 {
  809.                     TextDrawSetString(HoldsText[playerid][i], "LD_POKE:holdoff");
  810.                 }
  811. //--+
  812.             }  
  813.         }
  814.     } else {
  815.         if(PP_Info[playerid][hold] == SECOND_DIVID)
  816.         {
  817.             for(new i = 0; i < 5; i++)
  818.             {
  819.                 if(CardsText[playerid][i] == clickedid)
  820.                 {
  821.                     PP_Info[playerid][holdstate][i] = HOLDOFF - PP_Info[playerid][holdstate][i];
  822.                     TextDrawSetString(HoldsText[playerid][i], HoldCardText[PP_Info[playerid][holdstate][i]]);
  823.                     PlaySound(playerid, 21000); //43000);
  824.                     return 1;
  825.                 }
  826.             }
  827.         }
  828.     }
  829.     return 1;
  830. }
  831.  
  832. //Coming soon..
  833. /*
  834.             switch(listitem)
  835.                 {
  836.                     case 1: // Bet+
  837.                     {
  838.                         if(PP_Info[playerid][Bet] < 100)
  839.                         {
  840.                             PP_Info[playerid][Bet] += 5;
  841.                             BetCredit(playerid);
  842.                             WinnText(playerid, 0)
  843.                         }
  844.                         CreditBet_Dialog(playerid, " ");
  845.                         return 1;
  846.                     }
  847.                     case 2: // Bet-
  848.                     {
  849.                         if(PP_Info[playerid][Bet] > 5)
  850.                         {
  851.                             PP_Info[playerid][Bet] -= 5;
  852.                             BetCredit(playerid);
  853.                             WinnText(playerid, 0)
  854.                         }
  855.                         CreditBet_Dialog(playerid, " ");
  856.                         return 1;
  857.                     }
  858.                     case 3,4: // Credit +100 / Credit +500
  859.                     {
  860.                         new
  861.                             credit_[] = { 100, 500 };
  862.                         if(GetPlayerMoney(playerid) < credit_[listitem - 3])
  863.                         {
  864.                             CreditBet_Dialog(playerid, "{cc1212}You have no money.");
  865.                         } else {
  866.                             GivePlayerMoney(playerid, -credit_[listitem - 3]);
  867.                             PP_Info[playerid][Credit] += credit_[listitem - 3];
  868.                             BetCredit(playerid);
  869.                             CreditBet_Dialog(playerid, " ");
  870.                         }
  871.                         return 1;
  872.                     }
  873.                     case 5:
  874.                     {
  875.                         TextDrawSetString(BackGroundText[playerid], BackGroundData[random(sizeof BackGroundData)]);
  876.                         CreditBet_Dialog(playerid, "{ffff11}Changed background.");
  877.                         return 1;
  878.                     }
  879.                 }
  880. */
Add Comment
Please, Sign In to add comment