Advertisement
Zsolesszka

[FS]Poker SA-MP 0.3e RC4 2012.03.22

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