Advertisement
Admigo

[0.3z]a_OnPlayerShootVehiclePart_v2

Jan 20th, 2014
1,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.68 KB | None | 0 0
  1. //-----------------------------------------------------------------
  2. //||+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++||
  3. //||+++++++++[Admigo's OnPlayerShootVehiclePart Callback+++++++++||
  4. //||+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++||
  5. //||+++++++++++++++++++++++++Version 2.0+++++++++++++++++++++++++||
  6. //||+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++||
  7. //-----------------------------------------------------------------
  8.  
  9. #include <a_samp>
  10.  
  11. #define BULLET_HIT_PETROL_TANK 0
  12. #define BULLET_HIT_LEFT_FRONT_WHEEL 1
  13. #define BULLET_HIT_RIGHT_FRONT_WHEEL 2
  14. #define BULLET_HIT_LEFT_BACK_WHEEL 3
  15. #define BULLET_HIT_RIGHT_BACK_WHEEL 4
  16. #define BULLET_HIT_BODY 5
  17.  
  18. new VehicleTire[MAX_VEHICLES][4];
  19. new EnableVehicleDamageVar=0;
  20. new EnablePetrolCapExplosionVar=0;
  21. new EnableWheelTirePopVar=0;
  22.  
  23. enum WS_info
  24. {
  25.     Float:WS_Damage
  26. }
  27.  
  28. new WeaponShotInfo[17][WS_info] = {
  29.     {25.0},
  30.     {40.0},
  31.     {70.0},
  32.     {10.0},
  33.     {10.0},
  34.     {15.0},
  35.     {20.0},
  36.     {25.0},
  37.     {30.0},
  38.     {30.0},
  39.     {20.0},
  40.     {75.0},
  41.     {125.0},
  42.     {75.0},//Not Working Yet
  43.     {75.0},//Not Working Yet
  44.     {25.0},//Not Working Yet
  45.     {140.0}
  46. };
  47.  
  48. enum VS_info
  49. {
  50.     Float:VS_PetrolX,
  51.     Float:VS_PetrolY,
  52.     Float:VS_PetrolZ
  53. }
  54. //VehicleInfo[602-400][VehiclePrice]
  55. new VehicleShotInfo[212][VS_info] = {
  56.     {-1.06,-2.07,-0.03},
  57.     {1.25,-0.91,0.05},
  58.     {1.11,-1.92,0.17},
  59.     {-1.46,0.02,-0.66},
  60.     {-1.03,-2.37,0.06},
  61.     {-0.86,-2.16,-0.08},
  62.     {0.00,0.00,0.00},
  63.     {-1.07,-3.74,-0.42},
  64.     {-1.46,1.24,-0.57},
  65.     {-1.04,-2.82,0.14},
  66.     {-0.96,-1.66,0.23},
  67.     {1.06,-2.10,0.09},
  68.     {0.00,0.00,0.00},
  69.     {-0.46,0.53,-0.79},
  70.     {-0.66,-0.71,-0.70},
  71.     {-1.07,-2.06,0.05},
  72.     {-1.16,-2.72,-0.21},
  73.     {0.00,0.00,0.00},
  74.     {-1.24,-1.76,0.03},
  75.     {-1.09,-1.99,0.06},
  76.     {-1.03,-2.14,0.08},
  77.     {-1.02,-2.43,-0.14},
  78.     {-0.93,-0.41,-0.19},
  79.     {-1.13,-1.90,-0.28},
  80.     {-1.11,-0.54,-0.10},
  81.     {0.00,0.00,0.00},
  82.     {-1.00,-2.16,0.06},
  83.     {-1.27,-3.18,-0.18},
  84.     {-1.01,-2.65,-0.56},
  85.     {0.00,0.00,0.00},
  86.     {0.00,0.00,0.00},
  87.     {-1.32,-5.47,-0.12},
  88.     {0.00,0.00,0.00},
  89.     {-1.51,0.15,-0.67},
  90.     {0.00,0.00,0.00},
  91.     {0.00,0.00,0.00},
  92.     {-1.02,-1.81,0.16},
  93.     {-1.24,-4.98,-0.51},
  94.     {-1.06,-1.93,-0.00},
  95.     {-1.07,-1.50,0.07},
  96.     {-0.89,-0.47,-0.46},
  97.     {0.00,0.00,0.00},
  98.     {-1.17,-2.20,0.08},
  99.     {-1.24,1.25,-0.91},
  100.     {0.00,0.00,0.00},
  101.     {-1.07,-1.95,0.13},
  102.     {0.00,0.00,0.00},
  103.     {0.00,0.00,0.00},
  104.     {0.00,0.00,0.00},
  105.     {0.00,0.00,0.00},
  106.     {0.00,0.00,0.00},
  107.     {1.08,-1.21,-0.03},
  108.     {0.00,0.00,0.00},
  109.     {0.00,0.00,0.00},
  110.     {0.00,0.00,0.00},
  111.     {-1.52,0.00,-0.74},
  112.     {0.73,-0.05,-0.59},
  113.     {0.00,0.00,0.00},
  114.     {-1.11,-2.04,-0.09},
  115.     {-0.97,-2.30,0.21},
  116.     {0.00,0.00,0.00},
  117.     {0.00,0.00,0.00},
  118.     {0.00,0.00,0.00},
  119.     {-0.25,0.20,-0.17},
  120.     {0.00,0.00,0.00},
  121.     {0.00,0.00,0.00},
  122.     {0.00,0.00,0.00},
  123.     {-0.92,-2.30,0.08},
  124.     {-0.07,0.17,0.69},
  125.     {0.00,0.00,0.00},
  126.     {-1.17,-2.37,0.24},
  127.     {0.00,0.00,0.00},
  128.     {0.00,0.00,0.00},
  129.     {0.00,0.00,0.00},
  130.     {0.00,0.00,0.00},
  131.     {-1.09,-1.60,0.13},
  132.     {0.00,0.00,0.00},
  133.     {-1.03,-1.52,0.15},
  134.     {1.01,-0.33,0.23},
  135.     {-1.09,-1.98,0.09},
  136.     {-1.12,-0.88,0.14},
  137.     {0.00,0.00,0.00},
  138.     {1.03,-2.26,0.00},
  139.     {0.80,-2.50,-0.05},
  140.     {0.00,0.00,0.00},
  141.     {-0.88,0.71,0.03},
  142.     {-0.66,-3.17,0.58},
  143.     {0.00,0.00,0.00},
  144.     {0.00,0.00,0.00},
  145.     {1.22,-0.74,0.02},
  146.     {0.00,0.00,0.00},
  147.     {-1.05,-2.18,0.02},
  148.     {-1.07,-2.09,0.17},
  149.     {0.00,0.00,0.00},
  150.     {-1.00,-2.20,0.14},
  151.     {1.16,-1.91,-0.11},
  152.     {1.08,-1.83,0.15},
  153.     {0.00,0.00,0.00},
  154.     {-1.21,-0.01,0.09},
  155.     {-1.19,-1.09,-0.31},
  156.     {-0.91,-1.70,-0.06},
  157.     {0.00,0.00,0.00},
  158.     {-0.96,-1.88,0.13},
  159.     {-0.98,-2.03,0.04},
  160.     {-1.14,-1.82,0.13},
  161.     {1.22,-0.74,0.00},
  162.     {0.96,-1.11,-0.11},
  163.     {-1.08,-2.30,0.08},
  164.     {-1.35,-3.05,-0.67},
  165.     {0.00,0.00,0.00},
  166.     {0.00,0.00,0.00},
  167.     {0.00,0.00,0.00},
  168.     {0.00,0.00,0.00},
  169.     {0.00,0.00,0.00},
  170.     {-1.50,-0.88,-0.24},
  171.     {-1.08,0.51,-1.43},
  172.     {-1.13,-2.44,-0.01},
  173.     {-1.11,-1.95,0.08},
  174.     {1.09,-2.19,-0.08},
  175.     {0.00,0.00,0.00},
  176.     {0.00,0.00,0.00},
  177.     {-0.17,0.13,0.52},
  178.     {-0.14,0.18,0.53},
  179.     {-0.18,0.24,0.49},
  180.     {1.24,0.46,-1.06},
  181.     {-1.31,-0.50,-0.07},
  182.     {-0.94,-1.94,0.05},
  183.     {-1.13,-1.70,0.16},
  184.     {-0.51,-2.07,0.01},
  185.     {-1.15,-2.20,0.22},
  186.     {0.00,0.00,0.00},
  187.     {0.00,0.00,0.00},
  188.     {0.00,-2.43,-0.91},
  189.     {0.91,-1.97,0.11},
  190.     {-1.01,-0.83,-0.20},
  191.     {-1.13,-0.55,0.28},
  192.     {-0.98,-1.69,0.06},
  193.     {0.00,0.00,0.00},
  194.     {0.00,0.00,0.00},
  195.     {0.00,0.00,0.00},
  196.     {-1.23,-2.51,-0.03},
  197.     {0.00,0.00,0.00},
  198.     {-0.97,-1.92,0.31},
  199.     {-0.96,-0.94,-0.01},
  200.     {-1.15,2.04,0.32},
  201.     {0.00,0.00,0.00},
  202.     {1.22,-1.99,0.16},
  203.     {-1.09,-2.00,0.13},
  204.     {0.00,0.00,0.00},
  205.     {-0.89,-1.14,0.18},
  206.     {-1.10,-2.40,-0.02},
  207.     {-1.03,-2.66,0.07},
  208.     {-0.95,-0.94,0.45},
  209.     {0.00,0.00,0.00},
  210.     {1.27,-2.37,0.13},
  211.     {-0.80,-1.47,0.17},
  212.     {0.00,0.00,0.00},
  213.     {0.00,0.00,0.00},
  214.     {-0.84,-1.92,0.23},
  215.     {-1.01,-1.76,0.25},
  216.     {0.98,-1.83,0.20},
  217.     {1.13,-2.28,0.11},
  218.     {0.93,-0.71,0.05},
  219.     {0.00,0.00,0.00},
  220.     {0.00,0.00,0.00},
  221.     {0.95,-0.86,0.09},
  222.     {1.18,-2.26,0.06},
  223.     {0.00,0.00,0.00},
  224.     {0.00,0.00,0.00},
  225.     {0.00,0.00,0.00},
  226.     {0.00,0.00,0.00},
  227.     {0.62,-0.37,0.46},
  228.     {-0.35,-1.03,0.24},
  229.     {0.00,0.00,0.00},
  230.     {-0.59,-0.94,0.26},
  231.     {0.00,0.00,0.00},
  232.     {0.00,0.00,0.00},
  233.     {0.00,0.00,0.00},
  234.     {-1.33,2.89,-0.02},
  235.     {1.13,-2.29,0.16},
  236.     {1.23,-1.77,0.29},
  237.     {-0.22,0.01,0.54},
  238.     {-0.90,0.15,-0.32},
  239.     {-0.62,0.37,-0.12},
  240.     {0.00,0.00,0.00},
  241.     {1.07,-2.29,0.20},
  242.     {0.00,0.00,0.00},
  243.     {-1.22,-1.21,0.12},
  244.     {-1.20,-2.12,0.23},
  245.     {0.98,-0.89,0.10},
  246.     {0.00,0.00,0.00},
  247.     {0.00,0.00,0.00},
  248.     {0.00,0.00,0.00},
  249.     {0.00,0.00,0.00},
  250.     {0.00,0.00,0.00},
  251.     {0.00,0.00,0.00},
  252.     {-0.97,-2.16,0.06},
  253.     {-1.02,-2.16,0.07},
  254.     {-1.08,-1.95,0.18},
  255.     {0.00,0.00,0.00},
  256.     {0.95,-2.01,0.06},
  257.     {-1.36,-1.69,0.92},
  258.     {0.97,-1.95,0.08},
  259.     {1.24,-2.20,-0.04},
  260.     {0.00,0.00,0.00},
  261.     {-0.95,-0.93,-0.02},
  262.     {0.00,0.00,0.00},
  263.     {0.00,0.00,0.00},
  264.     {0.00,0.00,0.00},
  265.     {-1.26,-0.03,0.09},
  266.     {0.00,0.00,0.00},
  267.     {0.00,0.00,0.00}
  268. };
  269.  
  270.  
  271.  
  272. forward OnPlayerShootVehiclePart(playerid, weaponid, vehicleid,hittype);
  273.  
  274. public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
  275. {
  276.     switch(hittype)
  277.     {
  278.         case BULLET_HIT_TYPE_VEHICLE:
  279.         {
  280.             new Float:fSet[9];
  281.             new modelid = GetVehicleModel(hitid);
  282.             GetVehicleModelInfo(modelid, VEHICLE_MODEL_INFO_PETROLCAP,fSet[0], fSet[1], fSet[2]);
  283.             GetVehicleModelInfo(modelid, VEHICLE_MODEL_INFO_WHEELSFRONT, fSet[3], fSet[4], fSet[5]);
  284.             GetVehicleModelInfo(modelid, VEHICLE_MODEL_INFO_WHEELSREAR,  fSet[6], fSet[7], fSet[8]);
  285.            
  286.             /*if(fX >= fSet[0]-0.15 && fX <= fSet[0]+0.15 && fY >= fSet[1]-0.05 && fY <= fSet[1]+0.15 && fZ >= fSet[2]-0.15 && fZ <= fSet[2])
  287.             {
  288.                 CallLocalFunction("OnPlayerShootVehiclePart", "iiii", playerid, weaponid, hitid,BULLET_HIT_PETROL_TANK);
  289.             }*/
  290.             if(fX >= VehicleShotInfo[modelid-400][VS_PetrolX]-0.15 && fX <= VehicleShotInfo[modelid-400][VS_PetrolX]+0.15 && fY >= VehicleShotInfo[modelid-400][VS_PetrolY]-0.15 && fY <= VehicleShotInfo[modelid-400][VS_PetrolY]+0.15 && fZ >= VehicleShotInfo[modelid-400][VS_PetrolZ]-0.15 && fZ <= VehicleShotInfo[modelid-400][VS_PetrolZ]+0.15)
  291.             {
  292.                 if(EnablePetrolCapExplosionVar==1)
  293.                 {
  294.                     new Float:vPosx,Float:vPosy,Float:vPosz;
  295.                     GetVehiclePos(hitid, vPosx,vPosy,vPosz);
  296.                     CreateExplosion(vPosx,vPosy,vPosz, 3, 30.0);
  297.                     SetVehicleToRespawn(hitid);
  298.                 }
  299.                 CallLocalFunction("OnPlayerShootVehiclePart", "iiii", playerid, weaponid, hitid,BULLET_HIT_PETROL_TANK);
  300.             }
  301.             else if(fX >= fSet[3]-2.4 && fX <= fSet[3] && fY >= fSet[4]-0.4 && fY <= fSet[4]+0.4 && fZ >= fSet[5]-0.4 && fZ <= fSet[5]+0.4)
  302.             {
  303.                 if(EnableWheelTirePopVar==1)
  304.                 {
  305.                     SetVehicleTireStatus(hitid,8);
  306.                 }
  307.                 CallLocalFunction("OnPlayerShootVehiclePart", "iiii", playerid, weaponid, hitid,BULLET_HIT_LEFT_FRONT_WHEEL);
  308.             }
  309.             else if(fX >= fSet[3]-0.4 && fX <= fSet[3]+0.4 && fY >= fSet[4]-0.4 && fY <= fSet[4]+0.4 && fZ >= fSet[5]-0.4 && fZ <= fSet[5]+0.4)
  310.             {
  311.                 if(EnableWheelTirePopVar==1)
  312.                 {
  313.                     SetVehicleTireStatus(hitid,2);
  314.                 }
  315.                 CallLocalFunction("OnPlayerShootVehiclePart", "iiii", playerid, weaponid, hitid,BULLET_HIT_RIGHT_FRONT_WHEEL);
  316.             }
  317.             else if(fX >= fSet[6]-2.4 && fX <= fSet[6] && fY >= fSet[7]-0.4 && fY <= fSet[7]+0.4 && fZ >= fSet[8]-0.4 && fZ <= fSet[8]+0.4)
  318.             {
  319.                 if(EnableWheelTirePopVar==1)
  320.                 {
  321.                     SetVehicleTireStatus(hitid,4);
  322.                 }
  323.                 CallLocalFunction("OnPlayerShootVehiclePart", "iiii", playerid, weaponid, hitid,BULLET_HIT_LEFT_BACK_WHEEL);
  324.             }
  325.             else if(fX >= fSet[6]-0.4 && fX <= fSet[6]+0.4 && fY >= fSet[7]-0.4 && fY <= fSet[7]+0.4 && fZ >= fSet[8]-0.4 && fZ <= fSet[8]+0.4)
  326.             {
  327.                 if(EnableWheelTirePopVar==1)
  328.                 {
  329.                     SetVehicleTireStatus(hitid,1);
  330.                 }
  331.                 CallLocalFunction("OnPlayerShootVehiclePart", "iiii", playerid, weaponid, hitid,BULLET_HIT_RIGHT_BACK_WHEEL);
  332.             }
  333.             if(EnableVehicleDamageVar==1)
  334.             {
  335.                 if(IsVehicleOccupied(hitid)==0)
  336.                 {
  337.                     new Float:vHP;
  338.                     GetVehicleHealth(hitid,vHP);
  339.                     SetVehicleHealth(hitid,vHP-WeaponShotInfo[GetPlayerWeapon(playerid)-22][WS_Damage]);
  340.                 }
  341.             }
  342.             CallLocalFunction("OnPlayerShootVehiclePart", "iiii", playerid, weaponid, hitid,BULLET_HIT_BODY);
  343.         }
  344.     }
  345.     #if defined hook_OnPlayerWeaponShot
  346.         hook_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
  347.     #endif
  348.     return 1;
  349. }
  350.  
  351. #if defined _ALS_OnPlayerWeaponShot
  352.     #undef OnPlayerWeaponShot  
  353. #else
  354.     #define _ALS_OnPlayerWeaponShot
  355. #endif
  356.  
  357. #define OnPlayerWeaponShot hook_OnPlayerWeaponShot
  358.  
  359. #if defined hook_OnPlayerWeaponShot
  360.     forward hook_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
  361. #endif
  362.  
  363. public OnVehicleSpawn(vehicleid)
  364. {
  365.     VehicleTire[vehicleid][0]=0;
  366.     VehicleTire[vehicleid][1]=0;
  367.     VehicleTire[vehicleid][2]=0;
  368.     VehicleTire[vehicleid][3]=0;
  369.     //return CallLocalFunction("hook_OnVehicleSpawn", "");
  370.     #if defined hook_OnVehicleSpawn
  371.         hook_OnVehicleSpawn(vehicleid);
  372.     #endif
  373.     return 1;
  374. }
  375.  
  376. #if defined _ALS_OnVehicleSpawn
  377. #undef OnVehicleSpawn  
  378. #else
  379. #define _ALS_OnVehicleSpawn
  380. #endif
  381. #define OnVehicleSpawn hook_OnVehicleSpawn
  382.  
  383. #if defined hook_OnVehicleSpawn
  384.     forward hook_OnVehicleSpawn(vehicleid);
  385. #endif
  386.  
  387. stock SetVehicleTireStatus(vehicleid,tire)
  388. {
  389.     new panels, doors, lights, tires;
  390.     GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
  391.     VehicleTire[vehicleid][tire-1]=1;
  392.     if(VehicleTire[vehicleid][tire-1]==1)
  393.     {
  394.         tires=encode_tires(VehicleTire[vehicleid][0], VehicleTire[vehicleid][1], VehicleTire[vehicleid][2], VehicleTire[vehicleid][3]);
  395.         UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
  396.     }
  397.     return 1;
  398. }
  399.  
  400. forward HasPetrolCap(vid);
  401. public HasPetrolCap(vid)
  402. {
  403.     new modelid = GetVehicleModel(vid);
  404.     switch(modelid)
  405.     {
  406.         case 400,401,402,403,404,405,407,408,409,410,411,413,414,415,416,418,419,420,421,422,423,424,426,427,428,431,433,436,437,438,439,440,442,443,445,451,455,456,458,459,463,467,468,470,475,477,478,479,480,482,483,485,486,489,491,492,494,495,496,498,499:
  407.         {
  408.             return 1;
  409.         }
  410.         case 500,502,503,504,505,506,507,508,514,515,516,517,518,521,522,523,524,525,526,527,528,529,532,533,534,535,536,540,542,543,544,546,547,539,550,551,552,554,555,558,559,560,561,562,565,566,571,572,574,578,579,580,581,582,583,585,587,588,589,596,597,598,600,601,602,603,605,609:
  411.         {
  412.             return 1;
  413.         }
  414.     }
  415.     return 0;
  416. }
  417.  
  418. encode_tires(tires1, tires2, tires3, tires4) {
  419.  
  420.     return tires1 | (tires2 << 1) | (tires3 << 2) | (tires4 << 3);
  421. }
  422.  
  423. stock EnableVehicleDamage()
  424. {
  425.     return EnableVehicleDamageVar=1;
  426. }
  427.  
  428. stock EnableVehiclePetrolCapExplosion()
  429. {
  430.     return EnablePetrolCapExplosionVar=1;
  431. }
  432.  
  433. stock EnableVehicleWheelTirePop()
  434. {
  435.     return EnableWheelTirePopVar=1;
  436. }
  437.  
  438. stock IsVehicleOccupied( vehicleid )
  439. {
  440.     for( new i = 0; i < MAX_PLAYERS; i++ )
  441.     {
  442.         if( IsPlayerConnected( i ) )
  443.         {
  444.             if( IsPlayerInVehicle( i, vehicleid ) ) return 1;
  445.         }
  446.     }
  447.     return 0;
  448. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement