XADRENALINEIX

Motions97's Gravity Gun

Jul 6th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.91 KB | None | 0 0
  1. #include <natives.h>
  2. #include <consts.h>
  3. #include <types.h>
  4. #include <common.h>
  5.  
  6. #define MISSILECOUNT 10
  7. #define VEHICLECOUNT 10
  8.  
  9. #define BUTTON_SELECT 0xD
  10. #define BUTTON_START 0xC
  11. #define BUTTON_X 0xE
  12. #define BUTTON_Y 0xF
  13. #define BUTTON_A 0x10
  14. #define BUTTON_B 0x11
  15. #define DPAD_UP 0x8
  16. #define DPAD_DOWN 0x9
  17. #define DPAD_LEFT 0xA
  18. #define DPAD_RIGHT 0xB
  19. #define BUTTON_L 0x5
  20. #define BUTTON_R 0x7
  21. #define BUTTON_LB 0x4
  22. #define BUTTON_RB 0x6
  23. #define STICK_LEFT 0x12
  24. #define STICK_RIGHT 0x13
  25.  
  26. float ground;
  27. bool online;
  28. bool search;
  29. bool get_car;
  30. Cam game_cam;
  31. int option,options = 2;
  32. int i,timer,nvid;
  33. uint xx,weapon;
  34. Ped online_char;
  35. Vehicle closest_car,pveh,car,closest;
  36. uint model;
  37. Object ObjectProjectile;
  38. bool pressed;
  39. int ModePointer = 0;
  40. Vehicle MissileQueue[MISSILECOUNT];
  41. Vehicle VehicleQueue[VEHICLECOUNT];
  42. int VehiclePointer = 0;
  43. bool looped;
  44. Vehicle pveh;
  45. float px,py,pz,car_x,car_y,car_z,x,y,z,dist,prjX, prjY, prjZ, prjT,coord_x,coord_y,coord_z,
  46. gcX,gcY,gcZ,gcrotX,gcrotY,gcrotZ,objrotX,objrotZ,heading,qx,qy,qz;
  47.  
  48. void print(char* text){
  49. CLEAR_PRINTS();
  50. PRINT_STRING_WITH_LITERAL_STRING_NOW("STRING", text,1500, true);
  51. }
  52.  
  53. void scalevector(float *x, float *y, float *z, float scale)
  54. {
  55. if (*x != 0 || *y != 0 || *z != 0)
  56. {
  57. float Dist = SQRT(POW(*x,2) + POW(*y,2) + POW(*z,2));
  58. *x = (*x / Dist) * scale;
  59. *y = (*y / Dist) * scale;
  60. *z = (*z / Dist) * scale;
  61. }
  62. }
  63.  
  64. Vehicle GetClosestCar(float x, float y, float z, float dist)
  65. {
  66. Vehicle tVeh;
  67. int i = 69;
  68. for (;i<=71;i++)
  69. {
  70. tVeh = GET_CLOSEST_CAR(x, y, z, dist, 0, i);
  71. if (DOES_VEHICLE_EXIST(tVeh))return tVeh;
  72. }
  73. return INVALID_HANDLE;
  74. }
  75.  
  76. bool network_control(int netid){
  77.     uint tick = 0;
  78.     REQUEST_CONTROL_OF_NETWORK_ID(netid);
  79.     do{
  80.         tick++;
  81.         REQUEST_CONTROL_OF_NETWORK_ID(netid);
  82.         SET_NETWORK_ID_CAN_MIGRATE(netid, true);
  83.         if(HAS_CONTROL_OF_NETWORK_ID(netid)){
  84.             return true;
  85.         }
  86.         else{
  87.             WAIT(0);
  88.         }
  89.     } while(tick < 20);
  90.     return false;
  91. }
  92.  
  93. void object_aim(void){
  94.     GET_GAME_CAM(&game_cam);
  95.     if (IS_CAM_ACTIVE(game_cam)){
  96.         GET_CAM_ROT(game_cam, &gcrotX, &gcrotY, &gcrotZ);// used for setting the object rotation and for some weird trig stuff below
  97.         GET_CAM_POS(game_cam, &gcX, &gcY, &gcZ);// used for the spawn point of the object, because the player is offset while aiming
  98.         if (gcrotX < 0.0)// the range for cam rot is -180 to 180, to set object rot we need 0 to 360
  99.         {
  100.             objrotX = gcrotX + 360.0f;
  101.         }
  102.         else
  103.         {
  104.             objrotX = gcrotX;
  105.         }
  106.         if (gcrotZ < 0.0)
  107.         {
  108.             objrotZ = gcrotZ + 360.0f;
  109.         }
  110.         else
  111.         {
  112.             objrotZ = gcrotZ;
  113.         }
  114.         /*  the trig stuff below could possibly be replaced with vectors, I have no idea how to do that though.  *
  115.         *  I apologize if this is confusing, but if you want to change the distance from the game_cam that the  *
  116.         *  object is spawned, adjust "3.0" to your preference on the first and fourth lines.  Also prjT is the  *
  117.         *  adjacent side from the pitch calculation, its purpose is to be the tangent in the following 2 lines */
  118.         prjT = (6.0 * COS(gcrotX));// adj side calculation to be used as a tangent below
  119.         prjX = gcX - (prjT * SIN(gcrotZ));// calculates how far to spawn the object from the game_cam on the X plane
  120.         prjY = gcY + (prjT * COS(gcrotZ));// calculates how far to spawn the object from the game_cam on the Y plane
  121.         prjZ = gcZ + (6.0 * SIN(gcrotX)); // calculates how far to spawn the object from the game_cam on the Z plane
  122.     }
  123. }
  124. float cx,cy,cz;
  125. void looped_shit(void){
  126.     GET_CURRENT_CHAR_WEAPON(GetPlayerPed(),&weapon);
  127.     if(weapon == WEAPON_DEAGLE){
  128.     GET_OFFSET_FROM_CHAR_IN_WORLD_COORDS(GetPlayerPed(),0,0,0,&x,&y,&z);
  129.     if(IS_BUTTON_PRESSED(0,BUTTON_L) && IS_BUTTON_JUST_PRESSED(0,BUTTON_R)){
  130.         if(DOES_VEHICLE_EXIST(closest)){
  131.         if(network_control(nvid)){
  132.         FREEZE_CAR_POSITION(closest, false);
  133.         float cx, cy, cz, fx, fy, fz;
  134.         GET_CAR_COORDINATES(closest, &cx, &cy, &cz);
  135.         GET_DISTANCE_BETWEEN_COORDS_3D(cx, cy, cz, x, y, z, &dist);
  136.         fx = (cx - gcX) / dist * 1000;
  137.         fy = (cy - gcY) / dist * 1000;
  138.         fz = (cz - gcZ) / dist * 1000;
  139.         scalevector(&fx, &fy, &fz, 1000);
  140.         APPLY_FORCE_TO_CAR(closest, 3, fx, fy, fz, 0, 0, 0, true, false, true, true);
  141.         WAIT(100);
  142.         if(options == 1){
  143.         SET_PETROL_TANK_HEALTH(closest, -1);
  144.         }
  145.         search = true;
  146.         LOCK_CAR_DOORS(closest, 0);
  147.         car = INVALID_HANDLE;
  148.         closest = INVALID_HANDLE;
  149.         WAIT(500);
  150.         }
  151.         }
  152.     }
  153.     else if(IS_BUTTON_PRESSED(0,BUTTON_L) && !IS_BUTTON_PRESSED(0,BUTTON_R)){
  154.         if(!online){
  155.         Vehicle car = GetClosestCar(x, y, z, 500);
  156.         if(closest == INVALID_HANDLE){
  157.         closest = car;
  158.         }
  159.         if(DOES_VEHICLE_EXIST(closest)){
  160.             object_aim();
  161.             GET_NETWORK_ID_FROM_VEHICLE(closest, &nvid);
  162.             if(network_control(nvid)){
  163.                 GET_GROUND_Z_FOR_3D_COORD(prjX, prjY, 1000,&ground);
  164.             FREEZE_CAR_POSITION(closest, true);
  165.             GET_CHAR_HEADING(GetPlayerPed(),&heading);
  166.             heading += 90;
  167.             if(heading > 360.0) heading -= 360.0;
  168.             if(prjZ > ground+0.7){
  169.             SET_CAR_HEADING(closest,heading);
  170.             SET_CAR_COORDINATES_NO_OFFSET(closest,prjX,prjY,prjZ);
  171.             LOCK_CAR_DOORS(closest, 4);
  172.             }
  173.             else{
  174.                 SET_CAR_HEADING(closest,heading);
  175.             SET_CAR_COORDINATES(closest,prjX,prjY,prjZ);
  176.             LOCK_CAR_DOORS(closest, 4);
  177.             }
  178.             }
  179.         }
  180.         }
  181.         else{
  182.             if(search){
  183.             for(i = 0; i<16; i++){
  184.                 if(!IS_NETWORK_PLAYER_ACTIVE(i)) continue;
  185.                 if (i == GetPlayerIndex()) continue;
  186.                 GET_PLAYER_CHAR(i, &online_char);
  187.                 if(!DOES_CHAR_EXIST(online_char)) continue;
  188.                      if(IS_CHAR_IN_ANY_CAR(online_char)){
  189.                         GET_CAR_CHAR_IS_USING(online_char,&car);
  190.                         GET_OFFSET_FROM_CHAR_IN_WORLD_COORDS(online_char, 0, 0, 0, &qx, &qy, &qz);
  191.                         GET_DISTANCE_BETWEEN_COORDS_3D(qx, qy, qz, x, y, z, &dist);
  192.                         if(dist <= 50){
  193.                         GET_NETWORK_ID_FROM_VEHICLE(car, &nvid);
  194.                             if(network_control(nvid)){
  195.                                 if(closest == INVALID_HANDLE){
  196.                                 closest = car;
  197.                                 search = false;
  198.                                 return;
  199.                                 }
  200.                                 }
  201.                         }
  202.                 }
  203.                 }
  204.             }
  205.                     if(DOES_VEHICLE_EXIST(closest)){
  206.                         object_aim();
  207.                         GET_NETWORK_ID_FROM_VEHICLE(closest, &nvid);
  208.                         if(network_control(nvid)){
  209.                             GET_GROUND_Z_FOR_3D_COORD(prjX, prjY, prjZ,&ground);
  210.                         FREEZE_CAR_POSITION(closest, true);
  211.                         GET_CHAR_HEADING(GetPlayerPed(),&heading);
  212.                         heading += 90;
  213.                             if(heading > 360) heading -= 360;
  214.                         if(prjZ > ground+0.7){
  215.                         SET_CAR_HEADING(closest,heading);
  216.                         SET_CAR_COORDINATES_NO_OFFSET(closest,prjX,prjY,prjZ);
  217.                         }
  218.                         else{
  219.                             SET_CAR_HEADING(closest,heading);
  220.                         SET_CAR_COORDINATES(closest,prjX,prjY,prjZ);
  221.                         }
  222.                         LOCK_CAR_DOORS(closest, 4);
  223.                         }
  224.         }
  225.     }
  226.     }
  227.     else if(IS_BUTTON_JUST_PRESSED(0,STICK_RIGHT)){
  228.     if(online){
  229.     online = false;
  230.     print("Ped Cars Mode: ~g~ON");
  231.     }
  232.     else{
  233.     online = true;
  234.     search = true;
  235.     print("Online Players Cars Mode: ~g~ON");
  236.     }
  237.     }
  238.     else if(IS_BUTTON_JUST_PRESSED(0,STICK_LEFT)){
  239.         if(options == 1){
  240.         options = 2;
  241.         print("Car will now ~r~ not~w~ be on fire when u shoot");
  242.         }
  243.         else if(options == 2){
  244.         options = 1;
  245.         print("Car will now be on fire when u shoot");
  246.         }
  247.     }
  248.     if(!IS_BUTTON_PRESSED(0,BUTTON_L)){
  249.         if(DOES_VEHICLE_EXIST(closest)){
  250.         FREEZE_CAR_POSITION(closest, false);
  251.         LOCK_CAR_DOORS(closest, 0);
  252.         closest = INVALID_HANDLE;
  253.         car = INVALID_HANDLE;
  254.         search = true;
  255.         }
  256.     }
  257.     }
  258.     }
  259.  
  260. void main(void){
  261. THIS_SCRIPT_IS_SAFE_FOR_NETWORK_GAME();
  262. GIVE_WEAPON_TO_CHAR(GetPlayerPed(), WEAPON_DEAGLE, AMMO_MAX, false);
  263. SET_CURRENT_CHAR_WEAPON(GetPlayerPed(), WEAPON_DEAGLE, true);
  264. DISABLE_PLAYER_LOCKON(GET_PLAYER_ID(), true);
  265. print("Gravity gun Made by: ~y~Motions97");
  266. WAIT(1500);
  267. print("Press ~PAD_RSTICK_ALL~ to cycle through Online and Peds,Press ~PAD_LSTICK_ALL~ to set car that you shoot on fire");
  268. do{
  269.     if(IS_CHAR_ON_FOOT(GetPlayerPed())){
  270.     looped_shit();
  271.     }
  272. WAIT(0);
  273. }while(true);
  274. }
Advertisement
Add Comment
Please, Sign In to add comment