Advertisement
Nanory

OnEmptyVehicleDamage v0.1

Jul 26th, 2011
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.11 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define VehicleDamFloat 0.1
  4. #define VehicleDamFloatZ 0.04
  5. #define VehicleDamAngleFloat 5.0
  6. #define KORREKTUR_VEK 0
  7.  
  8. //==================================================================================//
  9. //      This Include allows you to damage vehicle althrough nobody is inside        //
  10. //        Furthermore thank you to RyDeR` for his "GetVehicleSize" Function,        //
  11. //                      wups for his alternativ Hook method                         //
  12. //                   and the person who made the Holding define                     //
  13. //                              Made by Nanory (2011)                               //
  14. //                                                                                  //
  15. //                                                                                  //
  16. //  If you want to edit this include you can do this, but edit my name inside it.   //
  17. //              Last but not least I apologize for my bad english :P                //
  18. //==================================================================================//
  19.  
  20. #if defined Holding
  21. #else
  22.         #define Holding(%0) \
  23.         ((newkeys & (%0)) == (%0))
  24. #endif
  25.  
  26. forward OnEmptyVehicleDamage(vehicleid,playerid);
  27.  
  28. new Float:PVehPos[MAX_PLAYERS][4];
  29.  
  30.  
  31.  
  32. stock GetVehicleSize(modelID, &Float: size_X, &Float: size_Y, &Float: size_Z) // Author: RyDeR`
  33. {
  34.     static const
  35.         Float: sizeData[212][3] =
  36.         {
  37.             { 2.32, 5.11, 1.63 }, { 2.56, 5.82, 1.71 }, { 2.41, 5.80, 1.52 }, { 3.15, 9.22, 4.17 },
  38.             { 2.20, 5.80, 1.84 }, { 2.34, 6.00, 1.49 }, { 5.26, 11.59, 4.42 }, { 2.84, 8.96, 2.70 },
  39.             { 3.11, 10.68, 3.91 }, { 2.36, 8.18, 1.52 }, { 2.25, 5.01, 1.79 }, { 2.39, 5.78, 1.37 },
  40.             { 2.45, 7.30, 1.38 }, { 2.27, 5.88, 2.23 }, { 2.51, 7.07, 4.59 }, { 2.31, 5.51, 1.13 },
  41.             { 2.73, 8.01, 3.40 }, { 5.44, 23.27, 6.61 }, { 2.56, 5.67, 2.14 }, { 2.40, 6.21, 1.40 },
  42.             { 2.41, 5.90, 1.76 }, { 2.25, 6.38, 1.37 }, { 2.26, 5.38, 1.54 }, { 2.31, 4.84, 4.90 },
  43.             { 2.46, 3.85, 1.77 }, { 5.15, 18.62, 5.19 }, { 2.41, 5.90, 1.76 }, { 2.64, 8.19, 3.23 },
  44.             { 2.73, 6.28, 3.48 }, { 2.21, 5.17, 1.27 }, { 4.76, 16.89, 5.92 }, { 3.00, 12.21, 4.42 },
  45.             { 4.30, 9.17, 3.88 }, { 3.40, 10.00, 4.86 }, { 2.28, 4.57, 1.72 }, { 3.16, 13.52, 4.76 },
  46.             { 2.27, 5.51, 1.72 }, { 3.03, 11.76, 4.01 }, { 2.41, 5.82, 1.72 }, { 2.22, 5.28, 1.47 },
  47.             { 2.30, 5.55, 2.75 }, { 0.87, 1.40, 1.01 }, { 2.60, 6.67, 1.75 }, { 4.15, 20.04, 4.42 },
  48.             { 3.66, 6.01, 3.28 }, { 2.29, 5.86, 1.75 }, { 4.76, 17.02, 4.30 }, { 2.42, 14.80, 3.15 },
  49.             { 0.70, 2.19, 1.62 }, { 3.02, 9.02, 4.98 }, { 3.06, 13.51, 3.72 }, { 2.31, 5.46, 1.22 },
  50.             { 3.60, 14.56, 3.28 }, { 5.13, 13.77, 9.28 }, { 6.61, 19.04, 13.84 }, { 3.31, 9.69, 3.63 },
  51.             { 3.23, 9.52, 4.98 }, { 1.83, 2.60, 2.72 }, { 2.41, 6.13, 1.47 }, { 2.29, 5.71, 2.23 },
  52.             { 10.85, 13.55, 4.44 }, { 0.69, 2.46, 1.67 }, { 0.70, 2.19, 1.62 }, { 0.69, 2.42, 1.34 },
  53.             { 1.58, 1.54, 1.14 }, { 0.87, 1.40, 1.01 }, { 2.52, 6.17, 1.64 }, { 2.52, 6.36, 1.66 },
  54.             { 0.70, 2.23, 1.41 }, { 2.42, 14.80, 3.15 }, { 2.66, 5.48, 2.09 }, { 1.41, 2.00, 1.71 },
  55.             { 2.67, 9.34, 4.86 }, { 2.90, 5.40, 2.22 }, { 2.43, 6.03, 1.69 }, { 2.45, 5.78, 1.48 },
  56.             { 11.02, 11.28, 3.28 }, { 2.67, 5.92, 1.39 }, { 2.45, 5.57, 1.74 }, { 2.25, 6.15, 1.99 },
  57.             { 2.26, 5.26, 1.41 }, { 0.70, 1.87, 1.32 }, { 2.33, 5.69, 1.87 }, { 2.04, 6.19, 2.10 },
  58.             { 5.34, 26.20, 7.15 }, { 1.97, 4.07, 1.44 }, { 4.34, 7.84, 4.44 }, { 2.32, 15.03, 4.67 },
  59.             { 2.32, 12.60, 4.65 }, { 2.53, 5.69, 2.14 }, { 2.92, 6.92, 2.14 }, { 2.30, 6.32, 1.28 },
  60.             { 2.34, 6.17, 1.78 }, { 4.76, 17.82, 3.84 }, { 2.25, 6.48, 1.50 }, { 2.77, 5.44, 1.99 },
  61.             { 2.27, 4.75, 1.78 }, { 2.32, 15.03, 4.65 }, { 2.90, 6.59, 4.28 }, { 2.64, 7.19, 3.75 },
  62.             { 2.28, 5.01, 1.85 }, { 0.87, 1.40, 1.01 }, { 2.34, 5.96, 1.51 }, { 2.21, 6.13, 1.62 },
  63.             { 2.52, 6.03, 1.64 }, { 2.53, 5.69, 2.14 }, { 2.25, 5.21, 1.16 }, { 2.56, 6.59, 1.62 },
  64.             { 2.96, 8.05, 3.33 }, { 0.70, 1.89, 1.32 }, { 0.72, 1.74, 1.12 }, { 21.21, 21.19, 5.05 },
  65.             { 11.15, 6.15, 2.99 }, { 8.69, 9.00, 2.23 }, { 3.19, 10.06, 3.05 }, { 3.54, 9.94, 3.42 },
  66.             { 2.59, 6.23, 1.71 }, { 2.52, 6.32, 1.64 }, { 2.43, 6.00, 1.57 }, { 20.30, 19.29, 6.94 },
  67.             { 8.75, 14.31, 2.16 }, { 0.69, 2.46, 1.67 }, { 0.69, 2.46, 1.67 }, { 0.69, 2.47, 1.67 },
  68.             { 3.58, 8.84, 3.64 }, { 3.04, 6.46, 3.28 }, { 2.20, 5.40, 1.25 }, { 2.43, 5.71, 1.74 },
  69.             { 2.54, 5.55, 2.14 }, { 2.38, 5.63, 1.86 }, { 1.58, 4.23, 2.68 }, { 1.96, 3.70, 1.66 },
  70.             { 8.61, 11.39, 4.17 }, { 2.38, 5.42, 1.49 }, { 2.18, 6.26, 1.15 }, { 2.67, 5.48, 1.58 },
  71.             { 2.46, 6.42, 1.29 }, { 3.32, 18.43, 5.19 }, { 3.26, 16.59, 4.94 }, { 2.50, 3.86, 2.55 },
  72.             { 2.58, 6.07, 1.50 }, { 2.26, 4.94, 1.24 }, { 2.48, 6.40, 1.70 }, { 2.38, 5.73, 1.86 },
  73.             { 2.80, 12.85, 3.89 }, { 2.19, 4.80, 1.69 }, { 2.56, 5.86, 1.66 }, { 2.49, 5.84, 1.76 },
  74.             { 4.17, 24.42, 4.90 }, { 2.40, 5.53, 1.42 }, { 2.53, 5.88, 1.53 }, { 2.66, 6.71, 1.76 },
  75.             { 2.65, 6.71, 3.55 }, { 28.73, 23.48, 7.38 }, { 2.68, 6.17, 2.08 }, { 2.00, 5.13, 1.41 },
  76.             { 3.66, 6.36, 3.28 }, { 3.66, 6.26, 3.28 }, { 2.23, 5.25, 1.75 }, { 2.27, 5.48, 1.39 },
  77.             { 2.31, 5.40, 1.62 }, { 2.50, 5.80, 1.78 }, { 2.25, 5.30, 1.50 }, { 3.39, 18.62, 4.71 },
  78.             { 0.87, 1.40, 1.01 }, { 2.02, 4.82, 1.50 }, { 2.50, 6.46, 1.65 }, { 2.71, 6.63, 1.58 },
  79.             { 2.71, 4.61, 1.41 }, { 3.25, 18.43, 5.03 }, { 3.47, 21.06, 5.19 }, { 1.57, 2.32, 1.58 },
  80.             { 1.65, 2.34, 2.01 }, { 2.93, 7.38, 3.16 }, { 1.62, 3.84, 2.50 }, { 2.49, 5.82, 1.92 },
  81.             { 2.42, 6.36, 1.85 }, { 62.49, 61.43, 34.95 }, { 3.15, 11.78, 2.77 }, { 2.47, 6.21, 2.55 },
  82.             { 2.66, 5.76, 2.24 }, { 0.69, 2.46, 1.67 }, { 2.44, 7.21, 3.19 }, { 1.66, 3.66, 3.21 },
  83.             { 3.54, 15.90, 3.40 }, { 2.44, 6.53, 2.05 }, { 0.69, 2.79, 1.96 }, { 2.60, 5.76, 1.45 },
  84.             { 3.07, 8.61, 7.53 }, { 2.25, 5.09, 2.11 }, { 3.44, 18.39, 5.03 }, { 3.18, 13.63, 4.65 },
  85.             { 44.45, 57.56, 18.43 }, { 12.59, 13.55, 3.56 }, { 0.50, 0.92, 0.30 }, { 2.84, 13.47, 2.21 },
  86.             { 2.41, 5.90, 1.76 }, { 2.41, 5.90, 1.76 }, { 2.41, 5.78, 1.76 }, { 2.92, 6.15, 2.14 },
  87.             { 2.40, 6.05, 1.55 }, { 3.07, 6.96, 3.82 }, { 2.31, 5.53, 1.28 }, { 2.64, 6.07, 1.42 },
  88.             { 2.52, 6.17, 1.64 }, { 2.38, 5.73, 1.86 }, { 2.93, 3.38, 1.97 }, { 3.01, 3.25, 1.60 },
  89.             { 1.45, 4.65, 6.36 }, { 2.90, 6.59, 4.21 }, { 2.48, 1.42, 1.62 }, { 2.13, 3.16, 1.83 }
  90.         }
  91.     ;
  92.     if(400 <= modelID <= 611)
  93.     {
  94.         size_X = sizeData[modelID - 400][0];
  95.         size_Y = sizeData[modelID - 400][1];
  96.         size_Z = sizeData[modelID - 400][2];      
  97.         return 1;
  98.     }
  99.     return 0;
  100. }
  101.  
  102. stock GetPlayerLookingPos(playerid,Float:radius,&Float:x,&Float:y,&Float:z)
  103. {
  104.     if(IsPlayerConnected(playerid))
  105.     {
  106.         new
  107.             Float:fPX, Float:fPY, Float:fPZ,
  108.             Float:fVX, Float:fVY, Float:fVZ;
  109.  
  110.         GetPlayerCameraPos(playerid, fPX, fPY, fPZ);
  111.         GetPlayerCameraFrontVector(playerid, fVX, fVY, fVZ);
  112.  
  113.         x = fPX + ((radius+KORREKTUR_VEK)*fVX); // Geradengleichung (Vektoren)
  114.         y = fPY + ((radius+KORREKTUR_VEK)*fVY); // Geradengleichung
  115.         z = fPZ + ((radius+KORREKTUR_VEK)*fVZ); // Geradengleichung
  116.     }
  117.     return 1;
  118. }
  119.  
  120. stock VehicleToPoint(Float:radi, vehicleid, Float:x, Float:y, Float:z)
  121. {
  122.     new Float:oldposx, Float:oldposy, Float:oldposz;
  123.     new Float:tempposx, Float:tempposy, Float:tempposz;
  124.     GetVehiclePos(vehicleid, oldposx, oldposy, oldposz);
  125.     tempposx = (oldposx -x);
  126.     tempposy = (oldposy -y);
  127.     tempposz = (oldposz -z);
  128.     if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  129.     {
  130.         return 1;
  131.     }
  132.     return 0;
  133. }
  134.  
  135. stock IsPlayerLookingAtVehicle(playerid,vehicleid)
  136. {
  137.     if(IsPlayerConnected(playerid) && GetVehicleModel(vehicleid))
  138.     {
  139.         new Float:VehPos[3],Float:PlyDis,Float:PlyPos[3],Float:VehSize[3];//,Float:ZDif,Float:RealDis;
  140.         GetVehiclePos(vehicleid,VehPos[0],VehPos[1],VehPos[2]);
  141.         PlyDis = GetPlayerDistanceFromPoint(playerid,VehPos[0],VehPos[1],VehPos[2]);
  142.         GetPlayerLookingPos(playerid,PlyDis,PlyPos[0],PlyPos[1],PlyPos[2]);
  143.         GetVehicleSize(GetVehicleModel(vehicleid),VehSize[0],VehSize[1],VehSize[2]);
  144.         if(VehicleToPoint(VehSize[1],vehicleid,PlyPos[0],PlyPos[1],PlyPos[2]))
  145.         {
  146.             return 1;
  147.         }
  148.     }
  149.     return 0;
  150. }
  151.  
  152. stock GiveVehicleHealth(vehicleid,Float:health)
  153. {
  154.     if(GetVehicleModel(vehicleid))
  155.     {
  156.         new Float:gpHealth;
  157.         GetVehicleHealth(vehicleid,gpHealth);
  158.         if(gpHealth + health >= 1000){gpHealth = 1000;}
  159.         else if(gpHealth + health <= 0){gpHealth = 0;}
  160.         else{gpHealth += health;}
  161.         SetVehicleHealth(vehicleid,gpHealth);
  162.     }
  163.     return 1;
  164. }
  165.  
  166. public OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat)
  167. {
  168.     new Float:VehPos[4];
  169.     GetVehiclePos(vehicleid,VehPos[0],VehPos[1],VehPos[2]);
  170.     GetVehicleZAngle(vehicleid,VehPos[3]);
  171.     new Float:DifPos[4];
  172.     DifPos[0] = floatabs(PVehPos[playerid][0]-VehPos[0]);
  173.     DifPos[1] = floatabs(PVehPos[playerid][1]-VehPos[1]);
  174.     DifPos[2] = floatabs(PVehPos[playerid][2]-VehPos[2]);
  175.     DifPos[3] = floatabs(PVehPos[playerid][3]-VehPos[3]);
  176.    
  177.     //--------------------
  178.     // Test Strings
  179.     /*new str[128];
  180.     for(new i = 0; i < 16; i++){SendClientMessageToAll(0xFFFFFFFF," ");}
  181.     format(str,sizeof(str),"VehicleID: %d --- VehicleModel: %d (%d)",vehicleid,GetVehicleModel(vehicleid),playerid);
  182.     SendClientMessageToAll(0xFFFFFFFF,str);
  183.     format(str,sizeof(str),"%.2f | %.2f | %.2f | A: %.2f",DifPos[0],DifPos[1],DifPos[2],DifPos[3]);
  184.     SendClientMessageToAll(0xFFFFFFFF,str);*/
  185.    
  186.     //------------------
  187.     if(DifPos[0] <= VehicleDamFloat ||
  188.        DifPos[1] <= VehicleDamFloat ||
  189.        DifPos[2] <= VehicleDamFloatZ ||
  190.        DifPos[0] == 0.0 && DifPos[1] == 0.0 && DifPos[2] == 0.0)
  191.     {
  192.         if(DifPos[3] <= VehicleDamAngleFloat)
  193.         {
  194.             new cammode = GetPlayerCameraMode(playerid);
  195.             if(cammode == 7 || cammode == 8 || cammode == 53)
  196.             {
  197.                 if(IsPlayerLookingAtVehicle(playerid,vehicleid))
  198.                 {
  199.                     new newkeys,plylr,plyup;
  200.                     GetPlayerKeys(playerid,newkeys,plyup,plylr);
  201.                     if(Holding(KEY_FIRE)){CallRemoteFunction("OnEmptyVehicleDamage","ii",vehicleid,playerid);}
  202.                 }
  203.             }
  204.         }
  205.     }
  206.     //------------------
  207.     GetVehiclePos(vehicleid,PVehPos[playerid][0],PVehPos[playerid][1],PVehPos[playerid][2]);
  208.     GetVehicleZAngle(vehicleid,PVehPos[playerid][3]);
  209.     return CallLocalFunction("VB_OnUnoccupiedVehicleUpdate", "iii", vehicleid, playerid, passenger_seat);
  210. }
  211. forward VB_OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat);
  212. #if defined _ALS_OnUnoccupiedVehicleUpdate
  213.     #undef OnUnoccupiedVehicleUpdate
  214. #else
  215.     #define _ALS_OnUnoccupiedVehicleUpdate
  216. #endif
  217. #define OnUnoccupiedVehicleUpdate VB_OnUnoccupiedVehicleUpdate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement