EnzoMetlc

[Include] stunt.inc - Detectar acrobacias vía client-side!

Aug 27th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.64 KB | None | 0 0
  1. /* stunt.inc
  2.         Info:
  3.             Detects when a player is doing a wheele or stoppie, so you can handle it.
  4.             Useful if you want give rewards to the players that did it.
  5.  
  6.         Soon:
  7.             Two-wheels detection, and maybe insane stunt
  8.             More acurrate in detection.
  9. */
  10.  
  11.  
  12. /* Vars */
  13. static const gValidModelForStunt[212] =
  14. {
  15.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1,
  16.     1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 2, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 2, 2, 2, 0, 0, 1, 1, 2, 0, 1, 2/*quad*/, 0, 0, 1, 1,
  17.     0, 1, 1, 1, 1, 2, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 0, 0, 0,
  18.     1, 1, 1, 1, 1, 0, 0, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
  19.     1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 2, 1, 1, 1,
  20.     0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0
  21. };
  22.  
  23. enum stunt_pInfo_enum
  24. {
  25.     stunt_ID,
  26.     stunt_Time,
  27.    
  28.     Float:stunt_fX,
  29.     Float:stunt_fY,
  30.     Float:stunt_fZ,
  31.     Float:stunt_Health
  32. };
  33. static stunt_pInfo[MAX_PLAYERS][stunt_pInfo_enum];
  34.    
  35.    
  36.  
  37. /* Macros */
  38. #define STUNT_NONE          0
  39. #define STUNT_WHEELIE       1
  40. #define STUNT_STOPPIE       2
  41. #define STUNT_TWO_WHEELS        3 // deprecated
  42.  
  43. #define VEHICLE_TYPE_NONE       0 // Boats, airplanes, trailers or RC vehicles can't do stunts.
  44. #define VEHICLE_TYPE_CAR        1 // Can do two-weels.
  45. #define VEHICLE_TYPE_BIKE       2 // Can do wheelie or stoppie.
  46.  
  47. #define GetPlayerCurrentStunt(%1,%2) stunt_pInfo[%1][stunt_ID]
  48.  
  49.  
  50.  
  51. /* Functions */
  52. public OnPlayerUpdate(playerid)
  53. {
  54.     static vehicleid, Float:quat[4], time;
  55.    
  56.     if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  57.     {
  58.         if(gValidModelForStunt[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400] == VEHICLE_TYPE_BIKE)
  59.         {
  60.             vehicleid = GetPlayerVehicleID(playerid);
  61.             time = (GetTickCount() - stunt_pInfo[playerid][stunt_Time]);
  62.             GetVehicleRotationQuat(vehicleid, quat[0], quat[1], quat[2], quat[3]);
  63.        
  64.             if(stunt_pInfo[playerid][stunt_ID] != STUNT_NONE) // Is stunting
  65.             {
  66.                 static Float:Health;
  67.                 GetVehicleHealth(vehicleid, Health);
  68.  
  69.                 if(Health != stunt_pInfo[playerid][stunt_Health]) // Failed stunt!
  70.                 {
  71.                     new Float:Pos[3];
  72.  
  73.                     GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  74.                     new const Float:dist = VectorSize(stunt_pInfo[playerid][stunt_fX] - Pos[0], stunt_pInfo[playerid][stunt_fY] - Pos[1], stunt_pInfo[playerid][stunt_fZ] - Pos[2]);
  75.  
  76.                     CallLocalFunction("OnPlayerFinishStunt", "ddifb", playerid, stunt_pInfo[playerid][stunt_ID], time, dist, false);
  77.                     stunt_pInfo[playerid][stunt_ID] = STUNT_NONE;
  78.                     return 1;
  79.                 }
  80.                 new Float:Pos[3];
  81.                 GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  82.                    
  83.                 CallLocalFunction("OnPlayerUpdateStunt", "ddif", playerid, stunt_pInfo[playerid][stunt_ID], GetTickCount() - stunt_pInfo[playerid][stunt_Time], VectorSize(stunt_pInfo[playerid][stunt_fX] - Pos[0], stunt_pInfo[playerid][stunt_fY] - Pos[1], stunt_pInfo[playerid][stunt_fZ] - Pos[2]));
  84.             }
  85.                        
  86.             if(quat[1] < -0.15) // Wheelie
  87.             {
  88.                 if(stunt_pInfo[playerid][stunt_ID] == STUNT_NONE)
  89.                 {
  90.                     stunt_pInfo[playerid][stunt_ID] = STUNT_WHEELIE;
  91.                     stunt_pInfo[playerid][stunt_Time] = GetTickCount();
  92.                     GetPlayerPos(playerid, stunt_pInfo[playerid][stunt_fX], stunt_pInfo[playerid][stunt_fY], stunt_pInfo[playerid][stunt_fZ]);
  93.  
  94.                     CallLocalFunction("OnPlayerStartStunt", "dd", playerid, STUNT_WHEELIE);
  95.                     GetVehicleHealth(vehicleid, stunt_pInfo[playerid][stunt_Health]);
  96.                 }
  97.                 return 1;
  98.             }
  99.             if(quat[1] > 0.15) // Stoppie
  100.             {
  101.                 if(stunt_pInfo[playerid][stunt_ID] == STUNT_NONE)
  102.                 {
  103.                     stunt_pInfo[playerid][stunt_ID] = STUNT_STOPPIE;
  104.                     stunt_pInfo[playerid][stunt_Time] = GetTickCount();
  105.                     GetPlayerPos(playerid, stunt_pInfo[playerid][stunt_fX], stunt_pInfo[playerid][stunt_fY], stunt_pInfo[playerid][stunt_fZ]);
  106.  
  107.                     CallLocalFunction("OnPlayerStartStunt", "dd", playerid, STUNT_STOPPIE);
  108.                     GetVehicleHealth(vehicleid, stunt_pInfo[playerid][stunt_Health]);
  109.                 }
  110.                 return 1;
  111.             }
  112.             if(stunt_pInfo[playerid][stunt_ID] != STUNT_NONE)
  113.             {
  114.                 new Float:Pos[3];
  115.  
  116.                 GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  117.                 new const Float:dist = VectorSize(stunt_pInfo[playerid][stunt_fX] - Pos[0], stunt_pInfo[playerid][stunt_fY] - Pos[1], stunt_pInfo[playerid][stunt_fZ] - Pos[2]);
  118.  
  119.                 CallLocalFunction("OnPlayerFinishStunt", "ddifb", playerid, stunt_pInfo[playerid][stunt_ID], time, dist, true);
  120.                 stunt_pInfo[playerid][stunt_ID] = STUNT_NONE;
  121.             }
  122.         }
  123.     }
  124.     return 1;
  125. }
  126.  
  127.  
  128.  
  129. public OnPlayerStateChange(playerid, newstate, oldstate)
  130. {
  131.     if(oldstate == PLAYER_STATE_DRIVER && stunt_pInfo[playerid][stunt_ID] != STUNT_NONE)
  132.     {
  133.         new Float:Pos[3];
  134.  
  135.         GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  136.         new const Float:dist = VectorSize(stunt_pInfo[playerid][stunt_fX] - Pos[0], stunt_pInfo[playerid][stunt_fY] - Pos[1], stunt_pInfo[playerid][stunt_fZ] - Pos[2]);
  137.         new const time = (GetTickCount() - stunt_pInfo[playerid][stunt_Time]);
  138.  
  139.         CallLocalFunction("OnPlayerFinishStunt", "ddifb", playerid, stunt_pInfo[playerid][stunt_ID], time, dist, false);
  140.         stunt_pInfo[playerid][stunt_ID] = STUNT_NONE;
  141.     }
  142.     return 1;
  143. }
  144.  
  145.  
  146.  
  147. /* Forwards */
  148. forward OnPlayerStartStunt(playerid, stuntid);
  149. forward OnPlayerUpdateStunt(playerid, stuntid, time, Float:dist);  
  150. forward OnPlayerFinishStunt(playerid, stuntid, time, Float:dist, bool:success);
  151. // "time" in miliseconds!
  152.  
  153.  
  154.  
  155. /* Hook functions */
  156. #if defined _ALS_OnPlayerUpdate
  157.     #undef OnPlayerUpdate
  158. #else
  159.     #define _ALS_OnPlayerUpdate
  160. #endif
  161. #define OnPlayerUpdate stunt_OnPlayerUpdate
  162. forward stunt_OnPlayerUpdate(playerid);
  163.  
  164.  
  165. #if defined _ALS_OnPlayerStateChange
  166.     #undef OnPlayerStateChange
  167. #else
  168.     #define _ALS_OnPlayerStateChange
  169. #endif
  170. #define OnPlayerStateChange stunt_OnPlayerStateChange
  171. forward stunt_OnPlayerStateChange(playerid, newstate, oldstate);
Advertisement
Add Comment
Please, Sign In to add comment