SHARE
TWEET

Drift Points Counter Filterscript - .: OWNAGE EDITION :.

ThresholdSAMP Jan 12th, 2015 (edited) 381 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //////////////////////////////////////////////////////////////
  2. //////////////// DRIFT POINTS COUNTER BY LUBY ////////////////
  3. /////////////// Edited by Threshold & Abhinav ////////////////
  4. //////////////////////////////////////////////////////////////
  5.  
  6. #include <a_samp>
  7. #include <foreach>
  8. #include <zcmd>
  9.  
  10. #define CASH_PERCENT    100
  11. #define SCORE_PERCENT   0
  12.  
  13. #define DRIFT_MINKAT    10.0
  14. #define DRIFT_MAXKAT    90.0
  15. #define DRIFT_SPEED     30.0
  16.  
  17. #define COLOR_Label     0xFFFFFFFF
  18. #define COLOR_LabelOut  0x00000040
  19. #define COLOR_ValueOut  0xFFFFFF40
  20. #define COLOR_Value     0x000000FF
  21.  
  22. new bool:DriftActive = true;
  23.  
  24. enum TimerData
  25. {
  26.         AngleTimer,
  27.         FixTimer,
  28.         StateTimer,
  29.         CancelTimer,
  30.         DriftTimer
  31. };
  32. new TimerInfo[MAX_PLAYERS][TimerData];
  33.  
  34. enum DriftData
  35. {
  36.         CurrentPoints,
  37.         DriftBonus,
  38.         bool:DriftMode,
  39.         bool:FixMode,
  40.         Float:CarHealth,
  41.         Float:pPos[3]
  42. };
  43. new Drifting[MAX_PLAYERS][DriftData];
  44.  
  45. new Text:TDLabels[3];
  46. new PlayerText:TDValueDrift[MAX_PLAYERS];
  47. new PlayerText:TDValueBonus[MAX_PLAYERS];
  48. new PlayerText:TDValueCash[MAX_PLAYERS];
  49.  
  50. forward Drift(playerid);
  51. forward AngleUpdate(playerid);
  52. forward DriftExit(playerid);
  53. forward CheckPlayerState(playerid);
  54. forward AutoFix(playerid);
  55.  
  56. public OnFilterScriptInit()
  57. {
  58.         TDLabels[0] = TextDrawCreate(500, 100, "Drift Points");
  59.         TextDrawColor(TDLabels[0], COLOR_Label);
  60.         TextDrawSetShadow(TDLabels[0], 0);
  61.         TextDrawSetOutline(TDLabels[0], 1);
  62.         TextDrawLetterSize(TDLabels[0], 0.5, 2);
  63.         TextDrawBackgroundColor(TDLabels[0], COLOR_LabelOut);
  64.         TextDrawFont(TDLabels[0], 1);
  65.  
  66.         TDLabels[1] = TextDrawCreate(500, 150, "Drift Bonus");
  67.         TextDrawColor(TDLabels[1], COLOR_Label);
  68.         TextDrawSetShadow(TDLabels[1], 0);
  69.         TextDrawSetOutline(TDLabels[1], 1);
  70.         TextDrawLetterSize(TDLabels[1], 0.5, 2);
  71.         TextDrawBackgroundColor(TDLabels[1], COLOR_LabelOut);
  72.         TextDrawFont(TDLabels[1], 1);
  73.  
  74.         TDLabels[2] = TextDrawCreate(500, 200, "Drift Cash");
  75.         TextDrawColor(TDLabels[2], COLOR_Label);
  76.         TextDrawSetShadow(TDLabels[2], 0);
  77.         TextDrawSetOutline(TDLabels[2], 1);
  78.         TextDrawLetterSize(TDLabels[2], 0.5, 2);
  79.         TextDrawBackgroundColor(TDLabels[2], COLOR_LabelOut);
  80.         TextDrawFont(TDLabels[2], 1);
  81.  
  82.         DriftActive = true;
  83.         return 1;
  84. }
  85.  
  86. public OnFilterScriptExit()
  87. {
  88.         TextDrawDestroy(TDLabels[0]);
  89.         TextDrawDestroy(TDLabels[1]);
  90.         TextDrawDestroy(TDLabels[2]);
  91.         return 1;
  92. }
  93.  
  94. public OnPlayerConnect(playerid)
  95. {
  96.         LoadTextDraws(playerid);
  97.         Drifting[playerid][CurrentPoints] = 0;
  98.         Drifting[playerid][DriftBonus] = 1;
  99.         Drifting[playerid][DriftMode] = false;
  100.         Drifting[playerid][FixMode] = false;
  101.         TimerInfo[playerid][AngleTimer] = SetTimerEx("AngleUpdate", 200, true, "i", playerid);
  102.         return 1;
  103. }
  104.  
  105. public OnPlayerDisconnect(playerid, reason)
  106. {
  107.         PlayerTextDrawDestroy(playerid, TDValueDrift[playerid]);
  108.         PlayerTextDrawDestroy(playerid, TDValueBonus[playerid]);
  109.         PlayerTextDrawDestroy(playerid, TDValueCash[playerid]);
  110.         return 1;
  111. }
  112.  
  113. Float:GetPlayerTheoreticAngle(playerid)
  114. {
  115.         new Float:MindAngle = 0.0, Float:angle2 = 0.0;
  116.         if(IsPlayerConnected(playerid))
  117.         {
  118.                 new Float:x, Float:y, Float:z;
  119.                 GetPlayerPos(playerid, x, y, z);
  120.                 new Float:dis = floatsqroot(floatpower(floatabs(floatsub(x, Drifting[playerid][pPos][0])), 2)+floatpower(floatabs(floatsub(y, Drifting[playerid][pPos][1])), 2));
  121.                 if(IsPlayerInAnyVehicle(playerid)) GetVehicleZAngle(GetPlayerVehicleID(playerid), angle2);
  122.                 else GetPlayerFacingAngle(playerid, angle2);
  123.                 if(Drifting[playerid][pPos][0] >= x)
  124.                 {
  125.                         new Float:tmp = (x >= Drifting[playerid][pPos][0]) ? (x - Drifting[playerid][pPos][0]) : (Drifting[playerid][pPos][0] - x), Float:sin = asin(tmp / dis);
  126.                         if(Drifting[playerid][pPos][1] >= y) MindAngle = floatadd(floatsub(floatadd(sin, 90), floatmul(sin, 2)), 90.0);
  127.                         else MindAngle = floatsub(floatadd(sin, 180), 180.0);
  128.                 }
  129.                 else
  130.                 {
  131.                         if(Drifting[playerid][pPos][1] < y)
  132.                         {
  133.                                 new Float:tmp2 = (y >= Drifting[playerid][pPos][1]) ? (y - Drifting[playerid][pPos][1]) : (Drifting[playerid][pPos][1] - y), Float:sin = acos(tmp2 / dis);
  134.                                 MindAngle = floatsub(floatadd(sin, 360), floatmul(sin, 2));
  135.                         }
  136.                         else
  137.                         {
  138.                                 new Float:tmp = (x >= Drifting[playerid][pPos][0]) ? (x - Drifting[playerid][pPos][0]) : (Drifting[playerid][pPos][0] - x), Float:sin = asin(tmp / dis);
  139.                                 MindAngle = floatadd(sin, 180);
  140.                         }
  141.                 }
  142.         }
  143.         return (!MindAngle) ? (angle2) : (MindAngle);
  144. }
  145.  
  146. public DriftExit(playerid)
  147. {
  148.         TimerInfo[playerid][CancelTimer] = 0;
  149.         new Float:h, veh = GetPlayerVehicleID(playerid);
  150.         GetVehicleHealth(veh, h);
  151.         if((70 <= Drifting[playerid][CurrentPoints] <= 10000) && h >= Drifting[playerid][CarHealth])
  152.         {
  153.                 GivePlayerMoney(playerid, (Drifting[playerid][CurrentPoints] * Drifting[playerid][DriftBonus]) * CASH_PERCENT);
  154.                 SetPlayerScore(playerid, GetPlayerScore(playerid) + (Drifting[playerid][CurrentPoints] * SCORE_PERCENT));
  155.         }
  156.         TextDrawHideForPlayer(playerid, TDLabels[0]);
  157.         TextDrawHideForPlayer(playerid, TDLabels[1]);
  158.         TextDrawHideForPlayer(playerid, TDLabels[2]);
  159.         PlayerTextDrawHide(playerid, TDValueDrift[playerid]);
  160.         PlayerTextDrawHide(playerid, TDValueBonus[playerid]);
  161.         PlayerTextDrawHide(playerid, TDValueCash[playerid]);
  162.         Drifting[playerid][DriftBonus] = 1;
  163.         Drifting[playerid][FixMode] = true;
  164.         SetVehicleHealth(veh, Drifting[playerid][CarHealth]);
  165.         Drifting[playerid][CurrentPoints] = 0;
  166.         return 1;
  167. }
  168.  
  169. public Drift(playerid)
  170. {
  171.         if(!DriftActive) return 1;
  172.         if(IsPlayerInAnyVehicle(playerid) && GetVType(GetPlayerVehicleID(playerid)))
  173.         {
  174.                 new Float:X, Float:Y, Float:Z, Float:SpeedX, Float:Angle1, Float:Angle2, Float:BySpeed;
  175.                 GetPlayerPos(playerid, X, Y, Z);
  176.                 SpeedX = floatsqroot(floatadd(floatadd(floatpower(floatabs(floatsub(X, Drifting[playerid][pPos][0])), 2), floatpower(floatabs(floatsub(Y, Drifting[playerid][pPos][1])), 2)), floatpower(floatabs(floatsub(Z, Drifting[playerid][pPos][2])), 2)));
  177.                 if(IsPlayerInAnyVehicle(playerid)) GetVehicleZAngle(GetPlayerVehicleID(playerid), Angle1);
  178.                 else GetPlayerFacingAngle(playerid, Angle1);
  179.                 Angle2 = GetPlayerTheoreticAngle(playerid);
  180.                 BySpeed = floatmul(SpeedX, 12);
  181.                 if((DRIFT_MINKAT <= floatabs(floatsub(Angle1, Angle2)) <= DRIFT_MAXKAT) && BySpeed >= DRIFT_SPEED)
  182.                 {
  183.                         if(TimerInfo[playerid][CancelTimer]) KillTimer(TimerInfo[playerid][CancelTimer]);
  184.                         Drifting[playerid][CurrentPoints] += floatround((floatabs(floatsub(Angle1, Angle2)) * BySpeed * 0.3) / 10);
  185.                         TimerInfo[playerid][CancelTimer] = SetTimerEx("DriftExit", 3000, false, "d", playerid);
  186.                 }
  187.                 switch(Drifting[playerid][CurrentPoints])
  188.                 {
  189.                         case 0 .. 499: Drifting[playerid][DriftBonus] = 1;
  190.                         case 500 .. 999: Drifting[playerid][DriftBonus] = 2;
  191.                         case 1000 .. 1699: Drifting[playerid][DriftBonus] = 3;
  192.                         case 1700 .. 2499: Drifting[playerid][DriftBonus] = 4;
  193.                         default: Drifting[playerid][DriftBonus] = 5;
  194.                 }
  195.                 TextDrawShowForPlayer(playerid, TDLabels[0]);
  196.                 TextDrawShowForPlayer(playerid, TDLabels[1]);
  197.                 TextDrawShowForPlayer(playerid, TDLabels[2]);
  198.                 PlayerTextDrawShow(playerid, TDValueDrift[playerid]);
  199.                 PlayerTextDrawShow(playerid, TDValueBonus[playerid]);
  200.                 PlayerTextDrawShow(playerid, TDValueCash[playerid]);
  201.                 new vstr[15];
  202.                 format(vstr, sizeof(vstr), "%d", Drifting[playerid][CurrentPoints]);
  203.                 PlayerTextDrawSetString(playerid, TDValueDrift[playerid], vstr);
  204.                 format(vstr, sizeof(vstr), "X%d", Drifting[playerid][DriftBonus]);
  205.                 PlayerTextDrawSetString(playerid, TDValueBonus[playerid], vstr);
  206.                 format(vstr, sizeof(vstr), "$%d", ((Drifting[playerid][CurrentPoints] * Drifting[playerid][DriftBonus]) * CASH_PERCENT));
  207.                 PlayerTextDrawSetString(playerid, TDValueCash[playerid], vstr);
  208.                 Drifting[playerid][pPos][0] = X;
  209.                 Drifting[playerid][pPos][1] = Y;
  210.                 Drifting[playerid][pPos][2] = Z;
  211.         }
  212.         return 1;
  213. }
  214.  
  215. public AngleUpdate(playerid)
  216. {
  217.         if(!DriftActive) return 1;
  218.         if(IsPlayerInAnyVehicle(playerid)) GetVehiclePos(GetPlayerVehicleID(playerid), Drifting[playerid][pPos][0], Drifting[playerid][pPos][1], Drifting[playerid][pPos][2]);
  219.         else GetPlayerPos(playerid, Drifting[playerid][pPos][0], Drifting[playerid][pPos][1], Drifting[playerid][pPos][2]);
  220.         return 1;
  221. }
  222.  
  223. LoadTextDraws(playerid)
  224. {
  225.         TDValueDrift[playerid] = CreatePlayerTextDraw(playerid, 500, 120, "0");
  226.         PlayerTextDrawColor(playerid, TDValueDrift[playerid], COLOR_Value);
  227.         PlayerTextDrawSetShadow(playerid, TDValueDrift[playerid], 0);
  228.         PlayerTextDrawSetOutline(playerid, TDValueDrift[playerid], 1);
  229.         PlayerTextDrawLetterSize(playerid, TDValueDrift[playerid], 0.5, 2);
  230.         PlayerTextDrawBackgroundColor(playerid, TDValueDrift[playerid], COLOR_ValueOut);
  231.         PlayerTextDrawFont(playerid, TDValueDrift[playerid], 3);
  232.  
  233.         TDValueBonus[playerid] = CreatePlayerTextDraw(playerid, 500, 170, "X1");
  234.         PlayerTextDrawColor(playerid, TDValueBonus[playerid], COLOR_Value);
  235.         PlayerTextDrawSetShadow(playerid, TDValueBonus[playerid], 0);
  236.         PlayerTextDrawSetOutline(playerid, TDValueBonus[playerid], 1);
  237.         PlayerTextDrawLetterSize(playerid, TDValueBonus[playerid], 0.5, 2);
  238.         PlayerTextDrawBackgroundColor(playerid, TDValueBonus[playerid], COLOR_ValueOut);
  239.         PlayerTextDrawFont(playerid, TDValueBonus[playerid], 3);
  240.  
  241.         TDValueCash[playerid] = CreatePlayerTextDraw(playerid, 500, 220, "$0");
  242.         PlayerTextDrawColor(playerid, TDValueCash[playerid], COLOR_Value);
  243.         PlayerTextDrawSetShadow(playerid, TDValueCash[playerid], 0);
  244.         PlayerTextDrawSetOutline(playerid, TDValueCash[playerid], 1);
  245.         PlayerTextDrawLetterSize(playerid, TDValueCash[playerid], 0.5, 2);
  246.         PlayerTextDrawBackgroundColor(playerid, TDValueCash[playerid], COLOR_ValueOut);
  247.         PlayerTextDrawFont(playerid, TDValueCash[playerid], 3);
  248.         return 1;
  249. }
  250.  
  251. public CheckPlayerState(playerid)
  252. {
  253.         if(Drifting[playerid][DriftMode])
  254.         {
  255.                 if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  256.                 {
  257.                         if(Drifting[playerid][CurrentPoints] > 70)
  258.                         {
  259.                                 new Float:h;
  260.                                 GetVehicleHealth(GetPlayerVehicleID(playerid), h);
  261.                                 if(h < Drifting[playerid][CarHealth])
  262.                                 {
  263.                                         KillTimer(TimerInfo[playerid][DriftTimer]);
  264.                                         DriftExit(playerid);
  265.                                         GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~r~Boom", 800, 5);
  266.                                         Drifting[playerid][DriftMode] = false;
  267.                                 }
  268.                         }
  269.                 }
  270.                 else
  271.                 {
  272.                         KillTimer(TimerInfo[playerid][DriftTimer]);
  273.                         Drifting[playerid][DriftMode] = false;
  274.                         Drifting[playerid][FixMode] = true;
  275.                 }
  276.         }
  277.         else if(!Drifting[playerid][DriftMode])
  278.         {
  279.                 new veh = GetPlayerVehicleID(playerid);
  280.                 if((GetVType(veh)) && (GetPlayerState(playerid) == PLAYER_STATE_DRIVER))
  281.                 {
  282.                         Drifting[playerid][DriftMode] = true;
  283.                         GetVehicleHealth(veh, Drifting[playerid][CarHealth]);
  284.                         Drifting[playerid][FixMode] = false;
  285.                         TimerInfo[playerid][DriftTimer] = SetTimerEx("Drift", 200, true, "i", playerid);
  286.                 }
  287.         }
  288.         return 1;
  289. }
  290.  
  291. public AutoFix(playerid)
  292. {
  293.         if(Drifting[playerid][FixMode] && IsPlayerInAnyVehicle(playerid)) SetVehicleHealth(GetPlayerVehicleID(playerid), Drifting[playerid][CarHealth]);
  294.         return 1;
  295. }
  296.  
  297. public OnPlayerStateChange(playerid, newstate, oldstate)
  298. {
  299.         if(newstate == PLAYER_STATE_DRIVER)
  300.         {
  301.                 if(DriftActive)
  302.                 {
  303.                         new Float:h;
  304.                         GetVehicleHealth(GetPlayerVehicleID(playerid), h);
  305.                         Drifting[playerid][CarHealth] = h;
  306.                         Drifting[playerid][FixMode] = true;
  307.                         TimerInfo[playerid][FixTimer] = SetTimerEx("AutoFix", 1000, true, "i", playerid);
  308.                         TimerInfo[playerid][StateTimer] = SetTimerEx("CheckPlayerState", 100, true, "i", playerid);
  309.                 }
  310.         }
  311.         else if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
  312.         {
  313.                 KillTimer(TimerInfo[playerid][FixTimer]);
  314.                 KillTimer(TimerInfo[playerid][StateTimer]);
  315.                 TextDrawHideForPlayer(playerid, TDLabels[0]);
  316.                 TextDrawHideForPlayer(playerid, TDLabels[1]);
  317.                 TextDrawHideForPlayer(playerid, TDLabels[2]);
  318.                 PlayerTextDrawHide(playerid, TDValueDrift[playerid]);
  319.                 PlayerTextDrawHide(playerid, TDValueBonus[playerid]);
  320.                 PlayerTextDrawHide(playerid, TDValueCash[playerid]);
  321.                 Drifting[playerid][CurrentPoints] = 0;
  322.                 Drifting[playerid][DriftBonus] = 1;
  323.         }
  324.         return 1;
  325. }
  326.  
  327. GetVType(vid)
  328. {
  329.         switch(GetVehicleModel(vid))
  330.         {
  331.                 case    480, 533, 439, 555, //Convertibles
  332.                                 403, 408, 413, 414, 422, 440, 443, 455, 456, 459, 478, 482, 498, 499, 514, 515, 524, 531, 543, 552, 554, 578, 582, 605, 609, //Industrial Vehicles
  333.                                 412, 534 .. 536, 566, 567, 575, 576, //Lowriders
  334.                                 470, 489, 500, 505, 556, 557, 568, 573, 579, 595, //Offroad Vehicles
  335.                                 407, 416, 420, 427, 431 .. 433, 437, 438, 490, 523, 528, 544, 596 .. 599, 601, //Service Vehicles
  336.                                 401, 405, 410, 419, 421, 426, 436, 445, 466, 467, 474, 491, 492, 504, 507, 516 .. 518, 526, 527, 529, 540, 542, 546, 547, 549, 550, 551, 560, 562, 580, 585, 600, 604, //Saloon Vehicles
  337.                                 402, 411, 415, 429, 451, 475, 477, 494, 496, 502, 503, 506, 541, 558, 559, 565, 587, 589, 602, 603, //Sports Vehicles
  338.                                 404, 418, 458, 479, 561: return 1; //Wagons
  339.         }
  340.         return 0;
  341. }
  342.  
  343. CMD:driftoff(playerid, params[])
  344. {
  345.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You must be an RCON admin to use this command.");
  346.         SendClientMessageToAll(-1, "Drift has been disabled.");
  347.         TextDrawHideForAll(TDLabels[0]);
  348.         TextDrawHideForAll(TDLabels[1]);
  349.         TextDrawHideForAll(TDLabels[2]);
  350.         foreach(new i : Player)
  351.         {
  352.                 PlayerTextDrawHide(i, TDValueDrift[i]);
  353.                 PlayerTextDrawHide(i, TDValueBonus[i]);
  354.                 PlayerTextDrawHide(i, TDValueCash[i]);
  355.                 KillTimer(TimerInfo[i][FixTimer]);
  356.                 KillTimer(TimerInfo[i][StateTimer]);
  357.         }
  358.         DriftActive = false;
  359.         return 1;
  360. }
  361.  
  362. CMD:drifton(playerid, params[])
  363. {
  364.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You must be an RCON admin to use this command.");
  365.         SendClientMessageToAll(-1, "Drift has been activated.");
  366.         foreach(new i : Player)
  367.         {
  368.                 if(GetPlayerState(i) != PLAYER_STATE_DRIVER) continue;
  369.                 TimerInfo[i][FixTimer] = SetTimerEx("AutoFix", 1000, true, "i", i);
  370.                 TimerInfo[i][StateTimer] = SetTimerEx("CheckPlayerState", 100, true, "i", i);
  371.         }
  372.         DriftActive = true;
  373.         return 1;
  374. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top