EnzoMetlc

[Include] Stunt detector (Server-Side stunt control)

Jan 5th, 2017 (edited)
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 21.12 KB | None | 0 0
  1. /*
  2.     @stunt.inc v26/12/16 - by Enzo
  3.     Check out original post for updates!
  4. */
  5.  
  6. #if defined _stunt_included
  7.     #endinput
  8. #endif
  9. #define _stunt_included
  10.  
  11. #if !defined _samp_included
  12.     #include <a_samp>
  13. #endif
  14.  
  15. //
  16. #include <MapAndreas>
  17.  
  18. enum pStuntInfo_enum
  19. {
  20.     stunt_ID,
  21.     stunt_Time,
  22.  
  23.     Float:stunt_fX,
  24.     Float:stunt_fY,
  25.     Float:stunt_fZ,
  26.     Float:stunt_LQ,
  27.     Float:stunt_Dist,
  28. };
  29. new pStuntInfo[MAX_PLAYERS][pStuntInfo_enum];
  30. new Stunt_ModelsType[212 char];
  31.  
  32.  
  33. /* Macros */
  34. #define STUNT_UNABLE            (-1) // Player is unable to do stunts
  35. #define STUNT_NONE              (0)
  36. #define STUNT_WHEELIE           (1)
  37. #define STUNT_STOPPIE           (2)
  38. #define STUNT_TWO_WHEELS        (3) // deprecated
  39. #define STUNT_ROLL_LEFT         (4)
  40. #define STUNT_ROLL_RIGHT        (5)
  41. #define STUNT_LOOP              (6) // deprecated
  42. #define STUNT_INSANE            (7)
  43. #define STUNT_DRIFT             (8) // deprecated
  44. #define STUNT_INVALID           (0xFF) // internal
  45.  
  46. #define VEHICLE_TYPE_NONE       (0)
  47. #define VEHICLE_TYPE_CAR        (1) // Two-wheels stunt
  48. #define VEHICLE_TYPE_BIKE       (2) // Wheelie/Stoppie stunt
  49. #define VEHICLE_TYPE_PLANE      (3) // Barrer-Roll/Loop stunt
  50.  
  51. #if !defined fix_angle
  52.     #define fix_angle(%1)       (float(floatround(%1, floatround_floor) % 360))
  53. #endif
  54.  
  55.  
  56. /* Forwards */
  57. forward OnPlayerStartStunt(playerid, stuntid);
  58. forward OnPlayerUpdateStunt(playerid, stuntid, time, Float:dist);
  59. forward OnPlayerFinishStunt(playerid, stuntid, time, Float:dist, bool:success);
  60.  
  61.  
  62.  
  63. /* i_quat.inc - thanks to sprtik! http://forum.sa-mp.com/showthread.php?t=608341 */
  64. static stock Float:asin_limit(Float:value)
  65. {
  66.     if(value > 1.0) value = 1.0;
  67.     else if(value < -1.0) value = -1.0;
  68.     return asin(value);
  69. }
  70.  
  71. static stock Float:atan2_limit(Float:x, Float:y)
  72. {
  73.     if(x > 1.0) x = 1.0;
  74.     else if(x < -1.0) x = -1.0;
  75.     if(y > 1.0) y = 1.0;
  76.     else if(y < -1.0) y = -1.0;
  77.     return atan2(x, y);
  78. }
  79.  
  80. // Returns a set of Euler angles from a quaternion
  81. stock GetQuaternionAngles(Float:w, Float:x, Float:y, Float:z, &Float:xa, &Float:ya, &Float:za)
  82. {
  83.     xa = asin_limit(2.0 * y * z - 2.0 * x * w);
  84.     ya = -atan2_limit(x * z + y * w, 0.5 - x * x - y * y);
  85.     za = -atan2_limit(x * y + z * w, 0.5 - x * x - z * z);
  86.     return 1;
  87. }
  88.  
  89. stock GetVehicleRotation(vehicleid, &Float:x, &Float:y, &Float:z)
  90. {
  91.     new Float:qw, Float:qx, Float:qy, Float:qz;
  92.     GetVehicleRotationQuat(vehicleid, qw, qx, qy, qz);
  93.     return GetQuaternionAngles(qw, qx, qy, qz, x, y, z);
  94. }
  95.  
  96. //
  97. public OnFilterScriptInit()
  98. {
  99.     // Load vehicle models data
  100.     Stunt_ModelsType{0} = VEHICLE_TYPE_CAR;
  101.     Stunt_ModelsType{1} = VEHICLE_TYPE_CAR;
  102.     Stunt_ModelsType{2} = VEHICLE_TYPE_CAR;
  103.     Stunt_ModelsType{3} = VEHICLE_TYPE_CAR;
  104.     Stunt_ModelsType{4} = VEHICLE_TYPE_CAR;
  105.     Stunt_ModelsType{5} = VEHICLE_TYPE_CAR;
  106.     Stunt_ModelsType{6} = VEHICLE_TYPE_CAR;
  107.     Stunt_ModelsType{7} = VEHICLE_TYPE_CAR;
  108.     Stunt_ModelsType{8} = VEHICLE_TYPE_CAR;
  109.     Stunt_ModelsType{9} = VEHICLE_TYPE_CAR;
  110.     Stunt_ModelsType{10} = VEHICLE_TYPE_CAR;
  111.     Stunt_ModelsType{11} = VEHICLE_TYPE_CAR;
  112.     Stunt_ModelsType{12} = VEHICLE_TYPE_CAR;
  113.     Stunt_ModelsType{13} = VEHICLE_TYPE_CAR;
  114.     Stunt_ModelsType{14} = VEHICLE_TYPE_CAR;
  115.     Stunt_ModelsType{15} = VEHICLE_TYPE_CAR;
  116.     Stunt_ModelsType{16} = VEHICLE_TYPE_CAR;
  117.     Stunt_ModelsType{17} = VEHICLE_TYPE_NONE;
  118.     Stunt_ModelsType{18} = VEHICLE_TYPE_CAR;
  119.     Stunt_ModelsType{19} = VEHICLE_TYPE_CAR;
  120.     Stunt_ModelsType{20} = VEHICLE_TYPE_CAR;
  121.     Stunt_ModelsType{21} = VEHICLE_TYPE_CAR;
  122.     Stunt_ModelsType{22} = VEHICLE_TYPE_CAR;
  123.     Stunt_ModelsType{23} = VEHICLE_TYPE_CAR;
  124.     Stunt_ModelsType{24} = VEHICLE_TYPE_CAR;
  125.     Stunt_ModelsType{25} = VEHICLE_TYPE_NONE;
  126.     Stunt_ModelsType{26} = VEHICLE_TYPE_CAR;
  127.     Stunt_ModelsType{27} = VEHICLE_TYPE_CAR;
  128.     Stunt_ModelsType{28} = VEHICLE_TYPE_CAR;
  129.     Stunt_ModelsType{29} = VEHICLE_TYPE_CAR;
  130.     Stunt_ModelsType{30} = VEHICLE_TYPE_NONE;
  131.     Stunt_ModelsType{31} = VEHICLE_TYPE_CAR;
  132.     Stunt_ModelsType{32} = VEHICLE_TYPE_NONE;
  133.     Stunt_ModelsType{33} = VEHICLE_TYPE_CAR;
  134.     Stunt_ModelsType{34} = VEHICLE_TYPE_CAR;
  135.     Stunt_ModelsType{35} = VEHICLE_TYPE_NONE;
  136.     Stunt_ModelsType{36} = VEHICLE_TYPE_CAR;
  137.     Stunt_ModelsType{37} = VEHICLE_TYPE_CAR;
  138.     Stunt_ModelsType{38} = VEHICLE_TYPE_CAR;
  139.     Stunt_ModelsType{39} = VEHICLE_TYPE_CAR;
  140.     Stunt_ModelsType{40} = VEHICLE_TYPE_CAR;
  141.     Stunt_ModelsType{41} = VEHICLE_TYPE_CAR;
  142.     Stunt_ModelsType{42} = VEHICLE_TYPE_CAR;
  143.     Stunt_ModelsType{43} = VEHICLE_TYPE_CAR;
  144.     Stunt_ModelsType{44} = VEHICLE_TYPE_CAR;
  145.     Stunt_ModelsType{45} = VEHICLE_TYPE_CAR;
  146.     Stunt_ModelsType{46} = VEHICLE_TYPE_NONE;
  147.     Stunt_ModelsType{47} = VEHICLE_TYPE_NONE;
  148.     Stunt_ModelsType{48} = VEHICLE_TYPE_BIKE;
  149.     Stunt_ModelsType{49} = VEHICLE_TYPE_NONE;
  150.     Stunt_ModelsType{50} = VEHICLE_TYPE_NONE;
  151.     Stunt_ModelsType{51} = VEHICLE_TYPE_CAR;
  152.     Stunt_ModelsType{52} = VEHICLE_TYPE_NONE;
  153.     Stunt_ModelsType{53} = VEHICLE_TYPE_NONE;
  154.     Stunt_ModelsType{54} = VEHICLE_TYPE_NONE;
  155.     Stunt_ModelsType{55} = VEHICLE_TYPE_CAR;
  156.     Stunt_ModelsType{56} = VEHICLE_TYPE_CAR;
  157.     Stunt_ModelsType{57} = VEHICLE_TYPE_CAR;
  158.     Stunt_ModelsType{58} = VEHICLE_TYPE_CAR;
  159.     Stunt_ModelsType{59} = VEHICLE_TYPE_CAR;
  160.     Stunt_ModelsType{60} = VEHICLE_TYPE_PLANE;
  161.     Stunt_ModelsType{61} = VEHICLE_TYPE_BIKE;
  162.     Stunt_ModelsType{62} = VEHICLE_TYPE_BIKE;
  163.     Stunt_ModelsType{63} = VEHICLE_TYPE_BIKE;
  164.     Stunt_ModelsType{64} = VEHICLE_TYPE_NONE;
  165.     Stunt_ModelsType{65} = VEHICLE_TYPE_NONE;
  166.     Stunt_ModelsType{66} = VEHICLE_TYPE_CAR;
  167.     Stunt_ModelsType{67} = VEHICLE_TYPE_CAR;
  168.     Stunt_ModelsType{68} = VEHICLE_TYPE_BIKE;
  169.     Stunt_ModelsType{69} = VEHICLE_TYPE_NONE;
  170.     Stunt_ModelsType{70} = VEHICLE_TYPE_CAR;
  171.     Stunt_ModelsType{71} = VEHICLE_TYPE_BIKE;
  172.     Stunt_ModelsType{72} = VEHICLE_TYPE_NONE;
  173.     Stunt_ModelsType{73} = VEHICLE_TYPE_NONE;
  174.     Stunt_ModelsType{74} = VEHICLE_TYPE_CAR;
  175.     Stunt_ModelsType{75} = VEHICLE_TYPE_CAR;
  176.     Stunt_ModelsType{76} = VEHICLE_TYPE_PLANE;
  177.     Stunt_ModelsType{77} = VEHICLE_TYPE_CAR;
  178.     Stunt_ModelsType{78} = VEHICLE_TYPE_CAR;
  179.     Stunt_ModelsType{79} = VEHICLE_TYPE_CAR;
  180.     Stunt_ModelsType{80} = VEHICLE_TYPE_CAR;
  181.     Stunt_ModelsType{81} = VEHICLE_TYPE_BIKE;
  182.     Stunt_ModelsType{82} = VEHICLE_TYPE_CAR;
  183.     Stunt_ModelsType{83} = VEHICLE_TYPE_CAR;
  184.     Stunt_ModelsType{84} = VEHICLE_TYPE_NONE;
  185.     Stunt_ModelsType{85} = VEHICLE_TYPE_CAR;
  186.     Stunt_ModelsType{86} = VEHICLE_TYPE_CAR;
  187.     Stunt_ModelsType{87} = VEHICLE_TYPE_NONE;
  188.     Stunt_ModelsType{88} = VEHICLE_TYPE_NONE;
  189.     Stunt_ModelsType{89} = VEHICLE_TYPE_CAR;
  190.     Stunt_ModelsType{90} = VEHICLE_TYPE_CAR;
  191.     Stunt_ModelsType{91} = VEHICLE_TYPE_CAR;
  192.     Stunt_ModelsType{92} = VEHICLE_TYPE_CAR;
  193.     Stunt_ModelsType{93} = VEHICLE_TYPE_NONE;
  194.     Stunt_ModelsType{94} = VEHICLE_TYPE_CAR;
  195.     Stunt_ModelsType{95} = VEHICLE_TYPE_CAR;
  196.     Stunt_ModelsType{96} = VEHICLE_TYPE_CAR;
  197.     Stunt_ModelsType{97} = VEHICLE_TYPE_NONE;
  198.     Stunt_ModelsType{98} = VEHICLE_TYPE_CAR;
  199.     Stunt_ModelsType{99} = VEHICLE_TYPE_CAR;
  200.     Stunt_ModelsType{100} = VEHICLE_TYPE_CAR;
  201.     Stunt_ModelsType{101} = VEHICLE_TYPE_NONE;
  202.     Stunt_ModelsType{102} = VEHICLE_TYPE_CAR;
  203.     Stunt_ModelsType{103} = VEHICLE_TYPE_CAR;
  204.     Stunt_ModelsType{104} = VEHICLE_TYPE_CAR;
  205.     Stunt_ModelsType{105} = VEHICLE_TYPE_CAR;
  206.     Stunt_ModelsType{106} = VEHICLE_TYPE_CAR;
  207.     Stunt_ModelsType{107} = VEHICLE_TYPE_CAR;
  208.     Stunt_ModelsType{108} = VEHICLE_TYPE_CAR;
  209.     Stunt_ModelsType{109} = VEHICLE_TYPE_BIKE;
  210.     Stunt_ModelsType{110} = VEHICLE_TYPE_BIKE;
  211.     Stunt_ModelsType{111} = VEHICLE_TYPE_PLANE;
  212.     Stunt_ModelsType{112} = VEHICLE_TYPE_PLANE;
  213.     Stunt_ModelsType{113} = VEHICLE_TYPE_PLANE;
  214.     Stunt_ModelsType{114} = VEHICLE_TYPE_CAR;
  215.     Stunt_ModelsType{115} = VEHICLE_TYPE_CAR;
  216.     Stunt_ModelsType{116} = VEHICLE_TYPE_CAR;
  217.     Stunt_ModelsType{117} = VEHICLE_TYPE_CAR;
  218.     Stunt_ModelsType{118} = VEHICLE_TYPE_CAR;
  219.     Stunt_ModelsType{119} = VEHICLE_TYPE_NONE;
  220.     Stunt_ModelsType{120} = VEHICLE_TYPE_NONE;
  221.     Stunt_ModelsType{121} = VEHICLE_TYPE_BIKE;
  222.     Stunt_ModelsType{122} = VEHICLE_TYPE_BIKE;
  223.     Stunt_ModelsType{123} = VEHICLE_TYPE_BIKE;
  224.     Stunt_ModelsType{124} = VEHICLE_TYPE_CAR;
  225.     Stunt_ModelsType{125} = VEHICLE_TYPE_CAR;
  226.     Stunt_ModelsType{126} = VEHICLE_TYPE_CAR;
  227.     Stunt_ModelsType{127} = VEHICLE_TYPE_CAR;
  228.     Stunt_ModelsType{128} = VEHICLE_TYPE_CAR;
  229.     Stunt_ModelsType{129} = VEHICLE_TYPE_CAR;
  230.     Stunt_ModelsType{130} = VEHICLE_TYPE_CAR;
  231.     Stunt_ModelsType{131} = VEHICLE_TYPE_CAR;
  232.     Stunt_ModelsType{132} = VEHICLE_TYPE_CAR;
  233.     Stunt_ModelsType{133} = VEHICLE_TYPE_CAR;
  234.     Stunt_ModelsType{134} = VEHICLE_TYPE_CAR;
  235.     Stunt_ModelsType{135} = VEHICLE_TYPE_CAR;
  236.     Stunt_ModelsType{136} = VEHICLE_TYPE_CAR;
  237.     Stunt_ModelsType{137} = VEHICLE_TYPE_NONE;
  238.     Stunt_ModelsType{138} = VEHICLE_TYPE_NONE;
  239.     Stunt_ModelsType{139} = VEHICLE_TYPE_NONE;
  240.     Stunt_ModelsType{140} = VEHICLE_TYPE_CAR;
  241.     Stunt_ModelsType{141} = VEHICLE_TYPE_CAR;
  242.     Stunt_ModelsType{142} = VEHICLE_TYPE_CAR;
  243.     Stunt_ModelsType{143} = VEHICLE_TYPE_CAR;
  244.     Stunt_ModelsType{144} = VEHICLE_TYPE_CAR;
  245.     Stunt_ModelsType{145} = VEHICLE_TYPE_CAR;
  246.     Stunt_ModelsType{146} = VEHICLE_TYPE_CAR;
  247.     Stunt_ModelsType{147} = VEHICLE_TYPE_CAR;
  248.     Stunt_ModelsType{148} = VEHICLE_TYPE_NONE;
  249.     Stunt_ModelsType{149} = VEHICLE_TYPE_CAR;
  250.     Stunt_ModelsType{150} = VEHICLE_TYPE_CAR;
  251.     Stunt_ModelsType{151} = VEHICLE_TYPE_CAR;
  252.     Stunt_ModelsType{152} = VEHICLE_TYPE_CAR;
  253.     Stunt_ModelsType{153} = VEHICLE_TYPE_NONE;
  254.     Stunt_ModelsType{154} = VEHICLE_TYPE_CAR;
  255.     Stunt_ModelsType{155} = VEHICLE_TYPE_CAR;
  256.     Stunt_ModelsType{156} = VEHICLE_TYPE_CAR;
  257.     Stunt_ModelsType{157} = VEHICLE_TYPE_CAR;
  258.     Stunt_ModelsType{158} = VEHICLE_TYPE_CAR;
  259.     Stunt_ModelsType{159} = VEHICLE_TYPE_CAR;
  260.     Stunt_ModelsType{160} = VEHICLE_TYPE_CAR;
  261.     Stunt_ModelsType{161} = VEHICLE_TYPE_CAR;
  262.     Stunt_ModelsType{162} = VEHICLE_TYPE_CAR;
  263.     Stunt_ModelsType{163} = VEHICLE_TYPE_NONE;
  264.     Stunt_ModelsType{164} = VEHICLE_TYPE_NONE;
  265.     Stunt_ModelsType{165} = VEHICLE_TYPE_CAR;
  266.     Stunt_ModelsType{166} = VEHICLE_TYPE_CAR;
  267.     Stunt_ModelsType{167} = VEHICLE_TYPE_CAR;
  268.     Stunt_ModelsType{168} = VEHICLE_TYPE_CAR;
  269.     Stunt_ModelsType{169} = VEHICLE_TYPE_NONE;
  270.     Stunt_ModelsType{170} = VEHICLE_TYPE_NONE;
  271.     Stunt_ModelsType{171} = VEHICLE_TYPE_CAR;
  272.     Stunt_ModelsType{172} = VEHICLE_TYPE_CAR;
  273.     Stunt_ModelsType{173} = VEHICLE_TYPE_CAR;
  274.     Stunt_ModelsType{174} = VEHICLE_TYPE_CAR;
  275.     Stunt_ModelsType{175} = VEHICLE_TYPE_CAR;
  276.     Stunt_ModelsType{176} = VEHICLE_TYPE_CAR;
  277.     Stunt_ModelsType{177} = VEHICLE_TYPE_NONE;
  278.     Stunt_ModelsType{178} = VEHICLE_TYPE_CAR;
  279.     Stunt_ModelsType{179} = VEHICLE_TYPE_CAR;
  280.     Stunt_ModelsType{180} = VEHICLE_TYPE_CAR;
  281.     Stunt_ModelsType{181} = VEHICLE_TYPE_BIKE;
  282.     Stunt_ModelsType{182} = VEHICLE_TYPE_CAR;
  283.     Stunt_ModelsType{183} = VEHICLE_TYPE_CAR;
  284.     Stunt_ModelsType{184} = VEHICLE_TYPE_NONE;
  285.     Stunt_ModelsType{185} = VEHICLE_TYPE_CAR;
  286.     Stunt_ModelsType{186} = VEHICLE_TYPE_NONE;
  287.     Stunt_ModelsType{187} = VEHICLE_TYPE_CAR;
  288.     Stunt_ModelsType{188} = VEHICLE_TYPE_CAR;
  289.     Stunt_ModelsType{189} = VEHICLE_TYPE_CAR;
  290.     Stunt_ModelsType{190} = VEHICLE_TYPE_NONE;
  291.     Stunt_ModelsType{191} = VEHICLE_TYPE_NONE;
  292.     Stunt_ModelsType{192} = VEHICLE_TYPE_NONE;
  293.     Stunt_ModelsType{193} = VEHICLE_TYPE_PLANE;
  294.     Stunt_ModelsType{194} = VEHICLE_TYPE_NONE;
  295.     Stunt_ModelsType{195} = VEHICLE_TYPE_NONE;
  296.     Stunt_ModelsType{196} = VEHICLE_TYPE_CAR;
  297.     Stunt_ModelsType{197} = VEHICLE_TYPE_CAR;
  298.     Stunt_ModelsType{198} = VEHICLE_TYPE_CAR;
  299.     Stunt_ModelsType{199} = VEHICLE_TYPE_CAR;
  300.     Stunt_ModelsType{200} = VEHICLE_TYPE_CAR;
  301.     Stunt_ModelsType{201} = VEHICLE_TYPE_CAR;
  302.     Stunt_ModelsType{202} = VEHICLE_TYPE_CAR;
  303.     Stunt_ModelsType{203} = VEHICLE_TYPE_CAR;
  304.     Stunt_ModelsType{204} = VEHICLE_TYPE_CAR;
  305.     Stunt_ModelsType{205} = VEHICLE_TYPE_CAR;
  306.     Stunt_ModelsType{206} = VEHICLE_TYPE_NONE;
  307.     Stunt_ModelsType{207} = VEHICLE_TYPE_NONE;
  308.     Stunt_ModelsType{208} = VEHICLE_TYPE_NONE;
  309.     Stunt_ModelsType{209} = VEHICLE_TYPE_CAR;
  310.     Stunt_ModelsType{210} = VEHICLE_TYPE_NONE;
  311.     Stunt_ModelsType{211} = VEHICLE_TYPE_NONE;
  312.    
  313.     EnableStuntBonusForAll(false);
  314.    
  315.     print("\n*****************************************");
  316.     print("*     stunt.inc loaded successfuly!     *");
  317.     print("*****************************************\n");
  318.     return 1;
  319. }
  320.  
  321.  
  322. public OnPlayerUpdate(playerid)
  323. {
  324.     static vehicleid,
  325.     Float:fX, Float:fY, Float:fZ,
  326.     Float:QX, Float:QY, Float:QZ,
  327.     Float:vX, Float:vY, Float:vZ,
  328.     Float:dist, Float:angle, Float:min_z, Float:speed,
  329.     time;
  330.  
  331.     if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER || pStuntInfo[playerid][stunt_ID] == STUNT_UNABLE) return 1;
  332.    
  333.     GetVehiclePos(vehicleid, fX, fY, fZ);
  334.     GetVehicleZAngle(vehicleid, angle);
  335.    
  336.     vehicleid = GetPlayerVehicleID(playerid);
  337.     time = GetTickCount() - pStuntInfo[playerid][stunt_Time];
  338.     dist = VectorSize(pStuntInfo[playerid][stunt_fX] - fX, pStuntInfo[playerid][stunt_fY] - fY, pStuntInfo[playerid][stunt_fZ] - fZ);
  339.     angle -= fix_angle(atan2(fY - pStuntInfo[playerid][stunt_fY], fX - pStuntInfo[playerid][stunt_fX]) + 270.0);
  340.    
  341.     pStuntInfo[playerid][stunt_fX] = fX;
  342.     pStuntInfo[playerid][stunt_fY] = fY;
  343.     pStuntInfo[playerid][stunt_fZ] = fZ;
  344.     pStuntInfo[playerid][stunt_Dist] += dist;
  345.    
  346.     switch(Stunt_ModelsType{GetVehicleModel(vehicleid) - 400})
  347.     {
  348.         case VEHICLE_TYPE_BIKE: // Wheelie or stoppie
  349.         {
  350.             MapAndreas_FindZ_For2DCoord(fX, fY, min_z);
  351.             if(fZ - min_z < 2.5)
  352.             {
  353.                 GetVehicleRotation(vehicleid, QX, QY, QZ);
  354.                 QX -= atan2(fZ - pStuntInfo[playerid][stunt_fZ], dist); // Subtract height angle
  355.                
  356.                 if(QX > 20.0) // Wheelie
  357.                 {
  358.                     if(pStuntInfo[playerid][stunt_ID] == STUNT_WHEELIE)
  359.                     {
  360.                         OnPlayerUpdateStunt(playerid, STUNT_WHEELIE, time, pStuntInfo[playerid][stunt_Dist]); // Update stunt info
  361.                         return 1;
  362.                     }
  363.                     if(++pStuntInfo[playerid][stunt_LQ] < 15.0) return 1; // Avoid false-positives
  364.  
  365.                     pStuntInfo[playerid][stunt_ID] = STUNT_WHEELIE;
  366.                     pStuntInfo[playerid][stunt_Time] = GetTickCount();
  367.                     pStuntInfo[playerid][stunt_Dist] =
  368.                     pStuntInfo[playerid][stunt_LQ] = 0.0;
  369.                     OnPlayerStartStunt(playerid, STUNT_WHEELIE);
  370.                     return 1;
  371.                 }
  372.                 if(QX < -10.0) // Stoppie
  373.                 {
  374.                     if(pStuntInfo[playerid][stunt_ID] == STUNT_WHEELIE)
  375.                     {
  376.                         OnPlayerUpdateStunt(playerid, STUNT_STOPPIE, time, pStuntInfo[playerid][stunt_Dist]); // Update stunt info
  377.                         return 1;
  378.                     }
  379.                     if(++pStuntInfo[playerid][stunt_LQ] < 15.0) return 1; // Avoid false-positives
  380.  
  381.                     pStuntInfo[playerid][stunt_ID] = STUNT_STOPPIE;
  382.                     pStuntInfo[playerid][stunt_Time] = GetTickCount();
  383.                     pStuntInfo[playerid][stunt_Dist] =
  384.                     pStuntInfo[playerid][stunt_LQ] = 0.0;
  385.                     OnPlayerStartStunt(playerid, STUNT_STOPPIE);
  386.                     return 1;
  387.                 }
  388.             }
  389.             if(pStuntInfo[playerid][stunt_ID] != STUNT_NONE) // Player finished stunt
  390.             {
  391.                 FinishPlayerStunt(playerid, true);
  392.             }
  393.            
  394.             pStuntInfo[playerid][stunt_LQ] = 0.0;
  395.         }
  396.         case VEHICLE_TYPE_PLANE: // Roll
  397.         {
  398.             // Check Roll
  399.             if(!(-45.0 < QX < 45.0)) return 1; // Avoid false-positives
  400.            
  401.             GetVehicleRotation(vehicleid, QX, QY, QZ);
  402.            
  403.             if(QY > 20.0)
  404.             {
  405.                 if(pStuntInfo[playerid][stunt_LQ] < 0.0) pStuntInfo[playerid][stunt_LQ] = QY; // Fix
  406.                 switch(pStuntInfo[playerid][stunt_ID])
  407.                 {
  408.                     case STUNT_NONE: // Start stunt
  409.                     {
  410.                         pStuntInfo[playerid][stunt_ID] = STUNT_ROLL_RIGHT;
  411.                         pStuntInfo[playerid][stunt_Time] = GetTickCount();
  412.                         pStuntInfo[playerid][stunt_Dist] = 0.0;
  413.                         OnPlayerStartStunt(playerid, STUNT_ROLL_RIGHT);
  414.                     }
  415.                     case STUNT_ROLL_RIGHT:
  416.                     {
  417.                         if(QY >= pStuntInfo[playerid][stunt_LQ]) OnPlayerUpdateStunt(playerid, STUNT_ROLL_RIGHT, time, pStuntInfo[playerid][stunt_Dist]); // Update stunt info
  418.                         else FinishPlayerStunt(playerid, false);
  419.                     }
  420.                     case STUNT_ROLL_LEFT:
  421.                     {
  422.                         if(QY <= pStuntInfo[playerid][stunt_LQ]) OnPlayerUpdateStunt(playerid, STUNT_ROLL_LEFT, time, pStuntInfo[playerid][stunt_Dist]); // Update stunt info
  423.                         else FinishPlayerStunt(playerid, false);
  424.                     }
  425.                 }
  426.                 pStuntInfo[playerid][stunt_LQ] = QY;
  427.                 return 1;
  428.             }
  429.             if(QY < -20.0)
  430.             {
  431.                 if(pStuntInfo[playerid][stunt_LQ] > 0.0) pStuntInfo[playerid][stunt_LQ] = QY; // Fix
  432.                 switch(pStuntInfo[playerid][stunt_ID])
  433.                 {
  434.                     case STUNT_NONE: // Start stunt
  435.                     {
  436.                         pStuntInfo[playerid][stunt_ID] = STUNT_ROLL_LEFT;
  437.                         pStuntInfo[playerid][stunt_Time] = GetTickCount();
  438.                         pStuntInfo[playerid][stunt_Dist] = 0.0;
  439.                         OnPlayerStartStunt(playerid, STUNT_ROLL_LEFT);
  440.                     }
  441.                     case STUNT_ROLL_RIGHT:
  442.                     {
  443.                         if(QY >= pStuntInfo[playerid][stunt_LQ]) OnPlayerUpdateStunt(playerid, STUNT_ROLL_RIGHT, time, pStuntInfo[playerid][stunt_Dist]); // Update stunt info
  444.                         else FinishPlayerStunt(playerid, false);
  445.                     }
  446.                     case STUNT_ROLL_LEFT:
  447.                     {
  448.                         if(QY <= pStuntInfo[playerid][stunt_LQ]) OnPlayerUpdateStunt(playerid, STUNT_ROLL_LEFT, time, pStuntInfo[playerid][stunt_Dist]); // Update stunt info
  449.                         else FinishPlayerStunt(playerid, false);
  450.                     }
  451.                 }
  452.                 pStuntInfo[playerid][stunt_LQ] = QY;
  453.                 return 1;
  454.             }
  455.            
  456.             if(STUNT_NONE < pStuntInfo[playerid][stunt_ID] < STUNT_INVALID) FinishPlayerStunt(playerid, true);
  457.  
  458.             pStuntInfo[playerid][stunt_ID] = STUNT_NONE;
  459.             pStuntInfo[playerid][stunt_LQ] = QY;
  460.         }
  461.         case VEHICLE_TYPE_CAR: // Insane stunt
  462.         {
  463.             GetVehicleVelocity(vehicleid, vX, vY, vZ);
  464.             MapAndreas_FindZ_For2DCoord(fX, fY, min_z);
  465.             speed = VectorSize(vX, vY, vZ);
  466.  
  467.             if(fZ - min_z > 2.5 && speed > 0.2) // Insane stunt
  468.             {
  469.                 switch(pStuntInfo[playerid][stunt_ID])
  470.                 {
  471.                     case STUNT_INSANE:
  472.                     {
  473.                         OnPlayerUpdateStunt(playerid, STUNT_INSANE, time, pStuntInfo[playerid][stunt_Dist]);
  474.                         return 1;
  475.                     }
  476.                     case STUNT_NONE:
  477.                     {
  478.                         if(++pStuntInfo[playerid][stunt_LQ] < 5.0) return 1;
  479.                        
  480.                         pStuntInfo[playerid][stunt_ID] = STUNT_INSANE;
  481.                         pStuntInfo[playerid][stunt_Time] = GetTickCount();
  482.                         pStuntInfo[playerid][stunt_Dist] = 0.0;
  483.                         OnPlayerStartStunt(playerid, STUNT_INSANE);
  484.                         return 1;
  485.                     }
  486.                     default: return FinishPlayerStunt(playerid, false);
  487.                 }
  488.                 return 1;
  489.             }
  490.         }
  491.     }
  492.     return 1;
  493. }
  494. #if defined _ALS_OnPlayerUpdate
  495.     #undef OnPlayerUpdate
  496. #else
  497.     #define _ALS_OnPlayerUpdate
  498. #endif
  499. #define OnPlayerUpdate stunt_OnPlayerUpdate
  500. forward OnPlayerUpdate(playerid);
  501.  
  502.  
  503. public OnPlayerStateChange(playerid, newstate, oldstate)
  504. {
  505.     if(pStuntInfo[playerid][stunt_ID] == STUNT_UNABLE) return 1;
  506.    
  507.     if(newstate == PLAYER_STATE_DRIVER && pStuntInfo[playerid][stunt_ID] != STUNT_NONE)
  508.     {
  509.         new Float:fX, Float:fY, Float:fZ, vehicleid = GetPlayerVehicleID(playerid);
  510.         GetVehiclePos(vehicleid, fX, fY, fZ);
  511.    
  512.         pStuntInfo[playerid][stunt_ID] =
  513.         pStuntInfo[playerid][stunt_Time] = 0;
  514.         pStuntInfo[playerid][stunt_fX] = fX;
  515.         pStuntInfo[playerid][stunt_fY] = fY;
  516.         pStuntInfo[playerid][stunt_fZ] = fZ;
  517.         pStuntInfo[playerid][stunt_Dist] = 0.0;
  518.         return 1;
  519.     }
  520.     if(oldstate == PLAYER_STATE_DRIVER && pStuntInfo[playerid][stunt_ID] != STUNT_NONE)
  521.     {
  522.         OnPlayerFinishStunt(playerid, pStuntInfo[playerid][stunt_ID], GetTickCount() - pStuntInfo[playerid][stunt_Time], pStuntInfo[playerid][stunt_Dist], false);
  523.         pStuntInfo[playerid][stunt_ID] =
  524.         pStuntInfo[playerid][stunt_Time] = 0;
  525.         pStuntInfo[playerid][stunt_fX]  =
  526.         pStuntInfo[playerid][stunt_fY] =
  527.         pStuntInfo[playerid][stunt_fZ] =
  528.         pStuntInfo[playerid][stunt_Dist] = 0.0;
  529.         return 1;
  530.     }
  531.     return 1;
  532. }
  533. #if defined _ALS_OnPlayerStateChange
  534.     #undef OnPlayerStateChange
  535. #else
  536.     #define _ALS_OnPlayerStateChange
  537. #endif
  538.  
  539. #define OnPlayerStateChange stunt_OnPlayerStateChange
  540. forward stunt_OnPlayerStateChange(playerid, newstate, oldstate);
  541.    
  542.    
  543.  
  544. /* Functions */
  545. #define MAX_STUNT_NAME              (18)
  546.  
  547. #define TogglePlayerStunt(%1,%2)    (pStuntInfo[playerid][stunt_ID] = STUNT_UNABLE + clamp(%1, 0, 1))
  548. #define IsPlayerStunting(%1)        (STUNT_NONE < pStuntInfo[playerid][stunt_ID] < STUNT_INVALID)
  549. #define GetPlayerStunt(%1)          (pStuntInfo[playerid][stunt_ID])
  550. #define GetPlayerStuntTime(%1)      (GetTickCount() - pStuntInfo[playerid][stunt_Time])
  551. #define GetPlayerStuntDist(%1)      (pStuntInfo[playerid][stunt_Dist])
  552.  
  553. #if !defined GetModelType
  554. #define GetModelType(%1)            {Stunt_ModelsType{%1 - 400}
  555. #endif
  556.  
  557.  
  558. stock FinishPlayerStunt(playerid, bool:success)
  559. {
  560.     new ret = 1;
  561.     if(STUNT_NONE < pStuntInfo[playerid][stunt_ID] < STUNT_INVALID) ret = 0;
  562.     else OnPlayerFinishStunt(playerid, pStuntInfo[playerid][stunt_ID], GetTickCount() - pStuntInfo[playerid][stunt_Time], pStuntInfo[playerid][stunt_Dist], success);
  563.  
  564.     pStuntInfo[playerid][stunt_ID] =
  565.     pStuntInfo[playerid][stunt_Time] = 0;
  566.     pStuntInfo[playerid][stunt_fX]  =
  567.     pStuntInfo[playerid][stunt_fY] =
  568.     pStuntInfo[playerid][stunt_fZ] =
  569.     pStuntInfo[playerid][stunt_Dist] =
  570.     pStuntInfo[playerid][stunt_LQ] = 0.0;
  571.     return ret;
  572. }
  573.  
  574. stock GetStuntName(stuntid)
  575. {
  576.     new stunt[MAX_STUNT_NAME];
  577.     switch(stuntid)
  578.     {
  579.         case STUNT_UNABLE: stunt = "Unable";
  580.         case STUNT_WHEELIE: stunt = "Wheelie";
  581.         case STUNT_STOPPIE: stunt = "Stoppie";
  582.         case STUNT_TWO_WHEELS: stunt = "Two Wheels";
  583.         case STUNT_ROLL_LEFT: stunt = "Roll Left";
  584.         case STUNT_ROLL_RIGHT: stunt = "Roll Right";
  585.         case STUNT_LOOP: stunt = "Loop";
  586.         case STUNT_INSANE: stunt = "Insane";
  587.         case STUNT_DRIFT: stunt = "Drift";
  588.         default: stunt = "None";
  589.     }
  590.     return stunt;
  591. }
  592.  
  593. /*
  594. - EOS
  595. */
Add Comment
Please, Sign In to add comment