Advertisement
KiLLerBoy_001

GTA 5: Sentry Function

Nov 11th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.69 KB | None | 0 0
  1. //-----------------  Sentry Gun  -----------------
  2. //
  3. //Includes a Variable TargetName[] that can be used to either display targeted players name or just "Vehicle"
  4. //Configurable timeout on variable Called:Timeout
  5. //Configurable weapon on variable Called:WeaponID  (http://www.se7ensins.com/forums/threads/weapon-and-explosion-hashes-list.1045035/)
  6.  
  7. //You can switch Players as target with bool:PlayerTarget
  8. //you can switch Vehicles as targets with bool:VehicleTarget
  9. //Vehicles always get priority over players
  10. //------------------------------------------------
  11.  
  12.  
  13. //Create Variables
  14. object SentryID = 0;
  15. int Timeout = 500;              // Time between shots.
  16. int Timer;
  17. object TargetID= 0;
  18. float Rotation = 0;
  19. bool PlayerTarget = true;
  20. bool VehicleTarget = true;
  21. hash WeaponID= GET_HASH_KEY("WEAPON_MG");   // this can be changed to any weapon offcourse
  22.  
  23.  
  24. // REQUIRED FUNCTIONS ----------------------------------------
  25. float GetHeadingFromCoords(Vector3 Source, Vector3 Target);
  26. {
  27.     return ATAN2((Target.y - Source.y),(Target.x - Source.x));
  28. }
  29.  
  30. object GetClosestVehicle(Vector3 Coords,float Distance);
  31. {
  32.    Flag = 64;    
  33.    Flag |= 65536;    
  34.    Flag |= 2048;    
  35.    Flag |= 1;    
  36.    Flag |= 2;    
  37.    Flag |= 4;  
  38.    Flag |= 32;  
  39.    Flag |= 16;    
  40.    Flag |= 8;
  41.    Flag |= 71;
  42.    return GET_CLOSEST_VEHICLE(Coords.x,Coords.y,Coords.z,Distance,0,Flag)
  43. }
  44. /----------------------------------------------------------------
  45.  
  46. SentryGunLoop()                 /This need to be looped
  47. {
  48.    object MagicCarpetObject;
  49.    vector3 PlayerCoord = ENTITY::GET_ENTITY_COORD(playerPed,1);
  50.  
  51.    if ((! ENTITY::DOES_ENTITY_EXIST(SentryID)) && (SentryActive))
  52.    {
  53.       SentryID = Create_Object("p_oil_slick_01",PlayerCoord.x,PlayerCoord.y,PlayerCoord.z);
  54.       Timer = GAMEPLAY::GET_GAME_TIMER() + Timeout;
  55.    }
  56.    else if ((ENTITY::DOES_ENTITY_EXIST(SentryID)) && (SentryActive))
  57.    {
  58.       If (PlayerTarget)
  59.       {
  60.          TargetID= PLAYER::GET_PLAYER_PED(ENTITY::GET_NEAREST_PLAYER_TO_ENTITY(SentryID));
  61.          char TargetName[] = PLAYER::GET_PLAYER_NAME(TargetID);
  62.          if (TargetID == playerPed());          // Dont Shoot Myself Check
  63.          {
  64.             TargetID = 0;               // Clear me as target
  65.          }
  66.       }
  67.  
  68.       If (VehicleTarget)
  69.       {
  70.          TargetID= GetClosestVehicle(ENTITY::GET_ENTITY_COORDS(SentryID,1),75);
  71.          char TargetName[] = VEHICLE::GET_DISPLAY_NAME_FROM_VEHICLE_MODEL(ENTITY::GET_ENTITY_MODEL(TargetID))
  72.          if (PED::IS_PED_IN_ANY_VEHICLE(playerPed,0) == True );
  73.          {
  74.             object VehID = GET_VEHICLE_PED_IS_IN(playerPed,0);
  75.             if (TargetID == VehID);             // Dont Shoot My Car check
  76.             {
  77.                TargetID = 0;                // Clear My car as target
  78.             }
  79.          }
  80.       }
  81.    
  82.       //Rotate and draw
  83.       if (ENTITY::DOES_ENTITY_EXIST(TargetID))
  84.       {
  85.          vector3 from = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(SentryID,0f,-0.2f,0.57f);
  86.          vector3 to = ENTITY::GET_ENTITY_COORDS(TargetID,true);
  87.          GRAPHICS::DRAW_LINE(from.x,from.y,from.z,to.x,to.y,to.z, 255, 0, 0, 0);
  88.          Rotation = GetHeadingFromCoords(from.x,from.y,from.z,to.x,to.y,to.z) + 90f;
  89.          SET_ENTITY_ROTATION(SentryID, 0, 0, Rotation);
  90.       }
  91.  
  92.       //Time to Kill
  93.       if (GET_GAME_TIMER() >= Timer)
  94.       {    
  95.          vector3 from = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(SentryObject,0,-0.8,0.6);
  96.          vector3 to = ENTITY::GET_ENTITY_COORDS(TargetID,true);
  97.          SHOOT_SINGLE_BULLET_BETWEEN_COORDS(from.x,from.y,from.z,to.x,to.y,to.z250,0,WeaponID,playerPed,1,0,1.0)
  98.      PLAY_SOUND_FROM_ENTITY(-1,"Remote_Sniper_Rifle_Fire",SentryID,"",0,0)
  99.    
  100.      Timer = GET_GAME_TIMER() + Timeout;
  101.       }
  102.    }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement