Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //----------------- Sentry Gun -----------------
- //
- //Includes a Variable TargetName[] that can be used to either display targeted players name or just "Vehicle"
- //Configurable timeout on variable Called:Timeout
- //Configurable weapon on variable Called:WeaponID (http://www.se7ensins.com/forums/threads/weapon-and-explosion-hashes-list.1045035/)
- //You can switch Players as target with bool:PlayerTarget
- //you can switch Vehicles as targets with bool:VehicleTarget
- //Vehicles always get priority over players
- //------------------------------------------------
- //Create Variables
- object SentryID = 0;
- int Timeout = 500; // Time between shots.
- int Timer;
- object TargetID= 0;
- float Rotation = 0;
- bool PlayerTarget = true;
- bool VehicleTarget = true;
- hash WeaponID= GET_HASH_KEY("WEAPON_MG"); // this can be changed to any weapon offcourse
- // REQUIRED FUNCTIONS ----------------------------------------
- float GetHeadingFromCoords(Vector3 Source, Vector3 Target);
- {
- return ATAN2((Target.y - Source.y),(Target.x - Source.x));
- }
- object GetClosestVehicle(Vector3 Coords,float Distance);
- {
- Flag = 64;
- Flag |= 65536;
- Flag |= 2048;
- Flag |= 1;
- Flag |= 2;
- Flag |= 4;
- Flag |= 32;
- Flag |= 16;
- Flag |= 8;
- Flag |= 71;
- return GET_CLOSEST_VEHICLE(Coords.x,Coords.y,Coords.z,Distance,0,Flag)
- }
- /----------------------------------------------------------------
- SentryGunLoop() /This need to be looped
- {
- object MagicCarpetObject;
- vector3 PlayerCoord = ENTITY::GET_ENTITY_COORD(playerPed,1);
- if ((! ENTITY::DOES_ENTITY_EXIST(SentryID)) && (SentryActive))
- {
- SentryID = Create_Object("p_oil_slick_01",PlayerCoord.x,PlayerCoord.y,PlayerCoord.z);
- Timer = GAMEPLAY::GET_GAME_TIMER() + Timeout;
- }
- else if ((ENTITY::DOES_ENTITY_EXIST(SentryID)) && (SentryActive))
- {
- If (PlayerTarget)
- {
- TargetID= PLAYER::GET_PLAYER_PED(ENTITY::GET_NEAREST_PLAYER_TO_ENTITY(SentryID));
- char TargetName[] = PLAYER::GET_PLAYER_NAME(TargetID);
- if (TargetID == playerPed()); // Dont Shoot Myself Check
- {
- TargetID = 0; // Clear me as target
- }
- }
- If (VehicleTarget)
- {
- TargetID= GetClosestVehicle(ENTITY::GET_ENTITY_COORDS(SentryID,1),75);
- char TargetName[] = VEHICLE::GET_DISPLAY_NAME_FROM_VEHICLE_MODEL(ENTITY::GET_ENTITY_MODEL(TargetID))
- if (PED::IS_PED_IN_ANY_VEHICLE(playerPed,0) == True );
- {
- object VehID = GET_VEHICLE_PED_IS_IN(playerPed,0);
- if (TargetID == VehID); // Dont Shoot My Car check
- {
- TargetID = 0; // Clear My car as target
- }
- }
- }
- //Rotate and draw
- if (ENTITY::DOES_ENTITY_EXIST(TargetID))
- {
- vector3 from = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(SentryID,0f,-0.2f,0.57f);
- vector3 to = ENTITY::GET_ENTITY_COORDS(TargetID,true);
- GRAPHICS::DRAW_LINE(from.x,from.y,from.z,to.x,to.y,to.z, 255, 0, 0, 0);
- Rotation = GetHeadingFromCoords(from.x,from.y,from.z,to.x,to.y,to.z) + 90f;
- SET_ENTITY_ROTATION(SentryID, 0, 0, Rotation);
- }
- //Time to Kill
- if (GET_GAME_TIMER() >= Timer)
- {
- vector3 from = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(SentryObject,0,-0.8,0.6);
- vector3 to = ENTITY::GET_ENTITY_COORDS(TargetID,true);
- SHOOT_SINGLE_BULLET_BETWEEN_COORDS(from.x,from.y,from.z,to.x,to.y,to.z250,0,WeaponID,playerPed,1,0,1.0)
- PLAY_SOUND_FROM_ENTITY(-1,"Remote_Sniper_Rifle_Fire",SentryID,"",0,0)
- Timer = GET_GAME_TIMER() + Timeout;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement