Seregamil

AIM

Oct 24th, 2013
1,406
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. By Seregamil
  4.  
  5. Car shot
  6.  
  7. */
  8. #include a_samp
  9.  
  10. native IsValidVehicle(vehicleid);
  11.  
  12. main(){}
  13.  
  14. new _update[MAX_PLAYERS];
  15.  
  16. public OnGameModeInit(){
  17.     return 1;
  18. }
  19.  
  20. public OnPlayerConnect(playerid){
  21.     _clearAim(playerid);
  22.     return 1;
  23. }
  24.  
  25. public OnPlayerDisconnect(playerid, reason){
  26.     _clearAim(playerid);
  27.     return 1;
  28. }
  29.  
  30. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys){
  31.     if(newkeys & KEY_FIRE){
  32.         if(newkeys & KEY_HANDBRAKE && damageGun(playerid))
  33.             _update[playerid] = SetTimerEx("_vehicleShot", 794, true, "i", playerid);
  34.         else
  35.             _clearAim(playerid);
  36.     }
  37.     else if(oldkeys & KEY_FIRE || oldkeys & KEY_HANDBRAKE)
  38.         _clearAim(playerid);
  39.     return 1;
  40. }
  41.  
  42. Float:setRadius(vehicleid){
  43.     switch(vehicleType(vehicleid)){
  44.         case 1,2: return 1.5;
  45.         case 3,4,6: return 6.0;
  46.         case 5: return 5.0;
  47.         case 7,9: return 2.0;
  48.         case 8: return 0.5;
  49.         default: return 3.0;
  50.     }
  51.     return 3.0;
  52. }
  53.  
  54. forward _vehicleShot(playerid);
  55. public _vehicleShot(playerid){
  56.     if(!damageGun(playerid)) return _clearAim(playerid);
  57.    
  58.     new Float: car_pos[3], Float: carHealth;
  59.     GetVehiclePos(GetPVarInt(playerid,"AimVehicle"), car_pos[0],car_pos[1],car_pos[2]);
  60.     if(IsPlayerAimingAt(playerid, car_pos[0],car_pos[1],car_pos[2], setRadius(GetPVarInt(playerid,"AimVehicle")))){
  61.         GetVehicleHealth(GetPVarInt(playerid,"AimVehicle"), carHealth);
  62.         if(carHealth > 100)
  63.             SetVehicleHealth(GetPVarInt(playerid,"AimVehicle"), carHealth-(GetPlayerWeapon(playerid) * 4));
  64.  
  65.         randomDamage(GetPVarInt(playerid,"AimVehicle"));
  66.         return true;
  67.     }
  68.     for(new vehicleid = 0; vehicleid!=MAX_VEHICLES;vehicleid++){
  69.         if(!IsValidVehicle(vehicleid)) continue;
  70.         if(!IsVehicleStreamedIn(vehicleid, playerid)) continue;
  71.         GetVehiclePos(vehicleid, car_pos[0],car_pos[1],car_pos[2]);
  72.         if(!IsPlayerAimingAt(playerid, car_pos[0],car_pos[1],car_pos[2], setRadius(vehicleid))) continue;
  73.  
  74.         GetVehicleHealth(vehicleid, carHealth);
  75.  
  76.         if(carHealth > 100)
  77.             SetVehicleHealth(vehicleid, carHealth-(GetPlayerWeapon(playerid) * 4));
  78.  
  79.         randomDamage(vehicleid);
  80.         SetPVarInt(playerid, "AimVehicle", vehicleid);
  81.         break;
  82.     }
  83.     return true;
  84. }
  85.  
  86. _clearAim(playerid){
  87.     SetPVarInt(playerid, "AimVehicle", MAX_VEHICLES+1);
  88.     KillTimer(_update[playerid]);
  89.     return true;
  90. }
  91.  
  92. encode_lights(light1, light2, light3, light4) return light1 | (light2 << 1) | (light3 << 2) | (light4 << 3);
  93. encode_panels(flp, frp, rlp, rrp, windshield, front_bumper, rear_bumper) return flp | (frp << 4) | (rlp << 8) | (rrp << 12) | (windshield << 16) | (front_bumper << 20) | (rear_bumper << 24);
  94.  
  95. encode_doors(bonnet, boot, driver_door, passenger_door, behind_driver_door, behind_passenger_door){
  96.     #pragma unused behind_driver_door
  97.     #pragma unused behind_passenger_door
  98.     return bonnet | (boot << 8) | (driver_door << 16) | (passenger_door << 24);
  99. }
  100.  
  101. randomDamage(vehicleid){
  102.     new panels, doors, lights, tires;
  103.     GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
  104.     switch(random(3)){
  105.         case 0: panels = encode_panels(1, 1, 1, 1, 3, 3, 3);
  106.         case 1: doors = encode_doors(4, 4, 4, 4, 0, 0);
  107.         case 2: lights = encode_lights(1, 1, 1, 1);
  108.     }
  109.     UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
  110.     return 1;
  111. }
  112.  
  113. damageGun(playerid){
  114.     switch(GetPlayerWeapon(playerid)){
  115.         case 22..38: return true;
  116.     }
  117.     return false;
  118. }
  119.  
  120. vehicleType(vehicleid){//by wh0am1
  121.     switch (GetVehicleModel(vehicleid)){
  122.         case 509,481,510: return 1;//velo
  123.         case 461..463,448,581,521..523,586,468,471: return 2;//moto
  124.         case 417,425,447,469,487,488,497,548,563: return 3;//heli
  125.         case 460,476,511..513,519,520,553,577,592,593: return 4;//air
  126.         case 435,450,569,570,584,590,591,606..608,610,611: return 5;//trailer
  127.         case 472,473,493,595,484,430,453,452,446,454: return 6;//boat
  128.         case 499,498,609,524,578,455,403,414,443,514,515,408,456,433: return 7;//autoB
  129.         case 441,464,465,501,564,594: return 8;//RC
  130.         default: return 9;//autoA
  131.     }
  132.     return false;
  133. }
  134.  
  135. Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ,  Float:ObjX, Float:ObjY, Float:ObjZ,  Float:FrX, Float:FrY, Float:FrZ){
  136.     new Float:TGTDistance;
  137.     TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
  138.     new Float:tmpX, Float:tmpY, Float:tmpZ;
  139.     tmpX = FrX * TGTDistance + CamX;
  140.     tmpY = FrY * TGTDistance + CamY;
  141.     tmpZ = FrZ * TGTDistance + CamZ;
  142.     return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
  143. }
  144.  
  145. IsPlayerAimingAt(playerid, Float:x, Float:y, Float:z, Float:radius){
  146.     new Float:cx,Float:cy,Float:cz,Float:fx,Float:fy,Float:fz;
  147.     GetPlayerCameraPos(playerid, cx, cy, cz);
  148.     GetPlayerCameraFrontVector(playerid, fx, fy, fz);
  149.     return (radius >= DistanceCameraTargetToLocation(cx, cy, cz, x, y, z, fx, fy, fz));
  150. }
RAW Paste Data