Advertisement
Guest User

SA-MP Simple Slot Machine

a guest
Nov 28th, 2018
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 16.87 KB | None | 0 0
  1. /*
  2.     Slot Machine script by NaS (2011).
  3.    
  4.     For 0.3dRC5-3 (+)
  5.    
  6.     Change MIN_BET for the minimum bet
  7.    
  8.     Change MAX_BET for the maximum bet
  9.    
  10.     Change Bet_STEO for the bet steps (if it's 5 the bets can be: 5,  10,  15,  20 etc up to MAX_BET)
  11.  
  12.  
  13.     Do NOT remove this credits.
  14. */
  15.  
  16.  
  17. #include <a_samp>
  18.  
  19. // cherry   x   25
  20. // grapes   x  100
  21. // 69       x  250
  22. // bells    x  500
  23. // bar 1    x 1000
  24. // bar 2    x 2000
  25.  
  26. #define WIN_MULTIPLIER_GLOBAL 1.0
  27.  
  28. #define SLOT_MACHINE_POS_Y  350.0
  29.  
  30. #define MIN_BET 5
  31. #define MAX_BET 50
  32.  
  33. #define BET_STEP 5
  34.  
  35. #define G_STATE_NOT_GAMBLING    0
  36. #define G_STATE_READY           1
  37. #define G_STATE_GAMBLING        2
  38. #define G_STATE_DISPLAY         3 // Currently displaying the message
  39. #define G_STATE_PLAY_AGAIN      4 // Not used
  40.  
  41. #define DISPLAY_TIME 750 // Time to display the messages
  42. #define GAMBLE_TIMER 100 // Decrease this if too fast
  43.  
  44. new Text:VerText;
  45. new Text:ReadyText;
  46. new PlayerText:BetText[MAX_PLAYERS] = {PlayerText:-1, ...};
  47.  
  48. new Text:Box;
  49.  
  50. new Text:Digit1[6];
  51. new Text:Digit2[6];
  52. new Text:Digit3[6];
  53.  
  54. new Slots[MAX_PLAYERS][3];
  55. new SlotCounter[MAX_PLAYERS];
  56. new Gambling[MAX_PLAYERS];
  57.  
  58. new SlotTimer[MAX_PLAYERS];
  59.  
  60. new Bet[MAX_PLAYERS];
  61. new Balance[MAX_PLAYERS];
  62.  
  63. new bool:rdy=false;
  64.  
  65. Text:CreateSprite(Float:X, Float:Y, Name[], Float:Width, Float:Height)
  66. {
  67.     new Text:RetSprite;
  68.     RetSprite = TextDrawCreate(X,  Y,  Name); // Text is txdfile:texture
  69.     TextDrawFont(RetSprite,  TEXT_DRAW_FONT_SPRITE_DRAW); // Font ID 4 is the sprite draw font
  70.     TextDrawColor(RetSprite, 0xFFFFFFFF);
  71.     TextDrawTextSize(RetSprite, Width, Height); // Text size is the Width:Height
  72.     return RetSprite;
  73. }
  74.  
  75. Text:CreateBox(Float:X, Float:Y, Float:Width, Float:Height, color)
  76. {
  77.     new Text[500];
  78.     for(new i = floatround(Y); i < floatround(Y+Height);i++)
  79.     {
  80.         strcat(Text, "~n~_");
  81.     }
  82.     new Text:RetSprite;
  83.     RetSprite = TextDrawCreate(X,  Y,  Text); // Text is txdfile:texture
  84.     TextDrawFont(RetSprite,  0); // Font ID 4 is the sprite draw font
  85.     TextDrawColor(RetSprite, 0xFFFFFFFF);
  86.     TextDrawTextSize(RetSprite, Width+X, Height+Y); // Text size is the Width:Height
  87.     TextDrawUseBox(RetSprite, 1);
  88.     TextDrawBoxColor(RetSprite, color);
  89.     TextDrawLetterSize(RetSprite, 0.0001, 0.1158);
  90.     return RetSprite;
  91. }
  92.  
  93. public OnFilterScriptInit()
  94. {
  95.     SetTimer("RDYBLINK", 500, 1);
  96.    
  97.     Box = CreateBox(194.0, SLOT_MACHINE_POS_Y-20, 3*64.0 + 3*20, 84, 0x00000077);
  98.    
  99.     // Cherries (x25)
  100.     Digit1[0] = CreateSprite(214.0, SLOT_MACHINE_POS_Y, "LD_SLOT:cherry", 64.0, 64.0);
  101.     Digit2[0] = CreateSprite(288.0, SLOT_MACHINE_POS_Y, "LD_SLOT:cherry", 64.0, 64.0);
  102.     Digit3[0] = CreateSprite(362.0, SLOT_MACHINE_POS_Y, "LD_SLOT:cherry", 64.0, 64.0);
  103.    
  104.     // grapes (x100)
  105.     Digit1[1] = CreateSprite(214.0, SLOT_MACHINE_POS_Y, "LD_SLOT:grapes", 64.0, 64.0);
  106.     Digit2[1] = CreateSprite(288.0, SLOT_MACHINE_POS_Y, "LD_SLOT:grapes", 64.0, 64.0);
  107.     Digit3[1] = CreateSprite(362.0, SLOT_MACHINE_POS_Y, "LD_SLOT:grapes", 64.0, 64);
  108.    
  109.     // 69's (x250)
  110.     Digit1[2] = CreateSprite(214.0, SLOT_MACHINE_POS_Y, "LD_SLOT:r_69", 64.0, 64.0);
  111.     Digit2[2] = CreateSprite(288.0, SLOT_MACHINE_POS_Y, "LD_SLOT:r_69", 64.0, 64.0);
  112.     Digit3[2] = CreateSprite(362.0, SLOT_MACHINE_POS_Y, "LD_SLOT:r_69", 64.0, 64.0);
  113.    
  114.     // bells (x500)
  115.     Digit1[3] = CreateSprite(214.0, SLOT_MACHINE_POS_Y, "LD_SLOT:bell", 64.0, 64.0);
  116.     Digit2[3] = CreateSprite(288.0, SLOT_MACHINE_POS_Y, "LD_SLOT:bell", 64.0, 64.0);
  117.     Digit3[3] = CreateSprite(362.0, SLOT_MACHINE_POS_Y, "LD_SLOT:bell", 64.0, 64.0);
  118.    
  119.     // Bars [1 bar] (x1000)
  120.     Digit1[4] = CreateSprite(214.0, SLOT_MACHINE_POS_Y, "LD_SLOT:bar1_o", 64.0, 64.0);
  121.     Digit2[4] = CreateSprite(288.0, SLOT_MACHINE_POS_Y, "LD_SLOT:bar1_o", 64.0, 64.0);
  122.     Digit3[4] = CreateSprite(362.0, SLOT_MACHINE_POS_Y, "LD_SLOT:bar1_o", 64.0, 64.0);
  123.    
  124.     // Bars [2 bar] (x2000)
  125.     Digit1[5] = CreateSprite(214.0, SLOT_MACHINE_POS_Y, "LD_SLOT:bar2_o", 64.0, 64.0);
  126.     Digit2[5] = CreateSprite(288.0, SLOT_MACHINE_POS_Y, "LD_SLOT:bar2_o", 64.0, 64.0);
  127.     Digit3[5] = CreateSprite(362.0, SLOT_MACHINE_POS_Y, "LD_SLOT:bar2_o", 64.0, 64.0);
  128.    
  129.    
  130.     ReadyText = TextDrawCreate(320.0, SLOT_MACHINE_POS_Y+1.4, "~w~Ready to play.~n~~b~ ~k~~PED_SPRINT~ ~w~- ~g~gamble~n~~b~~k~~VEHICLE_ENTER_EXIT~ ~w~- ~r~exit~n~~b~~k~~PED_JUMPING~ ~w~- ~y~increase Bet");
  131.     TextDrawUseBox(ReadyText, 1);
  132.     TextDrawFont(ReadyText, 2);
  133.     TextDrawSetShadow(ReadyText, 0);
  134.     TextDrawSetOutline(ReadyText, 1);
  135.     TextDrawLetterSize(ReadyText, 0.3, 1.23);
  136.     TextDrawAlignment(ReadyText, 2);
  137.     TextDrawBoxColor(ReadyText, 0x00000077);
  138.     TextDrawTextSize(ReadyText, 350, 210);
  139.    
  140.     VerText = TextDrawCreate(194.0, SLOT_MACHINE_POS_Y-21, "~g~$$$ ~p~$lotmachine v0.5 - by NaS ~g~$$$");
  141.     TextDrawFont(VerText, 1);
  142.     TextDrawSetShadow(VerText, 0);
  143.     TextDrawSetOutline(VerText, 1);
  144.     TextDrawLetterSize(VerText, 0.16, 0.65);
  145.  
  146.     for(new i; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) OnPlayerConnect(i); // This will make the slotmachine usable for already connected players!
  147.  
  148.     return 1;
  149. }
  150.  
  151. public OnFilterScriptExit()
  152. {
  153.     TextDrawDestroy(Digit1[0]);
  154.     TextDrawDestroy(Digit2[0]);
  155.     TextDrawDestroy(Digit3[0]);
  156.    
  157.     TextDrawDestroy(Digit1[1]);
  158.     TextDrawDestroy(Digit2[1]);
  159.     TextDrawDestroy(Digit3[1]);
  160.    
  161.     TextDrawDestroy(Digit1[2]);
  162.     TextDrawDestroy(Digit2[2]);
  163.     TextDrawDestroy(Digit3[2]);
  164.    
  165.     TextDrawDestroy(Digit1[3]);
  166.     TextDrawDestroy(Digit2[3]);
  167.     TextDrawDestroy(Digit3[3]);
  168.    
  169.     TextDrawDestroy(Digit1[4]);
  170.     TextDrawDestroy(Digit2[4]);
  171.     TextDrawDestroy(Digit3[4]);
  172.    
  173.     TextDrawDestroy(Digit1[5]);
  174.     TextDrawDestroy(Digit2[5]);
  175.     TextDrawDestroy(Digit3[5]);
  176.    
  177.    
  178.     TextDrawDestroy(Box);
  179.     TextDrawDestroy(ReadyText);
  180.     TextDrawDestroy(VerText);
  181.  
  182.     for(new i; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) OnPlayerDisconnect(i, 0);
  183.    
  184.     return 1;
  185. }
  186.  
  187. public OnPlayerRequestClass(playerid,  classid)
  188. {
  189.     SetPlayerPos(playerid,  1958.3783,  1343.1572,  15.3746);
  190.     SetPlayerCameraPos(playerid,  1958.3783,  1343.1572,  15.3746);
  191.     SetPlayerCameraLookAt(playerid,  1958.3783,  1343.1572,  15.3746);
  192.     return 1;
  193. }
  194.  
  195. public OnPlayerConnect(playerid)
  196. {
  197.     Gambling[playerid] = G_STATE_NOT_GAMBLING;
  198.     SlotTimer[playerid] = -1;
  199.    
  200.     GivePlayerMoney(playerid, 100000); // Test
  201.    
  202.     if(BetText[playerid] == PlayerText:-1)
  203.     {
  204.         BetText[playerid] = CreatePlayerTextDraw(playerid, 195.0, SLOT_MACHINE_POS_Y+58, "~y~Bet: 5$");
  205.         PlayerTextDrawFont(playerid, BetText[playerid], 2);
  206.         PlayerTextDrawLetterSize(playerid, BetText[playerid], 0.35, 0.8);
  207.         PlayerTextDrawSetShadow(playerid, BetText[playerid], 0);
  208.         PlayerTextDrawSetOutline(playerid, BetText[playerid], 1);
  209.     }
  210.  
  211.     return 1;
  212. }
  213.  
  214. public OnPlayerDisconnect(playerid,  reason)
  215. {
  216.     ExitPlayerFromSlotMachine(playerid);
  217.    
  218.     if(SlotTimer[playerid] != -1) KillTimer(SlotTimer[playerid]);
  219.  
  220.     if(BetText[playerid] != PlayerText:-1)
  221.     {
  222.         PlayerTextDrawDestroy(playerid, BetText[playerid]);
  223.         BetText[playerid] = PlayerText:-1;
  224.     }
  225.  
  226.     return 1;
  227. }
  228.  
  229. ShowPlayerSlots(playerid, slot1, slot2, slot3)
  230. {
  231.     TextDrawHideForPlayer(playerid, Digit1[0]);
  232.     TextDrawHideForPlayer(playerid, Digit2[0]);
  233.     TextDrawHideForPlayer(playerid, Digit3[0]);
  234.    
  235.     TextDrawHideForPlayer(playerid, Digit1[1]);
  236.     TextDrawHideForPlayer(playerid, Digit2[1]);
  237.     TextDrawHideForPlayer(playerid, Digit3[1]);
  238.    
  239.     TextDrawHideForPlayer(playerid, Digit1[2]);
  240.     TextDrawHideForPlayer(playerid, Digit2[2]);
  241.     TextDrawHideForPlayer(playerid, Digit3[2]);
  242.    
  243.     TextDrawHideForPlayer(playerid, Digit1[3]);
  244.     TextDrawHideForPlayer(playerid, Digit2[3]);
  245.     TextDrawHideForPlayer(playerid, Digit3[3]);
  246.    
  247.     TextDrawHideForPlayer(playerid, Digit1[4]);
  248.     TextDrawHideForPlayer(playerid, Digit2[4]);
  249.     TextDrawHideForPlayer(playerid, Digit3[4]);
  250.    
  251.     TextDrawHideForPlayer(playerid, Digit1[5]);
  252.     TextDrawHideForPlayer(playerid, Digit2[5]);
  253.     TextDrawHideForPlayer(playerid, Digit3[5]);
  254.    
  255.    
  256.     TextDrawShowForPlayer(playerid, Digit1[slot1]);
  257.     TextDrawShowForPlayer(playerid, Digit2[slot2]);
  258.     TextDrawShowForPlayer(playerid, Digit3[slot3]);
  259.    
  260.     TextDrawShowForPlayer(playerid, Box);
  261. }
  262.  
  263. HideSlotsForPlayer(playerid)
  264. {
  265.     TextDrawHideForPlayer(playerid, Digit1[0]);
  266.     TextDrawHideForPlayer(playerid, Digit2[0]);
  267.     TextDrawHideForPlayer(playerid, Digit3[0]);
  268.  
  269.     TextDrawHideForPlayer(playerid, Digit1[1]);
  270.     TextDrawHideForPlayer(playerid, Digit2[1]);
  271.     TextDrawHideForPlayer(playerid, Digit3[1]);
  272.  
  273.     TextDrawHideForPlayer(playerid, Digit1[2]);
  274.     TextDrawHideForPlayer(playerid, Digit2[2]);
  275.     TextDrawHideForPlayer(playerid, Digit3[2]);
  276.  
  277.     TextDrawHideForPlayer(playerid, Digit1[3]);
  278.     TextDrawHideForPlayer(playerid, Digit2[3]);
  279.     TextDrawHideForPlayer(playerid, Digit3[3]);
  280.  
  281.     TextDrawHideForPlayer(playerid, Digit1[4]);
  282.     TextDrawHideForPlayer(playerid, Digit2[4]);
  283.     TextDrawHideForPlayer(playerid, Digit3[4]);
  284.  
  285.     TextDrawHideForPlayer(playerid, Digit1[5]);
  286.     TextDrawHideForPlayer(playerid, Digit2[5]);
  287.     TextDrawHideForPlayer(playerid, Digit3[5]);
  288.    
  289.     TextDrawHideForPlayer(playerid, Box);
  290. }
  291.  
  292. PutPlayerInSlotMachine(playerid,  firstBet=MIN_BET,   startBalance=0)
  293. {
  294.     if(Gambling[playerid] != G_STATE_NOT_GAMBLING) return print("Already gambling");
  295.    
  296.     Gambling[playerid] = G_STATE_READY;
  297.     TextDrawShowForPlayer(playerid, ReadyText);
  298.     PlayerTextDrawShow(playerid, BetText[playerid]);
  299.     TextDrawShowForPlayer(playerid, VerText);
  300.    
  301.     Slots[playerid][0] = random(5);
  302.     Slots[playerid][1] = random(5);
  303.     Slots[playerid][2] = random(5);
  304.  
  305.     ShowPlayerSlots(playerid, Slots[playerid][0], Slots[playerid][1], Slots[playerid][2]);
  306.    
  307.     Bet[playerid] = firstBet;
  308.    
  309.     GivePlayerMoney(playerid, -startBalance);
  310.    
  311.     Balance[playerid] = startBalance;
  312.    
  313.     UpdateBetText(playerid);
  314.    
  315.     TogglePlayerControllable(playerid, 0);
  316.     return 1;
  317. }
  318.  
  319. ExitPlayerFromSlotMachine(playerid)
  320. {
  321.     if(Gambling[playerid] == G_STATE_NOT_GAMBLING) return 0;
  322.     HideSlotsForPlayer(playerid);
  323.     Gambling[playerid] = G_STATE_NOT_GAMBLING;
  324.    
  325.     TogglePlayerControllable(playerid, 1);
  326.    
  327.     TextDrawHideForPlayer(playerid, ReadyText);
  328.     PlayerTextDrawHide(playerid, BetText[playerid]);
  329.     TextDrawHideForPlayer(playerid, VerText);
  330.    
  331.     new str[128];
  332.     if(Balance[playerid] > 0) format(str, sizeof(str), "~g~Your balance: %d$", Balance[playerid]);
  333.     else format(str, sizeof(str), "~r~You lost your money. Stop playing.", Balance[playerid]);
  334.     GameTextForPlayer(playerid, str, 5000, 4);
  335.    
  336.     GivePlayerMoney(playerid, Balance[playerid]);
  337.     return 1;
  338. }
  339.  
  340. public OnPlayerKeyStateChange(playerid,  newkeys,  oldkeys)
  341. {
  342.     if(newkeys & KEY_SPRINT && !(oldkeys & KEY_SPRINT))
  343.     {
  344.         // Randomize if in Slotmachine
  345.         if(Gambling[playerid] == G_STATE_READY)
  346.         {
  347.             new money = GetPlayerMoney(playerid);
  348.             if(Bet[playerid] > money+Balance[playerid])
  349.             {
  350.                 GameTextForPlayer(playerid, "~r~You don't have enough money!", 5000, 4);
  351.                 return 1;
  352.             }
  353.            
  354.             if(Balance[playerid] - Bet[playerid] < 0)
  355.             {
  356.                 GameTextForPlayer(playerid, "~r~Your balance is too low!", 5000, 4);
  357.                 return 1;
  358.             }
  359.            
  360.             SlotCounter[playerid] = 30+random(18);
  361.             SlotTimer[playerid] = SetTimerEx("Gambler", GAMBLE_TIMER, 1, "d", playerid);
  362.             Gambling[playerid] = G_STATE_GAMBLING;
  363.            
  364.             Balance[playerid]-=Bet[playerid];
  365.            
  366.             new prefix[4];
  367.             if(Balance[playerid] == 0) strcat(prefix, "~y~");
  368.             if(Balance[playerid]  > 0) strcat(prefix, "~g~");
  369.             if(Balance[playerid]  < 0) strcat(prefix, "~r~");
  370.  
  371.             UpdateBetText(playerid);
  372.            
  373.             TextDrawHideForPlayer(playerid, ReadyText);
  374.         }
  375.     }
  376.    
  377.     if(newkeys & KEY_SECONDARY_ATTACK && !(oldkeys & KEY_SECONDARY_ATTACK))
  378.     {
  379.         if(Gambling[playerid] == G_STATE_READY)
  380.         {
  381.             ExitPlayerFromSlotMachine(playerid);
  382.         }
  383.     }
  384.    
  385.     if(newkeys & KEY_JUMP && !(oldkeys & KEY_JUMP))
  386.     {
  387.         if(Gambling[playerid] == G_STATE_READY)
  388.         {
  389.             Bet[playerid] = GetNextValidBet(Bet[playerid]);
  390.             UpdateBetText(playerid);
  391.         }
  392.     }
  393.     return 1;
  394. }
  395.  
  396. forward Gambler(playerid);
  397. public Gambler(playerid)
  398. {
  399.     if(Gambling[playerid] != G_STATE_GAMBLING)
  400.     {
  401.         print("Strange error @ gambler");
  402.         KillTimer(SlotTimer[playerid]);
  403.         SlotTimer[playerid] = -1;
  404.         Gambling[playerid] = G_STATE_NOT_GAMBLING;
  405.         return 0;
  406.     }
  407.     SlotCounter[playerid] -= 1;
  408.    
  409.     new slot = SlotCounter[playerid];
  410.    
  411.     if(slot < 10)
  412.     {
  413.         Slots[playerid][2]+=random(3)+1;
  414.     }
  415.     else if(slot < 20)
  416.     {
  417.         Slots[playerid][1]+=random(3)+1;
  418.         Slots[playerid][2]+=random(3)+1;
  419.     }
  420.     else
  421.     {
  422.         Slots[playerid][0]+=random(3)+1;
  423.         Slots[playerid][1]+=random(3)+1;
  424.         Slots[playerid][2]+=random(3)+1;
  425.     }
  426.     if(Slots[playerid][0] >= 6) Slots[playerid][0] = 0;
  427.     if(Slots[playerid][1] >= 6) Slots[playerid][1] = 0;
  428.     if(Slots[playerid][2] >= 6) Slots[playerid][2] = 0;
  429.    
  430.     ShowPlayerSlots(playerid, Slots[playerid][0], Slots[playerid][1], Slots[playerid][2]);
  431.    
  432.     if(SlotCounter[playerid] == 0)
  433.     {
  434.         KillTimer(SlotTimer[playerid]);
  435.         SlotTimer[playerid] = -1;
  436.         Gambling[playerid] = G_STATE_DISPLAY;
  437.        
  438.         if(Slots[playerid][0] == Slots[playerid][1] && Slots[playerid][0] == Slots[playerid][2])
  439.         {
  440.             //printf("player %d won with %d", playerid, Slots[playerid][0]); // Uncomment this line for seeing all wins
  441.            
  442.             new Multiplier=1;
  443.            
  444.             switch(Slots[playerid][0])
  445.             {
  446.                 case 0: Multiplier = 25;    // Cherries
  447.                 case 1: Multiplier = 100;   // Grapes
  448.                 case 2: Multiplier = 250;   // 69's
  449.                 case 3: Multiplier = 500;   // Bells
  450.                 case 4: Multiplier = 1000;  // Bar
  451.                 case 5: Multiplier = 2000;  // Double Bars
  452.             }
  453.            
  454.             new money = floatround(Bet[playerid] * Multiplier * WIN_MULTIPLIER_GLOBAL);
  455.             new str[128];
  456.             format(str, sizeof(str), "~w~Winner: ~g~%d$~w~!", money);
  457.             GameTextForPlayer(playerid, str, 5000, 4);
  458.            
  459.             Balance[playerid] += money;
  460.            
  461.             UpdateBetText(playerid);
  462.            
  463.             Slots[playerid][0] = random(5); // Randomize the slots again
  464.             Slots[playerid][1] = random(5);
  465.             Slots[playerid][2] = random(5);
  466.         }
  467.         else
  468.         {
  469.             if(Slots[playerid][0] == Slots[playerid][1] || Slots[playerid][1] == Slots[playerid][2] || Slots[playerid][0] == Slots[playerid][2]) GameTextForPlayer(playerid, "Almost!", 3000, 4);
  470.             else GameTextForPlayer(playerid, "Bad luck!", 3000, 4);
  471.         }
  472.        
  473.         SetTimerEx("PlayAgainTimer", DISPLAY_TIME, 0, "d", playerid);
  474.         return 1;
  475.     }
  476.     //printf("Counter: %d", SlotCounter[playerid]);
  477.     return 0;
  478. }
  479.  
  480. forward PlayAgainTimer(playerid);
  481. public PlayAgainTimer(playerid)
  482. {
  483.     Gambling[playerid] = G_STATE_READY;
  484.     TextDrawShowForPlayer(playerid, ReadyText);
  485.    
  486.     // Remove the following 3 lines to disable the ability to hold down SPRINT
  487.     new keys, lr, ud;
  488.     GetPlayerKeys(playerid, keys, ud, lr);
  489.     if(keys & KEY_SPRINT) OnPlayerKeyStateChange(playerid, KEY_SPRINT, 0);
  490. }
  491.  
  492. GetNextValidBet(value)
  493. {
  494.     if(value + BET_STEP > MAX_BET) return MIN_BET;
  495.     return value + BET_STEP;
  496. }
  497.  
  498. UpdateBetText(playerid)
  499. {
  500.     new str[128];
  501.     new prefix[4];
  502.     if(Balance[playerid] == 0) strcat(prefix, "~r~");
  503.     if(Balance[playerid]  > 0) strcat(prefix, "~g~");
  504.    
  505.     format(str, sizeof(str), "~w~Bet: ~g~%d$_____~w~Balance: %s%d$", Bet[playerid], prefix, Balance[playerid]);
  506.     PlayerTextDrawSetString(playerid, BetText[playerid], str);
  507. }
  508.  
  509. forward RDYBLINK();
  510. public RDYBLINK()
  511. {
  512.     // This will make the "Place your bet" text blinking. Comment out the Timer at OnFilterScriptInit for disabling it.
  513.     rdy=!rdy;
  514.     if(rdy)
  515.     {
  516.         TextDrawSetString(ReadyText, "~w~Place your ~y~bet~w~!~n~~b~ ~k~~PED_SPRINT~ ~w~- ~g~gamble~n~~b~~k~~VEHICLE_ENTER_EXIT~ ~w~- ~r~exit~n~~b~~k~~PED_JUMPING~ ~w~- ~y~increase Bet");
  517.     }
  518.     else
  519.     {
  520.         TextDrawSetString(ReadyText, "_~n~~b~ ~k~~PED_SPRINT~ ~w~- ~g~gamble~n~~b~~k~~VEHICLE_ENTER_EXIT~ ~w~- ~r~exit~n~~b~~k~~PED_JUMPING~ ~w~- ~y~increase Bet");
  521.     }
  522. }
  523.  
  524. stock strtok(const string[],  &index)
  525. {
  526.     new length = strlen(string);
  527.     while ((index < length) && (string[index] <= ' '))
  528.     {
  529.         index++;
  530.     }
  531.  
  532.     new offset = index;
  533.     new result[128]; // modified to 128
  534.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  535.     {
  536.         result[index - offset] = string[index];
  537.         index++;
  538.     }
  539.     result[index - offset] = EOS;
  540.     return result;
  541. }
  542.  
  543. public OnPlayerCommandText(playerid,  cmdtext[])
  544. {
  545.     new cmd[128], idx;
  546.    
  547.     cmd = strtok(cmdtext, idx);
  548.    
  549.     if (strcmp(cmd, "/gamble",  true) == 0)
  550.     {
  551.         cmd = strtok(cmdtext, idx);
  552.        
  553.         if(!strlen(cmd)) return SendClientMessage(playerid, -1, "Use /gamble [money] to put money into the Slot Machine!");
  554.        
  555.         new money = strval(cmd);
  556.        
  557.         if(money < MIN_BET) return SendClientMessage(playerid, -1, "You have to put more money into the Slot Machine!");
  558.        
  559.         if(money > GetPlayerMoney(playerid)) return SendClientMessage(playerid, -1, "You don't have enough money!");
  560.        
  561.         PutPlayerInSlotMachine(playerid, _, money);
  562.         return 1;
  563.     }
  564.     return 0;
  565. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement