Hiddos

Shit-Yourself-Rich v1.0

Feb 24th, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.75 KB | None | 0 0
  1. #include <a_samp>
  2. #define BETTING_ENTRANCE_TIME 180 // seconds after first bet before the 'race' actually starts
  3. #define DIALOG_INDEX 1543
  4. #define SC_INTERVAL 5000
  5. new secfence;
  6. new Float:field[2][2] = {{-1122.3,-1290.1}, {-1065.4104,-1255.9333}};
  7. new info_pickup;
  8.  
  9. new shouldcall[MAX_PLAYERS];
  10.  
  11. new bool:firstvisit[MAX_PLAYERS] = {true, true, ...};
  12. enum pBet {
  13.     bool:hasbet,
  14.     sumbet,
  15.     Float:betPos[3],
  16.     bool:isbetting,
  17. //  betflag,
  18.     Text3D:bettext,
  19. }
  20. new Bets[MAX_PLAYERS][pBet];
  21. new betvehicles[MAX_PLAYERS];
  22.  
  23. new cur_bets = 0;
  24. new timer;
  25. new cow;
  26. new cstate = 0;
  27. new ccd = 0;
  28. // 0 = nothing
  29. // 1 = timer running
  30. // 2 = cow raising
  31. // 3 = cow raving
  32. // 4 = cow shitting/win
  33.  
  34. public OnFilterScriptInit()
  35. {
  36.     secfence = CreateObject(3276, -1093.8, -1255.3, 129.1, 0.0, 0.0, 0.0);
  37.     info_pickup = CreatePickup(1239, 1, -1078.2122,-1247.8104,129.2188);
  38.     return 1;
  39. }
  40.  
  41. public OnFilterScriptExit()
  42. {
  43.     if(cstate != 0 ) KillTimer(timer);
  44.     DestroyObject(secfence);
  45.     DestroyPickup(info_pickup);
  46.     for(new i; i != MAX_PLAYERS; i++)
  47.     {
  48.         if(Bets[i][hasbet] == true)
  49.         {
  50.             Delete3DTextLabel(Bets[i][bettext]);
  51.         }
  52.         else if(Bets[i][isbetting] == true)
  53.         {
  54.             SetPlayerPos(i, -1078.2122,-1245.8104,129.2188);
  55.             DestroyVehicle(betvehicles[i]);
  56.         }
  57.     }
  58.     if(cstate >= 2)
  59.     {
  60.         DestroyObject(cow);
  61.     }
  62.     return 1;
  63. }
  64.  
  65. public OnPlayerConnect(playerid)
  66. {
  67.     firstvisit[playerid] = true;
  68.     shouldcall[playerid] = 0;
  69.     GivePlayerMoney(playerid, 200000); // debug
  70.     //print("kankeraids");
  71.     return 1;
  72. }
  73.  
  74. public OnPlayerDisconnect(playerid, reason)
  75. {
  76.     if(Bets[playerid][hasbet] == true)
  77.     {
  78.         Delete3DTextLabel(Bets[playerid][bettext]);
  79.         Bets[playerid][hasbet] = false;
  80.     }
  81.     else if(Bets[playerid][isbetting] == true)
  82.     {
  83.         DestroyVehicle(betvehicles[playerid]);
  84.         Bets[playerid][isbetting] = false;     
  85.     }
  86.     return 1;
  87. }
  88.  
  89. public OnPlayerPickUpPickup(playerid, pickupid)
  90. {
  91.     //print("t1");
  92.     if(shouldcall[playerid] == -1 || GetTickCount() < shouldcall[playerid] || IsPlayerInAnyVehicle(playerid)) return 1;
  93.     //print("t2");
  94.     if(pickupid == info_pickup)
  95.     {
  96.         if(firstvisit[playerid] == true)
  97.         {
  98.             new str[406];
  99.             strins(str, "{FFFFFF}Welcome to '{1874CD}Shit Yourself Rich{FFFFFF}'!\n\nIn this fun little minigame, you get to plant a {00FF00}marker{FFFFFF} somewhere in this field. A {FF0000}cow{FFFFFF} will then be let loose on the field. After a quick while, the cow will take a poop. If the {FF0000}cow{FFFFFF} poops close enough to your {00FF00}marker{FFFFFF}, you'll receive price money!\n\nTake a chance, and Shit Yourself Rich!", 0);
  100.  
  101.             ShowPlayerDialog(playerid, DIALOG_INDEX + 1, DIALOG_STYLE_MSGBOX, "Shit Yourself Rich!",str, "Ok", "");
  102.         }
  103.         else
  104.         {
  105.             if(Bets[playerid][hasbet] == false) { ShowPlayerDialog(playerid, DIALOG_INDEX + 0, DIALOG_STYLE_LIST, "Shit Yourself Rich!", "Welcome\nPlace Bet\nLeave", "Choose", ""); }
  106.             else { ShowPlayerDialog(playerid, DIALOG_INDEX + 0, DIALOG_STYLE_LIST, "Shit Yourself Rich!", "Welcome\nReview Bet\nLeave", "Choose", ""); }
  107.         }
  108.     }
  109.     shouldcall[playerid] = -1;
  110.     return 1;
  111. }
  112.  
  113. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  114. {
  115.     switch(dialogid)
  116.     {
  117.         case DIALOG_INDEX + 0: // the menu
  118.         {
  119.             if(response == 0)
  120.             {
  121.                 shouldcall[playerid] = GetTickCount() + SC_INTERVAL;
  122.                 return 1;
  123.             }
  124.             switch(listitem)
  125.             {
  126.                 case 0: //Welcome
  127.                 {
  128.                     new str[410];
  129.                     strins(str, "{FFFFFF}Welcome to '{1874CD}Shit Yourself Rich{FFFFFF}'!\n\nIn this fun little minigame, you get to plant a {00FF00}marker{FFFFFF} somewhere in this field. A {FF0000}cow{FFFFFF} will then be let loose on the field. After a quick while, the cow will take a poop. If the {FF0000}cow{FFFFFF} poops close enough to your {00FF00}marker{FFFFFF}, you'll receive price money!\n\nTake a chance, and Shit Yourself Rich!", 0);
  130.                     //printf("len because fucking aids: %i", str);
  131.                     ShowPlayerDialog(playerid, DIALOG_INDEX + 1, DIALOG_STYLE_MSGBOX, "Shit Yourself Rich!",str, "Ok", "");
  132.                     return 1;
  133.                 }
  134.                 case 1: //review/place bet
  135.                 {
  136.                     if(cstate >= 2)
  137.                     {
  138.                         ShowPlayerDialog(playerid, DIALOG_INDEX + 3, DIALOG_STYLE_MSGBOX, "Shit Yourself Rich!", "Sorry, you're too late! The game has already begun! Come back later!", "Ok", "");
  139.                     }
  140.                     if(Bets[playerid][hasbet] == true)  //  review bet
  141.                     {
  142.                         new str[128];
  143.                         format(str, sizeof str, "You've placed a bet of {FF5721}$%i{FFFFFF}! There's no backing out now anymore!", Bets[playerid][sumbet]);
  144.                         ShowPlayerDialog(playerid, DIALOG_INDEX + 3, DIALOG_STYLE_MSGBOX, "Shit Yourself Rich!", str, "Ok", "");
  145.                     }
  146.                     else ShowPlayerDialog(playerid, DIALOG_INDEX + 2, DIALOG_STYLE_INPUT, "Shit Yourself Rich!", "Please enter the amount of money you'd like to bet:", "Bet", "Cancel");
  147.                     return 1;
  148.                 }
  149.                 case 2:
  150.                 {
  151.                     shouldcall[playerid] = GetTickCount() + SC_INTERVAL;
  152.                     return 1; //Leave
  153.                 }
  154.             }
  155.         }
  156.         case DIALOG_INDEX + 1:
  157.         {
  158.             if(response == 0 && firstvisit[playerid] == true)
  159.             {
  160.                 firstvisit[playerid] = false;
  161.                 return 1;
  162.             }
  163.             firstvisit[playerid] = false;
  164.             if(Bets[playerid][hasbet] == false) { ShowPlayerDialog(playerid, DIALOG_INDEX + 0, DIALOG_STYLE_LIST, "Shit Yourself Rich!", "Welcome\nPlace Bet\nLeave", "Choose", ""); }
  165.             else { ShowPlayerDialog(playerid, DIALOG_INDEX + 0, DIALOG_STYLE_LIST, "Shit Yourself Rich!", "Welcome\nReview Bet\nLeave", "Choose", ""); }
  166.             return 1;
  167.         }
  168.         case DIALOG_INDEX + 2:
  169.         {
  170.             if(cstate >= 2) return ShowPlayerDialog(playerid, DIALOG_INDEX + 3, DIALOG_STYLE_MSGBOX, "Shit Yourself Rich!", "Sorry, you're too late! The game has already begun! Come back later!", "Ok", ""), 0;
  171.             if(response == 0) return ShowPlayerDialog(playerid, DIALOG_INDEX + 0, DIALOG_STYLE_LIST, "Shit Yourself Rich!", "Welcome\nPlace Bet\nLeave", "Choose", ""), 1;
  172.             new bet = strval(inputtext);
  173.             if(bet <= 0) return ShowPlayerDialog(playerid, DIALOG_INDEX + 2, DIALOG_STYLE_INPUT, "Shit Yourself Rich!", "{FF2222}Please bet a minimum of at least $1!\n\n{FFFFFF}Please enter the amount of money you'd like to bet:", "Bet", "Cancel"), 1;
  174.             else if(bet > GetPlayerMoney(playerid)) return ShowPlayerDialog(playerid, DIALOG_INDEX + 2, DIALOG_STYLE_INPUT, "Shit Yourself Rich!", "{FF2222}You don't have that much money!\n\n{FFFFFF}Please enter the amount of money you'd like to bet:", "Bet", "Cancel"), 1;
  175.             Bets[playerid][isbetting] = true;
  176.             Bets[playerid][sumbet] = bet;
  177.             betvehicles[playerid] = CreateVehicle(594, -1100.0, -1270.0, 129.1, 0.0, -1, -1, 0);
  178.             PutPlayerInVehicle(playerid, betvehicles[playerid], 0);
  179.             ShowPlayerDialog(playerid, DIALOG_INDEX + 4, DIALOG_STYLE_MSGBOX, "Shit Yourself Rich!", "Thank you for placing a bet! You must now drive around the flower pot to your desired {00FF00}marker location{FFFFFF}.\nYou must then exit the vehicle to register your bet!", "Ok", "");
  180.             shouldcall[playerid] = 0;
  181.         }
  182.         case DIALOG_INDEX + 3: return ShowPlayerDialog(playerid, DIALOG_INDEX + 0, DIALOG_STYLE_LIST, "Shit Yourself Rich!", "Welcome\nReview Bet\nLeave", "Choose", "") , 1; // review bet
  183.         case DIALOG_INDEX + 4: return 1; // Bet Confirm
  184.     }
  185.     return 1;
  186. }
  187.  
  188. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  189. {
  190.     if(Bets[playerid][isbetting] == true && (newkeys & KEY_HANDBRAKE || newkeys & KEY_SECONDARY_ATTACK))
  191.     {
  192.         GetVehiclePos(betvehicles[playerid], Bets[playerid][betPos][0], Bets[playerid][betPos][1], Bets[playerid][betPos][2]);
  193.         SetPlayerPos(playerid, -1078.2122,-1245.8104,129.2188);
  194.         Bets[playerid][isbetting] = false;
  195.         Bets[playerid][hasbet] = true;
  196.         GivePlayerMoney(playerid, -Bets[playerid][sumbet]);
  197.         new str[MAX_PLAYER_NAME];
  198.         GetPlayerName(playerid, str, MAX_PLAYER_NAME);
  199.         //printf("str: %s", str);
  200.         //printf("loc: %.3f %.3f %.3f", Bets[playerid][betPos][0], Bets[playerid][betPos][1], Bets[playerid][betPos][2]);
  201.         Bets[playerid][bettext] = Create3DTextLabel(str, 0x00FF00FF, Bets[playerid][betPos][0], Bets[playerid][betPos][1], Bets[playerid][betPos][2] + 3.4, 180.0, 0);
  202.         DestroyVehicle(betvehicles[playerid]);
  203.         cur_bets++;
  204.         if(cur_bets == 1)
  205.         {
  206.             new str2[148];
  207.             format(str2, sizeof str2, "{00FF00}%s{FFFFFF} has initiated the 'Shit-Yourself-Rich!' minigame! You have {FF0000}3{FFFFFF} minutes until the cow is let loose!", str);
  208.             SendClientMessageToAll(-1, str2);
  209.             timer = SetTimer("cowRaise", 3 * 60 * 1000, false);
  210.             cstate = 1;
  211.         }
  212.     }
  213.     return 1;
  214. }
  215.  
  216. forward cowRaise();
  217. public cowRaise()
  218. {
  219.     //print("1");
  220.  
  221.     for(new i; i != MAX_PLAYERS; i++)
  222.     {
  223.         if(Bets[i][isbetting] == true)
  224.         {
  225.             Bets[i][isbetting] = false;
  226.             DestroyVehicle(betvehicles[i]);
  227.             SetPlayerPos(i, -1078.2122,-1245.8104,129.2188);
  228.             SendClientMessage(i, -1, "Sorry, you're too late. The game has already started!");
  229.         }
  230.     }
  231.  
  232.     cstate = 2;
  233.     new Float:fieldX = field[0][0] + random(floatround(field[1][0]-field[0][0]));
  234.     new Float:fieldY = field[0][1] + random(floatround(field[1][1]-field[0][1]));
  235.     //printf("loc: %.3f %.3f", fieldX, fieldY);
  236.     //print("shoulder");
  237.     cow = CreateObject(16442, fieldX, fieldY, 129.2188 - 1.0, 0.0, 0.0, random(360));
  238.     MoveObject(cow, fieldX, fieldY, 129.2188 + 0.8, 1.0);
  239.     //print("knee");
  240. }
  241.  
  242. public OnObjectMoved(objectid)
  243. {
  244.     if(objectid == cow)
  245.     {
  246.         switch(cstate)
  247.         {
  248.             case 0..1: return 1;
  249.             case 2:
  250.             {
  251.                 //print("2");
  252.                 cstate = 3;
  253.                 timer = SetTimer("MoveCowToRandomLoc", random(3000), false);
  254.                 return 1;
  255.             }
  256.             case 3:
  257.             {
  258.                 //print("2i");
  259.                 new yn = random(8);
  260.                 //printf("yn: %i", yn);
  261.                 if(yn == 0)
  262.                 {
  263.                     //print("4");
  264.                     cstate = 4;
  265.                     ccd = 12;
  266.                     timer = SetTimer("CowPoop", random(4000), false);
  267.                 }
  268.                 else
  269.                 {
  270.                     //print("3");
  271.                     timer = SetTimer("MoveCowToRandomLoc", random(3000), false);
  272.                 }
  273.                 return 1;
  274.             }
  275.         }
  276.     }
  277.     return 1;
  278. }
  279.  
  280. forward MoveCowToRandomLoc();
  281. public MoveCowToRandomLoc()
  282. {
  283.  
  284.     new Float:x, Float:y, Float:oldpos[3];
  285.     GetObjectPos(cow, oldpos[0], oldpos[1], oldpos[2]);
  286.     x = field[0][0] + random(floatround(field[1][0] - field[0][0]));
  287.     y = field[0][1] + random(floatround(field[1][1] - field[0][1]));
  288.    
  289.     oldpos[2] = atan((y - oldpos[1]) / (x - oldpos[0]));
  290.     if(x < oldpos[0]) oldpos[2] += -180.0;
  291.     oldpos[2] -= 2.0;
  292.  
  293.     SetObjectRot(cow, 0.0, 0.0, oldpos[2]);
  294.     MoveObject(cow, x, y, 129.2188 + 0.8, 3.8);
  295. }
  296.  
  297. forward CowPoop();
  298. public CowPoop()
  299. {
  300.     ccd--;
  301.     if(ccd == 0)
  302.     {
  303.         new Float:loc[3];
  304.         GetObjectPos(cow, loc[0], loc[1], loc[2]);
  305.         CreateExplosion(loc[0], loc[1], loc[2], 1, 0.2);
  306.         for(new i; i != MAX_PLAYERS; i++)
  307.         {
  308.             if(Bets[i][hasbet] == true)
  309.             {
  310.                 new Float:range = 16.0 - floatsqroot((floatpower(loc[0] - Bets[i][betPos][0], 2) + floatpower(loc[1] - Bets[i][betPos][1], 2)));
  311.                 //printf("range: %.3f", range);
  312.                 if(range <= 0.0)
  313.                 {
  314.                     SendClientMessage(i, -1, "Sorry, you didn't win anything this round!");
  315.                     continue;
  316.                 }
  317.                 new str[128];
  318.                 new win = floatround(range * float(Bets[i][sumbet]));
  319.                 GivePlayerMoney(i, win);
  320.                 format(str, sizeof str, "Congratulations! The Cow took a dump {00FF00}%.2f{FFFFFF} m away from your marker! You've won ${FFFF00}%i{FFFFFF}!", 16.0 - range - 1.0, win);
  321.                 SendClientMessage(i, -1, str);
  322.             }
  323.         }
  324.         SetTimer("CleanThisShitUp", 30 * 1000, false);
  325.     }
  326.     else
  327.     {
  328.         //print("sup yo");
  329.         new Float:rot[3];
  330.         GetObjectRot(cow, rot[0], rot[1], rot[2]);
  331.         SetObjectRot(cow, float(random(20)) - 10.0, float(random(20)) - 10.0, rot[2]);
  332.         GetObjectPos(cow, rot[0], rot[1], rot[1]);
  333.         CreateExplosion(rot[0] - 1.2 + (float(random(24))/10.0), rot[1] - 1.2 + (float(random(24))/10.0), rot[1] - 0.60, 12, 0.1);
  334.         timer = SetTimer("CowPoop", 170, false);
  335.     }
  336. }
  337.  
  338. forward CleanThisShitUp();
  339. public CleanThisShitUp()
  340. {
  341.     DestroyObject(cow);
  342.     for(new i; i != MAX_PLAYERS; i++)
  343.     {
  344.         if(Bets[i][hasbet] == true)
  345.         {
  346.             Bets[i][hasbet] = false;
  347.             Delete3DTextLabel(Bets[i][bettext]);
  348.         }
  349.     }
  350.     cstate = 0;
  351.     cur_bets = 0;
  352. }
Advertisement
Add Comment
Please, Sign In to add comment