Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Drifting script by Joos ([email protected])*/
- #include <a_samp>
- #define MaximumPlayers 50 //Server-specific variable. PLEASE CHANGE ACCORDING TO YOUR SERVER!
- //drifting shizzle
- 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.
- new bool:ScoreState[MaximumPlayers]; //Array for checking whether or not the car is scoring points. Still loving the booleans.
- new Float:TDirection, //Travelling direction
- Float:CDirection, //Car facing direction
- Float:DriftAngle, //The resulting difference between the two corners
- Float:speed;
- 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.
- new string[64]; //Used everywhere.
- //textdraws
- new Text:DrawSpeedBonus[MaximumPlayers]; //speed
- new Text:DrawAngleBonus[MaximumPlayers]; //angle
- new Text:DrawScore[MaximumPlayers]; //current
- new Text:DrawLastScore[MaximumPlayers]; //last
- new Text:DrawBestScore[MaximumPlayers]; //best
- public OnPlayerConnect(playerid)
- {
- DrawScore[playerid] = TextDrawCreate(484.000000, 102.000000, "This drift: 0");
- TextDrawBackgroundColor(DrawScore[playerid], 255);
- TextDrawFont(DrawScore[playerid], 1);
- TextDrawLetterSize(DrawScore[playerid], 0.500000, 1.000000);
- TextDrawColor(DrawScore[playerid], -16776961);
- TextDrawSetOutline(DrawScore[playerid], 1);
- TextDrawSetProportional(DrawScore[playerid], 1);
- DrawBestScore[playerid] = TextDrawCreate(484.000000, 122.000000, "Max drift: 0");
- TextDrawBackgroundColor(DrawBestScore[playerid], 255);
- TextDrawFont(DrawBestScore[playerid], 1);
- TextDrawLetterSize(DrawBestScore[playerid], 0.500000, 1.000000);
- TextDrawColor(DrawBestScore[playerid], -16776961);
- TextDrawSetOutline(DrawBestScore[playerid], 1);
- TextDrawSetProportional(DrawBestScore[playerid], 1);
- DrawLastScore[playerid] = TextDrawCreate(485.000000, 112.000000, "Last drift: 0");
- TextDrawBackgroundColor(DrawLastScore[playerid], 255);
- TextDrawFont(DrawLastScore[playerid], 1);
- TextDrawLetterSize(DrawLastScore[playerid], 0.500000, 1.000000);
- TextDrawColor(DrawLastScore[playerid], -16776961);
- TextDrawSetOutline(DrawLastScore[playerid], 1);
- TextDrawSetProportional(DrawLastScore[playerid], 1);
- DrawSpeedBonus[playerid] = TextDrawCreate(606.000000, 133.000000, "Speed bonus!");
- TextDrawAlignment(DrawSpeedBonus[playerid], 3);
- TextDrawBackgroundColor(DrawSpeedBonus[playerid], 255);
- TextDrawFont(DrawSpeedBonus[playerid], 1);
- TextDrawLetterSize(DrawSpeedBonus[playerid], 0.500000, 1.000000);
- TextDrawColor(DrawSpeedBonus[playerid], 16711935);
- TextDrawSetOutline(DrawSpeedBonus[playerid], 1);
- TextDrawSetProportional(DrawSpeedBonus[playerid], 1);
- DrawAngleBonus[playerid] = TextDrawCreate(606.000000, 143.000000, "Angle bonus!");
- TextDrawAlignment(DrawAngleBonus[playerid], 3);
- TextDrawBackgroundColor(DrawAngleBonus[playerid], 255);
- TextDrawFont(DrawAngleBonus[playerid], 1);
- TextDrawLetterSize(DrawAngleBonus[playerid], 0.500000, 1.000000);
- TextDrawColor(DrawAngleBonus[playerid], 16711935);
- TextDrawSetOutline(DrawAngleBonus[playerid], 1);
- TextDrawSetProportional(DrawAngleBonus[playerid], 1);
- SendClientMessage(playerid, 0xAAFFFFFF, "Type /drifthelp for drifting help.");
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp("/drifthelp", cmdtext, true, 10) == 0)
- {
- SendClientMessage(playerid, 0xFFAAFF, "Type /drift to start drifting.");
- SendClientMessage(playerid, 0xFFAAFF, "The aim is to get as many points as possible with drifting.");
- SendClientMessage(playerid, 0xFFAAFF, "Getting high scores will upgrade your car with tuning parts.");
- SendClientMessage(playerid, 0xFFAAFF, "The amount of points needed varies with each car. Elegy is the most demanding with a max of 200");
- SendClientMessage(playerid, 0xFFAAFF, "Also, your car will be fixed and equipped with NOS every time you get 70 or more points.");
- SendClientMessage(playerid, 0xFFAAFF, "In order for the drift to count, you must be sliding at an angle of 15 degrees or higher.");
- 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.");
- SendClientMessage(playerid, 0xFFAAFF, "Also, you can't drift at low speeds. High speeds will provide another bonus, though!");
- 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!");
- SendClientMessage(playerid, 0xFFAAFF, "Remember to use your handbrake, countersteer, control your throttle and have fun!");
- return 1;
- }
- if (strcmp("/drift", cmdtext, true, 6) == 0)
- {
- if ((DriftingState[playerid] == false) && (IsPlayerInAnyVehicle(playerid)==1))
- {
- DriftingState[playerid]=true;
- SendClientMessage(playerid, 0xFFFFFF, "Drifting mode is ON");
- TextDrawShowForPlayer(playerid,DrawScore[playerid]);
- TextDrawShowForPlayer(playerid,DrawLastScore[playerid]);
- TextDrawShowForPlayer(playerid,DrawBestScore[playerid]);
- }
- else if (DriftingState[playerid] == true)
- {
- CancelDrifting(playerid);
- SendClientMessage(playerid, 0xFFFFFF, "Drifting mode is OFF");
- }
- if (IsPlayerInAnyVehicle(playerid)==0)
- {
- SendClientMessage(playerid, 0xFFFFFF, "Get in a car to start drifting!");
- }
- return 1;
- }
- return 0;
- }
- public OnPlayerUpdate(playerid)
- {
- if (DriftingState[playerid] == true)
- {
- Drifting(playerid);
- }
- return 1;
- }
- forward Drifting(playerid);
- public Drifting(playerid)
- {
- /*Speed calculation*/
- new Float:x, Float:y, Float:z, vid;
- vid = GetPlayerVehicleID(playerid);
- GetVehicleVelocity(vid, x, y, z);
- speed = floatpower(x*x+y*y, 0.5);
- if (speed > 0.2)
- {
- /*Trig functions for calculating moving(travelling) direction*/
- if (x<0)
- {
- if(y>0)
- { TDirection = atan(floatabs(x/y)); }
- else if (y<=0)
- { TDirection = atan(y/x) + 90; }
- }
- else if (x>0)
- {
- if(y<0)
- { TDirection = atan(floatabs(x/y)) + 180; }
- else if (y>=0)
- { TDirection = atan(y/x) + 270; }
- }
- else if (x==0)
- {
- if (y>0)
- { TDirection = 0; }
- else if (y<0)
- { TDirection = 180; }
- }
- /*Calculations for drifting angle*/
- GetVehicleZAngle(vid, CDirection);
- DriftAngle = floatabs(TDirection - CDirection);
- /*Adding score*/
- if ((15 < DriftAngle < 80) || ( 280 < DriftAngle < 345)) //At least a 15 degree angle is required to score anything
- {
- ScoreState[playerid] = true;
- Score[playerid]++;
- if ((25 < DriftAngle < 70) || (290 < DriftAngle < 335)) //At least a 25 degree angle is required to score 2 points
- {
- Score[playerid]++;
- if ((35 < DriftAngle < 45) || (315 < DriftAngle < 325)) //35-45 degree drifts receive additional bonuses
- {
- Score[playerid]++;
- SetPVarInt(playerid, "AngleBonus", GetPVarInt(playerid, "AngleBonus")+1);
- format(string,sizeof(string),"Angle Bonus + %d !", GetPVarInt(playerid, "AngleBonus"));
- TextDrawSetString(DrawAngleBonus[playerid], string);
- TextDrawShowForPlayer(playerid, DrawAngleBonus[playerid]);
- }
- }
- if (speed > 0.6)
- {
- Score[playerid]++;
- SetPVarInt(playerid, "SpeedBonus", GetPVarInt(playerid, "SpeedBonus")+1);
- format(string,sizeof(string),"Speed Bonus + %d !", GetPVarInt(playerid, "SpeedBonus"));
- TextDrawSetString(DrawSpeedBonus[playerid], string);
- TextDrawShowForPlayer(playerid, DrawSpeedBonus[playerid]);
- }
- format(string, sizeof(string), "This drift: %d", Score[playerid]);
- TextDrawSetString(DrawScore[playerid], string);
- }
- /*When the player stops drifting*/
- else if (Score[playerid]>0)
- {
- if (ScoreState[playerid] == true)
- {
- if (Score[playerid] > GetPVarInt(playerid, "MaxScore"))
- {
- SetPVarInt(playerid, "MaxScore", Score[playerid]);
- DriftRewards(vid, Score[playerid]); //Comment this line if you want to disable tuning rewards.
- if (Score[playerid] > GetPVarInt(playerid, "AbsMaxScore"))
- {
- SetPVarInt(playerid, "AbsMaxScore", Score[playerid]);
- format(string,sizeof(string),"Max drift: %d",GetPVarInt(playerid,"AbsMaxScore"));
- TextDrawSetString(DrawBestScore[playerid], string);
- SetPlayerScore(playerid, Score[playerid]); //Comment this line if you want to disable score updating(under TAB)
- }
- else
- {
- format(string,sizeof(string),"Last drift: %d",Score[playerid]);
- TextDrawSetString(DrawLastScore[playerid], string);
- }
- }
- else
- {
- format(string,sizeof(string),"Last drift %d",Score[playerid]);
- TextDrawSetString(DrawLastScore[playerid], string);
- 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)
- {
- RepairVehicle(vid);
- SetVehicleHealth(vid, 1000);
- AddVehicleComponent(vid, 1009); //2x nos
- }
- }
- ScoreState[playerid] = false;
- }
- TextDrawHideForPlayer(playerid, DrawSpeedBonus[playerid]);
- SetPVarInt(playerid, "SpeedBonus", 0);
- TextDrawHideForPlayer(playerid, DrawAngleBonus[playerid]);
- SetPVarInt(playerid, "AngleBonus", 0);
- Score[playerid]--;
- format(string, sizeof(string), "This drift: %d", Score[playerid]);
- TextDrawSetString(DrawScore[playerid], string);
- }
- }
- else if (Score[playerid] > 0)
- {
- if (Score[playerid] > GetPVarInt(playerid, "AbsMaxScore"))
- {
- SetPVarInt(playerid, "AbsMaxScore", Score[playerid]);
- format(string,sizeof(string),"Best drift: %d",Score[playerid]);
- TextDrawSetString(DrawBestScore[playerid], string);
- }
- format(string,sizeof(string),"Last drift: %d",Score[playerid]);
- TextDrawSetString(DrawLastScore[playerid], string);
- DriftRewards(vid, Score[playerid]);
- Score[playerid] = 0;
- TextDrawSetString(DrawScore[playerid], "This drift: 0");
- TextDrawHideForPlayer(playerid, DrawSpeedBonus[playerid]);
- SetPVarInt(playerid, "SpeedBonus", 0);
- TextDrawHideForPlayer(playerid, DrawAngleBonus[playerid]);
- SetPVarInt(playerid, "AngleBonus", 0);
- }
- }
- CancelDrifting(playerid)
- {
- DriftingState[playerid] = false;
- ScoreState[playerid] = false;
- Score[playerid] = 0;
- SetPVarInt(playerid, "MaxScore", 0);
- SetPVarInt(playerid, "SpeedBonus", 0);
- SetPVarInt(playerid, "AngleBonus", 0);
- TextDrawHideForPlayer(playerid,DrawScore[playerid]);
- TextDrawHideForPlayer(playerid,DrawBestScore[playerid]);
- TextDrawHideForPlayer(playerid,DrawLastScore[playerid]);
- TextDrawHideForPlayer(playerid, DrawSpeedBonus[playerid]);
- TextDrawHideForPlayer(playerid, DrawAngleBonus[playerid]);
- return 1;
- }
- DriftRewards(vid, RewardSize)
- {
- if (GetVehicleModel(vid) == 560) //For sultan
- {
- SultanRewards(vid, RewardSize);
- }
- else if (GetVehicleModel(vid) == 562) //For elegy
- {
- ElegyRewards(vid, RewardSize);
- }
- else
- {
- GenericRewards(vid, RewardSize);
- }
- }
- SultanRewards(vid, RewardSize)
- {
- if (RewardSize>20)
- {
- AddVehicleComponent(vid, 1033); //roof vent
- if (RewardSize>40)
- {
- AddVehicleComponent(vid, 1030); //side skirts
- AddVehicleComponent(vid, 1031);
- if (RewardSize > 70)
- {
- RepairVehicle(vid);
- SetVehicleHealth(vid, 1000);
- AddVehicleComponent(vid, 1009); //2x nos
- if (RewardSize>80)
- {
- AddVehicleComponent(vid, 1029); //exhaust
- AddVehicleComponent(vid, 1170); //front bumper
- if (RewardSize>100)
- {
- AddVehicleComponent(vid, 1085); //wheels
- AddVehicleComponent(vid, 1139); //spoiler
- AddVehicleComponent(vid, 1140); //rear bumper
- ChangeVehicleColor(vid, 151, 166); //bright red
- } } } } } }
- ElegyRewards(vid, RewardSize)
- {
- if (RewardSize>50)
- {
- AddVehicleComponent(vid, 1034); //roof vent
- if (RewardSize > 70)
- {
- RepairVehicle(vid);
- SetVehicleHealth(vid, 1000);
- AddVehicleComponent(vid, 1009); //2x nos
- if (RewardSize>100)
- {
- AddVehicleComponent(vid, 1036); //side skirts
- AddVehicleComponent(vid, 1040);
- if (RewardSize>150)
- {
- AddVehicleComponent(vid, 1029); //exhaust
- AddVehicleComponent(vid, 1171); //front bumper
- if (RewardSize>200)
- {
- AddVehicleComponent(vid, 1085); //wheels
- AddVehicleComponent(vid, 1147); //spoiler
- AddVehicleComponent(vid, 1149); //rear bumper
- ChangeVehicleColor(vid, 151, 166); //bright red
- } } } } } }
- GenericRewards(vid, RewardSize)
- {
- if (RewardSize>20)
- {
- AddVehicleComponent(vid, 1074);
- if (RewardSize>70)
- {
- AddVehicleComponent(vid, 1009);
- AddVehicleComponent(vid, 1011);
- if (RewardSize>80)
- {
- AddVehicleComponent(vid, 1085);
- ChangeVehicleColor(vid, 151, 166);
- } } } }
- public OnPlayerExitVehicle(playerid, vehicleid)
- {
- if (DriftingState[playerid] == true)
- {
- CancelDrifting(playerid);
- SendClientMessage(playerid, 0xFFAAFFAA, "Drifting mode is OFF. You can't drift without a vehicle!");
- }
- return 1;
- }
- public OnVehicleDamageStatusUpdate(vehicleid, playerid)
- {
- if (DriftingState[playerid] == true)
- {
- new a,b,c,d;
- GetVehicleDamageStatus(vehicleid, a,b,c,d);
- if (a || b || c || d == 1)
- {
- Score[playerid] = 0;
- TextDrawHideForPlayer(playerid, DrawSpeedBonus[playerid]);
- SetPVarInt(playerid, "SpeedBonus", 0);
- TextDrawHideForPlayer(playerid, DrawAngleBonus[playerid]);
- SetPVarInt(playerid, "AngleBonus", 0);
- TextDrawSetString(DrawScore[playerid], "This drift: 0");
- }
- }
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- if (DriftingState[playerid] == true)
- {
- CancelDrifting(playerid);
- SendClientMessage(playerid, 0xFFAAFFAA, "We don't want no dead people drifting 'round these parts");
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- CancelDrifting(playerid);
- SetPVarInt(playerid, "AbsMaxScore", 0);
- TextDrawHideForAll(DrawScore[playerid]);
- TextDrawDestroy(DrawScore[playerid]);
- TextDrawHideForAll(DrawBestScore[playerid]);
- TextDrawDestroy(DrawBestScore[playerid]);
- TextDrawHideForAll(DrawLastScore[playerid]);
- TextDrawDestroy(DrawLastScore[playerid]);
- TextDrawHideForAll(DrawAngleBonus[playerid]);
- TextDrawDestroy(DrawAngleBonus[playerid]);
- TextDrawHideForAll(DrawSpeedBonus[playerid]);
- TextDrawDestroy(DrawSpeedBonus[playerid]);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment