Guest User

King_Hual

a guest
Oct 17th, 2011
2,894
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <sscanf>
  4.  
  5. new Text:Horse1, Text:Horse2, Text:Horse3, Text:Horse4, Text:BG1, Text:BG2, Text:Start, Text:Finish, Text:Start2, Text:Finish2, HorseCD, Text:CDTextDraw, Text:HorseNum1, Text:HorseNum2, Text:HorseNum3, Text:HorseNum4, HorseAnimCount;
  6. new Float:HorsePosX1, Float:HorsePosX2, Float:HorsePosX3, Float:HorsePosX4, HorseStop;
  7. new Text:TimeTD, timestring[12];
  8. new MoneyBet[MAX_PLAYERS], BetOnHorse[MAX_PLAYERS], RaceStarted, Watching[MAX_PLAYERS], Prepared, Horsemsg;
  9. //Meh, I know it's alot of variables.
  10. static ServerMinutes;
  11. static ServerHours;
  12.  
  13. //Some simple defines for easier access :>
  14. #define ORANGE 0xF97804FF
  15. #define TimerTextDrawLocX 547
  16. #define TimerTextDrawLocY 2
  17. #define TimeOfHorseRaceHours 1
  18. #define TimeOfHorseRaceMinutes 20
  19. #define CashLowerBounds 100
  20. #define CashHigherBounds 50000
  21. #define RealMilisecondsPerIGMinute 2000
  22.  
  23. //I had to make these stocks as I was too lazy to type everything :D
  24. stock HorseInfo(Text:horseid)
  25. {
  26.     TextDrawFont(horseid, 4);
  27.     TextDrawColor(horseid,0xFFFFFFFF);
  28.     TextDrawTextSize(horseid,64,64);
  29. }
  30.  
  31. stock HorseNumInfo(Text:horsenumid)
  32. {
  33.     TextDrawFont(horsenumid, 4);
  34.     TextDrawColor(horsenumid,0xFFFFFFFF);
  35.     TextDrawTextSize(horsenumid,32,32);
  36. }
  37.  
  38. public OnFilterScriptInit()
  39. {
  40.     print("\n--------------------------------------");
  41.     print(" Horse Betting Track system by King_Hual");
  42.     print("--------------------------------------\n");
  43.     SetTimer("GameTimeTimer", RealMilisecondsPerIGMinute, 1);
  44.     TimeTD = TextDrawCreate(TimerTextDrawLocX, TimerTextDrawLocY, " ");
  45.     TextDrawAlignment(TimeTD,0);
  46.     TextDrawBackgroundColor(TimeTD,0x000000ff);
  47.     TextDrawFont(TimeTD,3);
  48.     TextDrawLetterSize(TimeTD,0.6,2.6);
  49.     TextDrawColor(TimeTD,0xffffffff);
  50.     TextDrawSetOutline(TimeTD,1);
  51.     TextDrawSetProportional(TimeTD,1);
  52.     TextDrawSetShadow(TimeTD,1);
  53.     RaceStarted = 0;
  54.     Prepared = 0;
  55.     Horsemsg = 1;
  56.     return 1;
  57. }
  58.  
  59. forward GameTimeTimer();
  60.  
  61. public GameTimeTimer()
  62. {
  63.     ServerMinutes++;
  64.     if(ServerMinutes == 60)
  65.     {
  66.         ServerMinutes = 0;
  67.         ServerHours++;
  68.  
  69.         if(ServerHours == 24)
  70.         {
  71.         ServerHours = 0;
  72.         }
  73.     }
  74.     format(timestring, sizeof(timestring), "%02d:%02d",ServerHours,ServerMinutes);
  75.     TextDrawSetString(TimeTD, timestring);
  76.     SetWorldTime(ServerHours);
  77.     if (ServerHours == TimeOfHorseRaceHours && ServerMinutes == TimeOfHorseRaceMinutes)
  78.     {
  79.         SendClientMessageToAll(ORANGE, "The race is starting... You can no longer place bets! Type /watch to watch it!");
  80.         for(new i = 0; i < MAX_PLAYERS; i++)
  81.         {
  82.         new Float:X[MAX_PLAYERS], Float:Y[MAX_PLAYERS], Float:Z[MAX_PLAYERS];
  83.         GetPlayerPos(i, X[i], Y[i], Z[i]);
  84.         PlayerPlaySound(i, 5410, X[i], Y[i], Z[i]);
  85.         }
  86.         SetTimer("HorseStartTimer", 2000, 0);
  87.         RaceStarted = 1;
  88.         Prepared = 0;
  89.     }
  90.     else if (ServerHours == TimeOfHorseRaceHours - 1 && ServerMinutes == TimeOfHorseRaceMinutes)
  91.     {
  92.     HorseCD = 3;
  93.     HorseStop = 0;
  94.  
  95.     BG2 = TextDrawCreate(0, 0, "LD_OTB:bckgrnd");
  96.     TextDrawFont(BG2, 4);
  97.     TextDrawColor(BG2,0xFFFFFFFF);
  98.     TextDrawTextSize(BG2,640,200);
  99.  
  100.     BG1 = TextDrawCreate(0, 0, "LD_OTB:trees");
  101.     TextDrawFont(BG1, 4);
  102.     TextDrawColor(BG1,0xFFFFFFFF);
  103.     TextDrawTextSize(BG1,640,480);
  104.  
  105.     Start2 = TextDrawCreate(-170, 145, "LD_OTB:pole2");
  106.     TextDrawFont(Start2, 4);
  107.     TextDrawColor(Start2,0xFFFFFFFF);
  108.     TextDrawTextSize(Start2,256,200);
  109.  
  110.     Finish2 = TextDrawCreate(365, 145, "LD_OTB:pole2");
  111.     TextDrawFont(Finish2, 4);
  112.     TextDrawColor(Finish2,0xFFFFFFFF);
  113.     TextDrawTextSize(Finish2,256,200);
  114.  
  115.     Horse1 = TextDrawCreate(0, 200, "LD_OTB:hrs8");
  116.     HorseInfo(Horse1);
  117.     HorsePosX1 = 0;
  118.  
  119.     Horse2 = TextDrawCreate(0, 250, "LD_OTB:hrs8");
  120.     HorseInfo(Horse2);
  121.     HorsePosX2 = 0;
  122.  
  123.     Horse3 = TextDrawCreate(0, 300, "LD_OTB:hrs8");
  124.     HorseInfo(Horse3);
  125.     HorsePosX3 = 0;
  126.  
  127.     Horse4 = TextDrawCreate(0, 350, "LD_OTB:hrs8");
  128.     HorseInfo(Horse4);
  129.     HorsePosX4 = 0;
  130.  
  131.     HorseNum1 = TextDrawCreate(15, 204, "LD_OTB2:Ric1");
  132.     HorseNumInfo(HorseNum1);
  133.  
  134.     HorseNum2 = TextDrawCreate(15, 254, "LD_OTB2:Ric2");
  135.     HorseNumInfo(HorseNum2);
  136.  
  137.     HorseNum3 = TextDrawCreate(15, 304, "LD_OTB2:Ric3");
  138.     HorseNumInfo(HorseNum3);
  139.  
  140.     HorseNum4 = TextDrawCreate(15, 354, "LD_OTB2:Ric4");
  141.     HorseNumInfo(HorseNum4);
  142.  
  143.     Start = TextDrawCreate(-170, 338, "LD_OTB:pole2");
  144.     TextDrawFont(Start, 4);
  145.     TextDrawColor(Start,0xFFFFFFFF);
  146.     TextDrawTextSize(Start,256,200);
  147.  
  148.     Finish = TextDrawCreate(365, 338, "LD_OTB:pole2");
  149.     TextDrawFont(Finish, 4);
  150.     TextDrawColor(Finish,0xFFFFFFFF);
  151.     TextDrawTextSize(Finish,256,200);
  152.  
  153.     CDTextDraw = TextDrawCreate(310,235,"3");
  154.     TextDrawAlignment(CDTextDraw,0);
  155.     TextDrawBackgroundColor(CDTextDraw,0x000000ff);
  156.     TextDrawFont(CDTextDraw,2);
  157.     TextDrawLetterSize(CDTextDraw,0.5,2);
  158.     TextDrawColor(CDTextDraw,0x00ff0099);
  159.     TextDrawSetOutline(CDTextDraw,1);
  160.     TextDrawSetProportional(CDTextDraw,1);
  161.     TextDrawSetShadow(CDTextDraw,1);
  162.  
  163.     HorseAnimCount = 1;
  164.     Prepared = 1;
  165.     for(new i = 0; i < MAX_PLAYERS; i++)
  166.     {
  167.     new Float:X[MAX_PLAYERS], Float:Y[MAX_PLAYERS], Float:Z[MAX_PLAYERS];
  168.     GetPlayerPos(i, X[i], Y[i], Z[i]);
  169.     PlayerPlaySound(i, 5401, X[i], Y[i], Z[i]);
  170.     }
  171.     SendClientMessageToAll(ORANGE, "1 Hour left until the race starts! Place your bets now by typing /bet! You can also type /watch to watch!");
  172.     }
  173. }
  174.  
  175. forward HorseStartTimer();
  176.  
  177. public HorseStartTimer()
  178. {
  179.     if (HorseCD > 0)
  180.     {
  181.     new string[128];
  182.     format(string, sizeof(string), "%d",HorseCD);
  183.     if (Horsemsg == 1)
  184.     {
  185.     SendClientMessageToAll(ORANGE, "The horse race has begun! Type /watch to watch it!");
  186.     Horsemsg = 0;
  187.     }
  188.     TextDrawColor(CDTextDraw,0xff0000ff);
  189.     TextDrawSetString(CDTextDraw, string);
  190.     HorseCD -= 1;
  191.     SetTimer("HorseStartTimer", 2000, 0);
  192.     for(new i = 0; i < MAX_PLAYERS; i++)
  193.         {
  194.         new Float:X[MAX_PLAYERS], Float:Y[MAX_PLAYERS], Float:Z[MAX_PLAYERS];
  195.         GetPlayerPos(i, X[i], Y[i], Z[i]);
  196.         PlayerPlaySound(i, 3200, X[i], Y[i], Z[i]);
  197.         }
  198.     }
  199.     else
  200.     {
  201.     TextDrawColor(CDTextDraw,0x00ff00ff);
  202.     TextDrawSetString(CDTextDraw, "Go!");
  203.     Horsemsg = 1;
  204.     for(new i = 0; i < MAX_PLAYERS; i++)
  205.         {
  206.         new Float:X[MAX_PLAYERS], Float:Y[MAX_PLAYERS], Float:Z[MAX_PLAYERS];
  207.         GetPlayerPos(i, X[i], Y[i], Z[i]);
  208.         PlayerPlaySound(i, 3201, X[i], Y[i], Z[i]);
  209.         }
  210.     SetTimer("HorseAnimTimer", 100, 0);
  211.     }
  212.     TextDrawShowForAll(CDTextDraw);
  213.     SetTimer("HorseStartHideTimer", 1000, 0);
  214.     return 1;
  215. }
  216.  
  217. COMMAND:exit(playerid, params[])
  218. {
  219.     if (Watching[playerid] == 1)
  220.     {
  221.         TogglePlayerControllable(playerid, 1);
  222.         TextDrawHideForPlayer(playerid,BG2);
  223.         TextDrawHideForPlayer(playerid,BG1);
  224.         TextDrawHideForPlayer(playerid,Start2);
  225.         TextDrawHideForPlayer(playerid,Finish2);
  226.         TextDrawHideForPlayer(playerid, Horse1);
  227.         TextDrawHideForPlayer(playerid,Horse2);
  228.         TextDrawHideForPlayer(playerid,Horse3);
  229.         TextDrawHideForPlayer(playerid,Horse4);
  230.         TextDrawHideForPlayer(playerid,HorseNum1);
  231.         TextDrawHideForPlayer(playerid,HorseNum2);
  232.         TextDrawHideForPlayer(playerid,HorseNum3);
  233.         TextDrawHideForPlayer(playerid,HorseNum4);
  234.         TextDrawHideForPlayer(playerid,Start);
  235.         TextDrawHideForPlayer(playerid,Finish);
  236.         Watching[playerid] = 0;
  237.         SendClientMessage(playerid, 0x00FF00, "You stopped watching the race");
  238.     }
  239.     return 1;
  240. }
  241.  
  242. COMMAND:watch(playerid, params[])
  243. {
  244.     if (Prepared == 1 || RaceStarted == 1)
  245.     {
  246.         TogglePlayerControllable(playerid, 0);
  247.         TextDrawShowForPlayer(playerid,BG2);
  248.         TextDrawShowForPlayer(playerid,BG1);
  249.         TextDrawShowForPlayer(playerid,Start2);
  250.         TextDrawShowForPlayer(playerid,Finish2);
  251.         TextDrawShowForPlayer(playerid, Horse1);
  252.         TextDrawShowForPlayer(playerid,Horse2);
  253.         TextDrawShowForPlayer(playerid,Horse3);
  254.         TextDrawShowForPlayer(playerid,Horse4);
  255.         TextDrawShowForPlayer(playerid,HorseNum1);
  256.         TextDrawShowForPlayer(playerid,HorseNum2);
  257.         TextDrawShowForPlayer(playerid,HorseNum3);
  258.         TextDrawShowForPlayer(playerid,HorseNum4);
  259.         TextDrawShowForPlayer(playerid,Start);
  260.         TextDrawShowForPlayer(playerid,Finish);
  261.         Watching[playerid] = 1;
  262.         SendClientMessage(playerid, 0x00FF00, "You are now watching the race");
  263.     }
  264.     else
  265.     {
  266.       SendClientMessage(playerid, 0xFFFF00FF, "The race hasn't started yet. Type /bet to bet.");
  267.     }
  268.     return 1;
  269. }
  270.  
  271. COMMAND:mybet(playerid, params[])
  272. {
  273.     if (MoneyBet[playerid] > 0 && BetOnHorse[playerid] > 0)
  274.     {
  275.         new string[128];
  276.         format(string, sizeof(string), "You have bet %d on horse number %d.",MoneyBet[playerid],BetOnHorse[playerid]);
  277.         SendClientMessage(playerid, 0x00FFFFFF, string);
  278.     }
  279.     return 1;
  280. }
  281.  
  282. COMMAND:cmds(playerid, params[])
  283. {
  284.     SendClientMessage(playerid, ORANGE, "Commands: mybet, bet, watch, exit");
  285. }
  286.  
  287. COMMAND:bet(playerid, params[])
  288. {
  289.             new horse, cash;
  290.             if(!sscanf(params,"ii",horse, cash) && horse < 5 && horse > 0 && cash <= CashHigherBounds && cash >= CashLowerBounds)
  291.             {
  292.                     if (GetPlayerMoney(playerid) >= cash)
  293.                     {
  294.                         if (RaceStarted == 1)
  295.                         {
  296.                             SendClientMessage(playerid, 0xFF0000FF, "The race has already started. You can't bet until it finishes.");
  297.                         }
  298.                             else
  299.                             {
  300.                             if (MoneyBet[playerid] > 0)
  301.                             {
  302.                                 SendClientMessage(playerid, 0xFF0000FF, "You already bet! Type /mybet to see how much money you've bet and on which horse.");
  303.                             }
  304.                             else
  305.                             {
  306.                                 MoneyBet[playerid] = cash;
  307.                                 GivePlayerMoney(playerid, -cash);
  308.                                 BetOnHorse[playerid] = horse;
  309.                                 new string[128];
  310.                                 format(string, sizeof(string), "You have just bet %d on horse number %d. Wait for the race to finish and see if you won.",MoneyBet[playerid],BetOnHorse[playerid]);
  311.                                 SendClientMessage(playerid, 0x00FFFFFF, string);
  312.                             }
  313.                         }
  314.                     }
  315.                     else
  316.                     {
  317.                         SendClientMessage(playerid, 0xFF0000FF, "You don't have that much money.");
  318.                         new Float:X, Float:Y, Float:Z;
  319.                         GetPlayerPos(playerid, X, Y, Z);
  320.                         PlayerPlaySound(playerid, 5405, X, Y, Z);
  321.                     }
  322.             }
  323.             else
  324.             {
  325.                 new string[128];
  326.                 format(string, sizeof(string), "Usage: /bet [Horse(1-4)][Ammount(%d-%d]",CashLowerBounds,CashHigherBounds);
  327.                 SendClientMessage(playerid, 0xFF0000FF,string);
  328.             }
  329.             return 1;
  330. }
  331.  
  332. forward HorseAnimTimer();
  333.  
  334. public HorseAnimTimer()
  335. {
  336.     new string[12], HorseWon;
  337.     format(string, sizeof(string), "LD_OTB:hrs%i", HorseAnimCount);
  338.     HorseAnimCount++;
  339.     if (HorseAnimCount == 9) HorseAnimCount = 1;
  340.  
  341.     HorsePosX1 = HorsePosX1 + (random(600) / 100);
  342.     HorsePosX2 = HorsePosX2 + (random(600) / 100);
  343.     HorsePosX3 = HorsePosX3 + (random(600) / 100);
  344.     HorsePosX4 = HorsePosX4 + (random(600) / 100);
  345.  
  346.     TextDrawDestroy(Horse1);
  347.     TextDrawDestroy(Horse2);
  348.     TextDrawDestroy(Horse3);
  349.     TextDrawDestroy(Horse4);
  350.     TextDrawDestroy(HorseNum1);
  351.     TextDrawDestroy(HorseNum2);
  352.     TextDrawDestroy(HorseNum3);
  353.     TextDrawDestroy(HorseNum4);
  354.  
  355.  
  356.     Horse1 = TextDrawCreate(HorsePosX1, 200, string);
  357.     HorseInfo(Horse1);
  358.     Horse2 = TextDrawCreate(HorsePosX2, 250, string);
  359.     HorseInfo(Horse2);
  360.     Horse3 = TextDrawCreate(HorsePosX3, 300, string);
  361.     HorseInfo(Horse3);
  362.     Horse4 = TextDrawCreate(HorsePosX4, 350, string);
  363.     HorseInfo(Horse4);
  364.     HorseNum1 = TextDrawCreate(HorsePosX1 + 15, 204, "LD_OTB2:Ric1");
  365.     HorseNumInfo(HorseNum1);
  366.     HorseNum2 = TextDrawCreate(HorsePosX2 + 15, 254, "LD_OTB2:Ric2");
  367.     HorseNumInfo(HorseNum2);
  368.     HorseNum3 = TextDrawCreate(HorsePosX3 + 15, 304, "LD_OTB2:Ric3");
  369.     HorseNumInfo(HorseNum3);
  370.     HorseNum4 = TextDrawCreate(HorsePosX4 + 15, 354, "LD_OTB2:Ric4");
  371.     HorseNumInfo(HorseNum4);
  372.  
  373.     for(new i = 0; i < MAX_PLAYERS; i++)
  374.         {
  375.             if (Watching[i] == 1)
  376.             {
  377.                 TextDrawShowForPlayer(i,Horse1);
  378.                 TextDrawShowForPlayer(i,Horse2);
  379.                 TextDrawShowForPlayer(i,Horse3);
  380.                 TextDrawShowForPlayer(i,Horse4);
  381.                 TextDrawShowForPlayer(i,HorseNum1);
  382.                 TextDrawShowForPlayer(i,HorseNum2);
  383.                 TextDrawShowForPlayer(i,HorseNum3);
  384.                 TextDrawShowForPlayer(i,HorseNum4);
  385.             }
  386.         }
  387.  
  388.     if (HorsePosX1 >= 560)
  389.     {
  390.     SendClientMessageToAll(ORANGE, "Horse 1 won!");
  391.     HorseStop = 1;
  392.     HorseWon = 1;
  393.     }
  394.     else if (HorsePosX2 >= 560)
  395.     {
  396.     SendClientMessageToAll(ORANGE, "Horse 2 won!");
  397.     HorseStop = 1;
  398.     HorseWon = 2;
  399.     }
  400.     else if (HorsePosX3 >= 560)
  401.     {
  402.     SendClientMessageToAll(ORANGE, "Horse 3 won!");
  403.     HorseStop = 1;
  404.     HorseWon = 3;
  405.     }
  406.     else if (HorsePosX4 >= 560)
  407.     {
  408.     SendClientMessageToAll(ORANGE, "Horse 4 won!");
  409.     HorseStop = 1;
  410.     HorseWon = 4;
  411.     }
  412.     if (HorseStop == 0)
  413.     {
  414.     SetTimer("HorseAnimTimer", 100, 0);
  415.     }
  416.     else
  417.     {
  418.     HorseStop = 1;
  419.     RaceStarted = 0;
  420.     TextDrawDestroy(BG2);
  421.     TextDrawDestroy(BG1);
  422.     TextDrawDestroy(Start2);
  423.     TextDrawDestroy(Finish2);
  424.     TextDrawDestroy(Horse1);
  425.     TextDrawDestroy(Horse2);
  426.     TextDrawDestroy(Horse3);
  427.     TextDrawDestroy(Horse4);
  428.     TextDrawDestroy(HorseNum1);
  429.     TextDrawDestroy(HorseNum2);
  430.     TextDrawDestroy(HorseNum3);
  431.     TextDrawDestroy(HorseNum4);
  432.     TextDrawDestroy(Start);
  433.     TextDrawDestroy(Finish);
  434.     for(new i = 0; i < MAX_PLAYERS; i++)
  435.     {
  436.         if (BetOnHorse[i] == HorseWon)
  437.         {
  438.             new Float:X[MAX_PLAYERS], Float:Y[MAX_PLAYERS], Float:Z[MAX_PLAYERS];
  439.             GetPlayerPos(i, X[i], Y[i], Z[i]);
  440.             PlayerPlaySound(i, 5448, X[i], Y[i], Z[i]);
  441.             SendClientMessage(i, 0xFFFF00FF, "You won! The money you bet have been doubled!");
  442.             GivePlayerMoney(i, MoneyBet[i] * 2);
  443.         }
  444.         else if (MoneyBet[i] != 0 && BetOnHorse[i] != HorseWon)
  445.         {
  446.             SendClientMessage(i, 0xFFFF00FF, "Sorry but you didn't win!");
  447.             new Float:X[MAX_PLAYERS], Float:Y[MAX_PLAYERS], Float:Z[MAX_PLAYERS];
  448.             GetPlayerPos(i, X[i], Y[i], Z[i]);
  449.             PlayerPlaySound(i, 5453, X[i], Y[i], Z[i]);
  450.         }
  451.         if (Watching[i] == 1)
  452.         {
  453.             TogglePlayerControllable(i, 1);
  454.         }
  455.     }
  456. }
  457. }
  458.  
  459. forward HorseStartHideTimer();
  460.  
  461. public HorseStartHideTimer()
  462. {
  463.     TextDrawHideForAll(CDTextDraw);
  464. }
  465.  
  466. public OnPlayerConnect(playerid)
  467. {
  468.     Watching[playerid] = 0;
  469.     TextDrawShowForPlayer(playerid, TimeTD);
  470.     return 1;
  471. }
  472.  
  473. public OnPlayerDisconnect(playerid, reason)
  474. {
  475.     MoneyBet[playerid] = 0;
  476.     BetOnHorse[playerid] = 0;
  477.     Watching[playerid] = 0;
  478.     return 1;
  479. }
  480.  
  481. public OnPlayerSpawn(playerid)
  482. {
  483.     GivePlayerMoney(playerid, 10000);
  484.     return 1;
  485. }
  486.  
  487. public OnPlayerRequestSpawn(playerid)
  488. {
  489.     if (RaceStarted == 1)
  490.     {
  491.         SendClientMessage(playerid, 0xFF0000FF, "A race is in proggress. Type /join to join.");
  492.     }
  493.     return 1;
  494. }
  495.  
RAW Paste Data