Guest User

Drift FS 1.0

a guest
May 8th, 2010
2,716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.40 KB | None | 0 0
  1. /*Drifting script by Joos ([email protected])*/
  2.  
  3. #include <a_samp>
  4. #define MaximumPlayers 50 //Server-specific variable. PLEASE CHANGE ACCORDING TO YOUR SERVER!
  5.  
  6. //drifting shizzle
  7. new bool:DriftingState[MaximumPlayers]; //Array for storing whether or not the player is drifting. Kept it as a var instead of a pvar because pvars have no bools.
  8. new bool:ScoreState[MaximumPlayers]; //Array for checking whether or not the car is scoring points. Still loving the booleans.
  9. new Float:TDirection, //Travelling direction
  10.     Float:CDirection, //Car facing direction
  11.     Float:DriftAngle, //The resulting difference between the two corners
  12.     Float:speed;
  13. new Score[MaximumPlayers]; //Current drift score. Left this as a normal var instead of a PVar because the code adds and subtracts A LOT in this array and I don't want 50 function calls every second per player.
  14. new string[64]; //Used everywhere.
  15.  
  16. //textdraws
  17. new Text:DrawSpeedBonus[MaximumPlayers]; //speed
  18. new Text:DrawAngleBonus[MaximumPlayers]; //angle
  19. new Text:DrawScore[MaximumPlayers]; //current
  20. new Text:DrawLastScore[MaximumPlayers]; //last
  21. new Text:DrawBestScore[MaximumPlayers]; //best
  22.  
  23. public OnPlayerConnect(playerid)
  24. {
  25.     DrawScore[playerid] = TextDrawCreate(484.000000, 102.000000, "This drift: 0");
  26.     TextDrawBackgroundColor(DrawScore[playerid], 255);
  27.     TextDrawFont(DrawScore[playerid], 1);
  28.     TextDrawLetterSize(DrawScore[playerid], 0.500000, 1.000000);
  29.     TextDrawColor(DrawScore[playerid], -16776961);
  30.     TextDrawSetOutline(DrawScore[playerid], 1);
  31.     TextDrawSetProportional(DrawScore[playerid], 1);
  32.  
  33.     DrawBestScore[playerid] = TextDrawCreate(484.000000, 122.000000, "Max drift: 0");
  34.     TextDrawBackgroundColor(DrawBestScore[playerid], 255);
  35.     TextDrawFont(DrawBestScore[playerid], 1);
  36.     TextDrawLetterSize(DrawBestScore[playerid], 0.500000, 1.000000);
  37.     TextDrawColor(DrawBestScore[playerid], -16776961);
  38.     TextDrawSetOutline(DrawBestScore[playerid], 1);
  39.     TextDrawSetProportional(DrawBestScore[playerid], 1);
  40.  
  41.     DrawLastScore[playerid] = TextDrawCreate(485.000000, 112.000000, "Last drift: 0");
  42.     TextDrawBackgroundColor(DrawLastScore[playerid], 255);
  43.     TextDrawFont(DrawLastScore[playerid], 1);
  44.     TextDrawLetterSize(DrawLastScore[playerid], 0.500000, 1.000000);
  45.     TextDrawColor(DrawLastScore[playerid], -16776961);
  46.     TextDrawSetOutline(DrawLastScore[playerid], 1);
  47.     TextDrawSetProportional(DrawLastScore[playerid], 1);
  48.    
  49.     DrawSpeedBonus[playerid] = TextDrawCreate(606.000000, 133.000000, "Speed bonus!");
  50.     TextDrawAlignment(DrawSpeedBonus[playerid], 3);
  51.     TextDrawBackgroundColor(DrawSpeedBonus[playerid], 255);
  52.     TextDrawFont(DrawSpeedBonus[playerid], 1);
  53.     TextDrawLetterSize(DrawSpeedBonus[playerid], 0.500000, 1.000000);
  54.     TextDrawColor(DrawSpeedBonus[playerid], 16711935);
  55.     TextDrawSetOutline(DrawSpeedBonus[playerid], 1);
  56.     TextDrawSetProportional(DrawSpeedBonus[playerid], 1);
  57.  
  58.     DrawAngleBonus[playerid] = TextDrawCreate(606.000000, 143.000000, "Angle bonus!");
  59.     TextDrawAlignment(DrawAngleBonus[playerid], 3);
  60.     TextDrawBackgroundColor(DrawAngleBonus[playerid], 255);
  61.     TextDrawFont(DrawAngleBonus[playerid], 1);
  62.     TextDrawLetterSize(DrawAngleBonus[playerid], 0.500000, 1.000000);
  63.     TextDrawColor(DrawAngleBonus[playerid], 16711935);
  64.     TextDrawSetOutline(DrawAngleBonus[playerid], 1);
  65.     TextDrawSetProportional(DrawAngleBonus[playerid], 1);
  66.  
  67.     SendClientMessage(playerid, 0xAAFFFFFF, "Type /drifthelp for drifting help.");
  68. }
  69.  
  70. public OnPlayerCommandText(playerid, cmdtext[])
  71. {
  72.     if (strcmp("/drifthelp", cmdtext, true, 10) == 0)
  73.     {
  74.         SendClientMessage(playerid, 0xFFAAFF, "Type /drift to start drifting.");
  75.         SendClientMessage(playerid, 0xFFAAFF, "The aim is to get as many points as possible with drifting.");
  76.         SendClientMessage(playerid, 0xFFAAFF, "Getting high scores will upgrade your car with tuning parts.");
  77.         SendClientMessage(playerid, 0xFFAAFF, "The amount of points needed varies with each car. Elegy is the most demanding with a max of 200");
  78.         SendClientMessage(playerid, 0xFFAAFF, "Also, your car will be fixed and equipped with NOS every time you get 70 or more points.");
  79.         SendClientMessage(playerid, 0xFFAAFF, "In order for the drift to count, you must be sliding at an angle of 15 degrees or higher.");
  80.         SendClientMessage(playerid, 0xFFAAFF, "More points will be given if the angle is above 25 degrees and the optimal bonus is given between 35-45 degrees.");
  81.         SendClientMessage(playerid, 0xFFAAFF, "Also, you can't drift at low speeds. High speeds will provide another bonus, though!");
  82.         SendClientMessage(playerid, 0xFFAAFF, "You can also link your drifts, but the combos will be broken when the car is damaged or when you drive too slow!");
  83.         SendClientMessage(playerid, 0xFFAAFF, "Remember to use your handbrake, countersteer, control your throttle and have fun!");
  84.         return 1;
  85.     }
  86.    
  87.     if (strcmp("/drift", cmdtext, true, 6) == 0)
  88.     {
  89.         if ((DriftingState[playerid] == false) && (IsPlayerInAnyVehicle(playerid)==1))
  90.         {
  91.             DriftingState[playerid]=true;
  92.             SendClientMessage(playerid, 0xFFFFFF, "Drifting mode is ON");
  93.             TextDrawShowForPlayer(playerid,DrawScore[playerid]);
  94.             TextDrawShowForPlayer(playerid,DrawLastScore[playerid]);
  95.             TextDrawShowForPlayer(playerid,DrawBestScore[playerid]);
  96.         }
  97.         else if (DriftingState[playerid] == true)
  98.         {
  99.             CancelDrifting(playerid);
  100.             SendClientMessage(playerid, 0xFFFFFF, "Drifting mode is OFF");
  101.         }
  102.         if (IsPlayerInAnyVehicle(playerid)==0)
  103.         {
  104.             SendClientMessage(playerid, 0xFFFFFF, "Get in a car to start drifting!");
  105.         }
  106.         return 1;
  107.     }
  108.     return 0;
  109. }
  110.  
  111. public OnPlayerUpdate(playerid)
  112. {
  113.     if (DriftingState[playerid] == true)
  114.     {
  115.         Drifting(playerid);
  116.     }
  117.     return 1;
  118. }
  119.  
  120. forward Drifting(playerid);
  121. public Drifting(playerid)
  122. {
  123.     /*Speed calculation*/
  124.     new Float:x, Float:y, Float:z, vid;
  125.     vid = GetPlayerVehicleID(playerid);
  126.     GetVehicleVelocity(vid, x, y, z);
  127.     speed = floatpower(x*x+y*y, 0.5);
  128.     if (speed > 0.2)
  129.     {
  130.         /*Trig functions for calculating moving(travelling) direction*/
  131.         if (x<0)
  132.         {
  133.             if(y>0)
  134.                 { TDirection = atan(floatabs(x/y)); }
  135.             else if (y<=0)
  136.                 { TDirection = atan(y/x) + 90; }
  137.         }
  138.         else if (x>0)
  139.         {
  140.             if(y<0)
  141.                 { TDirection = atan(floatabs(x/y)) + 180; }
  142.             else if (y>=0)
  143.                 { TDirection = atan(y/x) + 270; }
  144.         }
  145.         else if (x==0)
  146.         {
  147.             if (y>0)
  148.                 { TDirection = 0; }
  149.             else if (y<0)
  150.                 { TDirection = 180; }
  151.         }
  152.         /*Calculations for drifting angle*/
  153.         GetVehicleZAngle(vid, CDirection);
  154.         DriftAngle = floatabs(TDirection - CDirection);
  155.         /*Adding score*/
  156.         if ((15 < DriftAngle < 80) || ( 280 < DriftAngle < 345)) //At least a 15 degree angle is required to score anything
  157.         {
  158.             ScoreState[playerid] = true;
  159.             Score[playerid]++;
  160.             if ((25 < DriftAngle < 70) || (290 < DriftAngle < 335)) //At least a 25 degree angle is required to score 2 points
  161.             {
  162.                 Score[playerid]++;
  163.                 if ((35 < DriftAngle < 45) || (315 < DriftAngle < 325)) //35-45 degree drifts receive additional bonuses
  164.                 {
  165.                     Score[playerid]++;
  166.                     SetPVarInt(playerid, "AngleBonus", GetPVarInt(playerid, "AngleBonus")+1);
  167.                     format(string,sizeof(string),"Angle Bonus + %d !", GetPVarInt(playerid, "AngleBonus"));
  168.                     TextDrawSetString(DrawAngleBonus[playerid], string);
  169.                     TextDrawShowForPlayer(playerid, DrawAngleBonus[playerid]);
  170.                 }
  171.             }
  172.             if (speed > 0.6)
  173.                 {
  174.                     Score[playerid]++;
  175.                     SetPVarInt(playerid, "SpeedBonus", GetPVarInt(playerid, "SpeedBonus")+1);
  176.                     format(string,sizeof(string),"Speed Bonus + %d !", GetPVarInt(playerid, "SpeedBonus"));
  177.                     TextDrawSetString(DrawSpeedBonus[playerid], string);
  178.                     TextDrawShowForPlayer(playerid, DrawSpeedBonus[playerid]);
  179.                 }
  180.             format(string, sizeof(string), "This drift: %d", Score[playerid]);
  181.             TextDrawSetString(DrawScore[playerid], string);
  182.             }
  183.         /*When the player stops drifting*/
  184.         else if (Score[playerid]>0)
  185.         {
  186.             if (ScoreState[playerid] == true)
  187.             {
  188.                 if (Score[playerid] > GetPVarInt(playerid, "MaxScore"))
  189.                 {
  190.                     SetPVarInt(playerid, "MaxScore", Score[playerid]);
  191.                     DriftRewards(vid, Score[playerid]); //Comment this line if you want to disable tuning rewards.
  192.                     if (Score[playerid] > GetPVarInt(playerid, "AbsMaxScore"))
  193.                     {
  194.                         SetPVarInt(playerid, "AbsMaxScore", Score[playerid]);
  195.                         format(string,sizeof(string),"Max drift: %d",GetPVarInt(playerid,"AbsMaxScore"));
  196.                         TextDrawSetString(DrawBestScore[playerid], string);
  197.                         SetPlayerScore(playerid, Score[playerid]); //Comment this line if you want to disable score updating(under TAB)
  198.                     }
  199.                     else
  200.                     {
  201.                         format(string,sizeof(string),"Last drift: %d",Score[playerid]);
  202.                         TextDrawSetString(DrawLastScore[playerid], string);
  203.                     }
  204.                 }
  205.                 else
  206.                 {
  207.                     format(string,sizeof(string),"Last drift %d",Score[playerid]);
  208.                     TextDrawSetString(DrawLastScore[playerid], string);
  209.                     if (Score[playerid] > 70) //comment this bracket section if you don't want NOS/fixing with scoring (for example, when you have your own autofix)
  210.                     {
  211.                         RepairVehicle(vid);
  212.                         SetVehicleHealth(vid, 1000);
  213.                         AddVehicleComponent(vid, 1009); //2x nos
  214.                     }
  215.                 }
  216.                 ScoreState[playerid] = false;
  217.             }
  218.             TextDrawHideForPlayer(playerid, DrawSpeedBonus[playerid]);
  219.             SetPVarInt(playerid, "SpeedBonus", 0);
  220.             TextDrawHideForPlayer(playerid, DrawAngleBonus[playerid]);
  221.             SetPVarInt(playerid, "AngleBonus", 0);
  222.             Score[playerid]--;
  223.             format(string, sizeof(string), "This drift: %d", Score[playerid]);
  224.             TextDrawSetString(DrawScore[playerid], string);
  225.         }
  226.     }
  227.     else if (Score[playerid] > 0)
  228.     {
  229.         if (Score[playerid] > GetPVarInt(playerid, "AbsMaxScore"))
  230.         {
  231.             SetPVarInt(playerid, "AbsMaxScore", Score[playerid]);
  232.             format(string,sizeof(string),"Best drift: %d",Score[playerid]);
  233.             TextDrawSetString(DrawBestScore[playerid], string);
  234.         }
  235.         format(string,sizeof(string),"Last drift: %d",Score[playerid]);
  236.         TextDrawSetString(DrawLastScore[playerid], string);
  237.         DriftRewards(vid, Score[playerid]);
  238.         Score[playerid] = 0;
  239.         TextDrawSetString(DrawScore[playerid], "This drift: 0");
  240.         TextDrawHideForPlayer(playerid, DrawSpeedBonus[playerid]);
  241.         SetPVarInt(playerid, "SpeedBonus", 0);
  242.         TextDrawHideForPlayer(playerid, DrawAngleBonus[playerid]);
  243.         SetPVarInt(playerid, "AngleBonus", 0);
  244.     }
  245. }
  246.  
  247. CancelDrifting(playerid)
  248. {
  249.     DriftingState[playerid] = false;
  250.     ScoreState[playerid] = false;
  251.     Score[playerid] = 0;
  252.     SetPVarInt(playerid, "MaxScore", 0);
  253.     SetPVarInt(playerid, "SpeedBonus", 0);
  254.     SetPVarInt(playerid, "AngleBonus", 0);
  255.     TextDrawHideForPlayer(playerid,DrawScore[playerid]);
  256.     TextDrawHideForPlayer(playerid,DrawBestScore[playerid]);
  257.     TextDrawHideForPlayer(playerid,DrawLastScore[playerid]);
  258.     TextDrawHideForPlayer(playerid, DrawSpeedBonus[playerid]);
  259.     TextDrawHideForPlayer(playerid, DrawAngleBonus[playerid]);
  260.     return 1;
  261. }
  262.  
  263. DriftRewards(vid, RewardSize)
  264. {
  265.     if (GetVehicleModel(vid) == 560) //For sultan
  266.     {
  267.         SultanRewards(vid, RewardSize);
  268.     }
  269.     else if (GetVehicleModel(vid) == 562) //For elegy
  270.     {
  271.         ElegyRewards(vid, RewardSize);
  272.     }
  273.     else
  274.     {
  275.         GenericRewards(vid, RewardSize);
  276.     }
  277. }
  278.  
  279. SultanRewards(vid, RewardSize)
  280. {
  281.     if (RewardSize>20)
  282.     {
  283.         AddVehicleComponent(vid, 1033); //roof vent
  284.         if (RewardSize>40)
  285.         {
  286.             AddVehicleComponent(vid, 1030); //side skirts
  287.             AddVehicleComponent(vid, 1031);
  288.             if (RewardSize > 70)
  289.             {
  290.                 RepairVehicle(vid);
  291.                 SetVehicleHealth(vid, 1000);
  292.                 AddVehicleComponent(vid, 1009); //2x nos
  293.                 if (RewardSize>80)
  294.                 {
  295.                     AddVehicleComponent(vid, 1029); //exhaust
  296.                     AddVehicleComponent(vid, 1170); //front bumper
  297.                     if (RewardSize>100)
  298.                     {
  299.                         AddVehicleComponent(vid, 1085); //wheels
  300.                         AddVehicleComponent(vid, 1139); //spoiler
  301.                         AddVehicleComponent(vid, 1140); //rear bumper
  302.                         ChangeVehicleColor(vid, 151, 166); //bright red
  303. }   }   }   }   }   }
  304.  
  305. ElegyRewards(vid, RewardSize)
  306. {
  307.     if (RewardSize>50)
  308.     {
  309.         AddVehicleComponent(vid, 1034); //roof vent
  310.         if (RewardSize > 70)
  311.         {
  312.             RepairVehicle(vid);
  313.             SetVehicleHealth(vid, 1000);
  314.             AddVehicleComponent(vid, 1009); //2x nos
  315.             if (RewardSize>100)
  316.             {
  317.                 AddVehicleComponent(vid, 1036); //side skirts
  318.                 AddVehicleComponent(vid, 1040);
  319.                 if (RewardSize>150)
  320.                 {
  321.                     AddVehicleComponent(vid, 1029); //exhaust
  322.                     AddVehicleComponent(vid, 1171); //front bumper
  323.                     if (RewardSize>200)
  324.                     {
  325.                         AddVehicleComponent(vid, 1085); //wheels
  326.                         AddVehicleComponent(vid, 1147); //spoiler
  327.                         AddVehicleComponent(vid, 1149); //rear bumper
  328.                         ChangeVehicleColor(vid, 151, 166); //bright red
  329. }   }   }   }   }   }
  330.  
  331. GenericRewards(vid, RewardSize)
  332. {
  333.     if (RewardSize>20)
  334.     {
  335.         AddVehicleComponent(vid, 1074);
  336.         if (RewardSize>70)
  337.         {
  338.             AddVehicleComponent(vid, 1009);
  339.             AddVehicleComponent(vid, 1011);
  340.             if (RewardSize>80)
  341.             {
  342.                 AddVehicleComponent(vid, 1085);
  343.                 ChangeVehicleColor(vid, 151, 166);
  344. }   }   }   }
  345.  
  346. public OnPlayerExitVehicle(playerid, vehicleid)
  347. {
  348.     if (DriftingState[playerid] == true)
  349.     {
  350.         CancelDrifting(playerid);
  351.         SendClientMessage(playerid, 0xFFAAFFAA, "Drifting mode is OFF. You can't drift without a vehicle!");
  352.     }
  353.     return 1;
  354. }
  355.  
  356. public OnVehicleDamageStatusUpdate(vehicleid, playerid)
  357. {
  358.     if (DriftingState[playerid] == true)
  359.     {
  360.         new a,b,c,d;
  361.         GetVehicleDamageStatus(vehicleid, a,b,c,d);
  362.         if (a || b || c || d == 1)
  363.         {
  364.             Score[playerid] = 0;
  365.             TextDrawHideForPlayer(playerid, DrawSpeedBonus[playerid]);
  366.             SetPVarInt(playerid, "SpeedBonus", 0);
  367.             TextDrawHideForPlayer(playerid, DrawAngleBonus[playerid]);
  368.             SetPVarInt(playerid, "AngleBonus", 0);
  369.             TextDrawSetString(DrawScore[playerid], "This drift: 0");
  370.         }
  371.     }
  372.     return 1;
  373. }
  374.  
  375. public OnPlayerDeath(playerid, killerid, reason)
  376. {
  377.     if (DriftingState[playerid] == true)
  378.     {
  379.         CancelDrifting(playerid);
  380.         SendClientMessage(playerid, 0xFFAAFFAA, "We don't want no dead people drifting 'round these parts");
  381.     }
  382.     return 1;
  383. }
  384.  
  385. public OnPlayerDisconnect(playerid, reason)
  386. {
  387.     CancelDrifting(playerid);
  388.     SetPVarInt(playerid, "AbsMaxScore", 0);
  389.     TextDrawHideForAll(DrawScore[playerid]);
  390.     TextDrawDestroy(DrawScore[playerid]);
  391.     TextDrawHideForAll(DrawBestScore[playerid]);
  392.     TextDrawDestroy(DrawBestScore[playerid]);
  393.     TextDrawHideForAll(DrawLastScore[playerid]);
  394.     TextDrawDestroy(DrawLastScore[playerid]);
  395.     TextDrawHideForAll(DrawAngleBonus[playerid]);
  396.     TextDrawDestroy(DrawAngleBonus[playerid]);
  397.     TextDrawHideForAll(DrawSpeedBonus[playerid]);
  398.     TextDrawDestroy(DrawSpeedBonus[playerid]);
  399.     return 1;
  400. }
Advertisement
Add Comment
Please, Sign In to add comment